-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from ootd-zip/feature/search-brand
feature : 브랜드 조회 시 검색 추가
- Loading branch information
Showing
9 changed files
with
137 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/zip/ootd/ootdzip/brand/controller/request/BrandSearchReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package zip.ootd.ootdzip.brand.controller.request; | ||
|
||
import lombok.Setter; | ||
import zip.ootd.ootdzip.brand.service.request.BrandSearchSvcReq; | ||
|
||
@Setter | ||
public class BrandSearchReq { | ||
|
||
private String brandName; | ||
|
||
public BrandSearchSvcReq toServiceRequest() { | ||
return BrandSearchSvcReq.builder() | ||
.name(this.brandName) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
package zip.ootd.ootdzip.brand.data; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import zip.ootd.ootdzip.brand.domain.Brand; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class BrandDto { | ||
|
||
private Long id; | ||
|
||
private String name; | ||
|
||
public BrandDto(Brand brand) { | ||
this.id = brand.getId(); | ||
this.name = brand.getName(); | ||
@Builder | ||
private BrandDto(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public static BrandDto of(Brand brand) { | ||
return BrandDto.builder() | ||
.id(brand.getId()) | ||
.name(brand.getName()) | ||
.build(); | ||
} | ||
} |
15 changes: 13 additions & 2 deletions
15
src/main/java/zip/ootd/ootdzip/brand/data/BrandSaveReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
package zip.ootd.ootdzip.brand.data; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Data; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Data | ||
@Setter | ||
@NoArgsConstructor | ||
@Getter | ||
public class BrandSaveReq { | ||
|
||
@NotBlank(message = "브랜드 이름을 입력해주세요.") | ||
public String name; | ||
|
||
@Builder | ||
public BrandSaveReq(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/zip/ootd/ootdzip/brand/service/request/BrandSearchSvcReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package zip.ootd.ootdzip.brand.service.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BrandSearchSvcReq { | ||
|
||
private final String name; | ||
|
||
@Builder | ||
private BrandSearchSvcReq(String name) { | ||
this.name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/zip/ootd/ootdzip/brand/service/BrandServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package zip.ootd.ootdzip.brand.service; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import zip.ootd.ootdzip.IntegrationTestSupport; | ||
import zip.ootd.ootdzip.brand.data.BrandDto; | ||
import zip.ootd.ootdzip.brand.data.BrandSaveReq; | ||
import zip.ootd.ootdzip.brand.service.request.BrandSearchSvcReq; | ||
|
||
class BrandServiceTest extends IntegrationTestSupport { | ||
|
||
@Autowired | ||
private BrandService brandService; | ||
|
||
@DisplayName("브랜드를 저장한다.") | ||
@Test | ||
void saveBrand() { | ||
// given | ||
BrandSaveReq request = BrandSaveReq.builder() | ||
.name("브랜드1") | ||
.build(); | ||
|
||
// when | ||
BrandDto result = brandService.saveBrand(request); | ||
|
||
//then | ||
assertThat(result.getName()).isEqualTo(request.getName()); | ||
} | ||
|
||
@DisplayName("브랜드를 조회한다.") | ||
@Test | ||
void getBrand() { | ||
// given | ||
BrandSaveReq request1 = BrandSaveReq.builder() | ||
.name("브랜드1") | ||
.build(); | ||
|
||
BrandDto brand1 = brandService.saveBrand(request1); | ||
|
||
BrandSaveReq request2 = BrandSaveReq.builder() | ||
.name("테스트1") | ||
.build(); | ||
|
||
BrandDto brand2 = brandService.saveBrand(request2); | ||
|
||
BrandSearchSvcReq request3 = BrandSearchSvcReq.builder() | ||
.name("브") | ||
.build(); | ||
|
||
// when | ||
List<BrandDto> brands = brandService.getBrands(request3); | ||
|
||
//then | ||
assertThat(brands).hasSize(1) | ||
.extracting("name") | ||
.contains("브랜드1"); | ||
|
||
} | ||
|
||
} |