-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
449 additions
and
298 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
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
69 changes: 69 additions & 0 deletions
69
src/main/java/poomasi/domain/farm/dto/request/FarmInfoAggregateRequest.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,69 @@ | ||
package poomasi.domain.farm.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import poomasi.global.error.BusinessException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static poomasi.global.error.BusinessError.FARM_INFO_DETAIL_SIZE_MISMATCH; | ||
|
||
@Builder | ||
public record FarmInfoAggregateRequest( | ||
@NotBlank(message = "제목은 필수 입력값입니다.") | ||
String title, | ||
|
||
@NotBlank(message = "대표 이미지는 필수 입력값입니다.") | ||
String mainImage, | ||
|
||
@NotNull(message = "세부 제목 리스트는 null일 수 없습니다.") | ||
@Size(min = 3, max = 3, message = "세부 제목은 3개여야 합니다.") | ||
List<String> detailTitles, | ||
|
||
@NotNull(message = "세부 설명 리스트는 null일 수 없습니다.") | ||
List<String> detailDescriptions, | ||
|
||
@NotNull(message = "세부 이미지 리스트는 null일 수 없습니다.") | ||
List<String> detailImages | ||
) { | ||
public List<FarmInfoRegisterRequest> toRequest() { | ||
validateListsSize(); | ||
|
||
List<FarmInfoRegisterRequest> requests = new ArrayList<>(); | ||
|
||
requests.add(new FarmInfoRegisterRequest( | ||
true, | ||
title, | ||
null, | ||
mainImage | ||
)); | ||
|
||
// Add detailed farm info requests | ||
for (int i = 0; i < detailTitles.size(); i++) { | ||
String detailTitle = detailTitles.get(i); | ||
String detailDescription = (i < detailDescriptions.size()) ? detailDescriptions.get(i) : null; | ||
String detailImage = (i < detailImages.size()) ? detailImages.get(i) : null; | ||
|
||
requests.add(new FarmInfoRegisterRequest( | ||
false, | ||
detailTitle, | ||
detailDescription, | ||
detailImage | ||
)); | ||
} | ||
|
||
return requests; | ||
} | ||
|
||
private void validateListsSize() { | ||
if (detailDescriptions.size() != detailTitles.size()) { | ||
throw new BusinessException(FARM_INFO_DETAIL_SIZE_MISMATCH); | ||
} | ||
if (detailImages.size() != detailTitles.size()) { | ||
throw new BusinessException(FARM_INFO_DETAIL_SIZE_MISMATCH); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/poomasi/domain/farm/dto/request/FarmInfoUpdateRequest.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,9 @@ | ||
package poomasi.domain.farm.dto.request; | ||
|
||
public record FarmInfoUpdateRequest( | ||
Long farmId, | ||
String title, | ||
String content, | ||
String imageUrl | ||
) { | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/main/java/poomasi/domain/farm/dto/response/FarmInfoAggregateResponse.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,36 @@ | ||
package poomasi.domain.farm.dto.response; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import poomasi.domain.farm.entity.FarmInfo; | ||
|
||
import java.util.List; | ||
|
||
public record FarmInfoAggregateResponse( | ||
@NotBlank(message = "제목은 필수 입력값입니다.") | ||
String title, | ||
|
||
@NotBlank(message = "대표 이미지는 필수 입력값입니다.") | ||
String mainImage, | ||
|
||
@NotNull(message = "세부 제목 리스트는 null일 수 없습니다.") | ||
@Size(min = 3, max = 3, message = "세부 제목은 3개여야 합니다.") | ||
List<String> detailTitles, | ||
|
||
@NotNull(message = "세부 설명 리스트는 null일 수 없습니다.") | ||
List<String> detailDescriptions, | ||
|
||
@NotNull(message = "세부 이미지 리스트는 null일 수 없습니다.") | ||
List<String> detailImages | ||
) { | ||
public static FarmInfoAggregateResponse fromEntity(List<FarmInfo> farmInfos) { | ||
return new FarmInfoAggregateResponse( | ||
farmInfos.get(0).getTitle(), | ||
farmInfos.get(0).getImageUrl(), | ||
List.of(farmInfos.get(1).getTitle(), farmInfos.get(2).getTitle(), farmInfos.get(3).getTitle()), | ||
List.of(farmInfos.get(1).getContent(), farmInfos.get(2).getContent(), farmInfos.get(3).getContent()), | ||
List.of(farmInfos.get(1).getImageUrl(), farmInfos.get(2).getImageUrl(), farmInfos.get(3).getImageUrl()) | ||
); | ||
} | ||
} |
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
Oops, something went wrong.