Skip to content

Commit

Permalink
refactor : #18 service 로직 내에서 entity -> dto 변환
Browse files Browse the repository at this point in the history
  • Loading branch information
j2noo committed Mar 5, 2024
1 parent 434bed0 commit d468c52
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public record ModelIntroductionResponse(
List<ModelRecentWorkResponse> modelRecentWorks,
List<ModelRecentAdvertisementResponse> modelRecentAdvertisements
) {
// public static ModelIntroductionResponse fromModelIntroduction(
// public static ModelIntroductionResponse transfromToDto(
// List<ModelImageKeyword> modelImageKeywords,
// List<ModelRecentWork> modelRecentWorks,
// List<ModelRecentAdvertisement> modelRecentAdvertisements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,42 @@ public ModelIntroductionResponse getModelIntroduction(Long modelId) {
.orElseThrow(() -> new NotFoundUserException());

List<ModelImageKeyword> modelImageKeywords = modelImageKeywordRepository.findAllByModel(model);
List<ModelRecentWork> modelRecentWorks = modelRecentWorkRepository.findAllByModel(model);
List<ModelRecentAdvertisement> modelRecentAdvertisements = modelRecentAdvertisementRepository.findAllByModel(model);

List<String> modelImageKeywordResponse = new ArrayList<>();
List<ModelRecentWorkResponse> modelRecentWorkResponse = new ArrayList<>();
List<ModelRecentAdvertisementResponse> modelRecentAdvertisementResponse = new ArrayList<>();

List<String> modelImageKeywordList = new ArrayList<>();
for (ModelImageKeyword keyword : modelImageKeywords) {


modelImageKeywordList.add(keyword.getKeyword());
modelImageKeywordResponse.add(keyword.getKeyword());
}
for (ModelRecentWork modelRecentWork : modelRecentWorks) {
modelRecentWorkResponse.add(
ModelRecentWorkResponse.builder()
.year(modelRecentWork.getYear())
.category(modelRecentWork.getCategory())
.title(modelRecentWork.getTitle())
.genre(modelRecentWork.getGenre())
.role(modelRecentWork.getRole())
.isMainActor(modelRecentWork.getIsMainActor())
.build()
);
}


for (ModelRecentAdvertisement modelRecentAdvertisement : modelRecentAdvertisements) {
modelRecentAdvertisementResponse.add(
ModelRecentAdvertisementResponse.builder()
.year(modelRecentAdvertisement.getYear())
.brand(modelRecentAdvertisement.getBrand())
.build()
);
}

return ModelIntroductionResponse.builder()
.modelImageKeywords(modelImageKeywordList)
.modelRecentWorks(null)
.modelRecentAdvertisements(null)
.modelImageKeywords(modelImageKeywordResponse)
.modelRecentWorks(modelRecentWorkResponse)
.modelRecentAdvertisements(modelRecentAdvertisementResponse)
.build();


Expand Down Expand Up @@ -101,9 +122,7 @@ public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest r

modelImageKeywordRepository.save(modelImageKeyword);

//dto객체 생성


// ModelImageKeywordResponse (String) 생성
modelImageKeywordList.add(keyword);

}
Expand All @@ -122,15 +141,14 @@ public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest r

modelRecentWorkRepository.save(modelRecentWork);

//dto 객체 생성
// ModelRecentWorkResponse 생성
ModelRecentWorkResponse modelRecentWorkResponse = ModelRecentWorkResponse.builder()
.year(modelRecentWorkRequest.year())
.category(modelRecentWorkRequest.category())
.title(modelRecentWorkRequest.title())
.genre(modelRecentWorkRequest.genre())
.role(modelRecentWorkRequest.role())
.isMainActor(modelRecentWorkRequest.isMainActor())
// .model(model)
.build();

modelRecentWorkList.add(modelRecentWorkResponse);
Expand All @@ -146,17 +164,17 @@ public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest r

modelRecentAdvertisementRepository.save(modelRecentAdvertisement);

//dto 생성
// ModelRecentAdvertisementResponse 생성
ModelRecentAdvertisementResponse modelRecentAdvertisementResponse = ModelRecentAdvertisementResponse.builder()
.year(modelRecentAdvertisementRequest.year())
.brand(modelRecentAdvertisementRequest.brand())
// .model(model)
.build();

modelRecentAdvertisementList.add(modelRecentAdvertisementResponse);
}

//전체 dto생성
//ModelIntroductionResponse 생성

return ModelIntroductionResponse.builder()
.modelImageKeywords(modelImageKeywordList)
.modelRecentWorks(modelRecentWorkList)
Expand Down

0 comments on commit d468c52

Please sign in to comment.