diff --git a/src/main/java/com/backend/soullive_a/controller/ModelIntroductionController.java b/src/main/java/com/backend/soullive_a/controller/ModelIntroductionController.java new file mode 100644 index 0000000..3a98a98 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/controller/ModelIntroductionController.java @@ -0,0 +1,27 @@ +package com.backend.soullive_a.controller; + +import com.backend.soullive_a.dto.response.ModelIntroductionResponse; +import com.backend.soullive_a.service.ModelIntroductionService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/model/introduction") +public class ModelIntroductionController { + + private final ModelIntroductionService modelIntroductionService; + + /** + * 모델소개 조회 api + * @param modelId + * @return + */ + @GetMapping("/{modelId}") + public ModelIntroductionResponse getModelInroduction(@PathVariable Long modelId) { + return modelIntroductionService.getModelIntroduction(modelId); + } +} diff --git a/src/main/java/com/backend/soullive_a/dto/response/ModelIntroductionResponse.java b/src/main/java/com/backend/soullive_a/dto/response/ModelIntroductionResponse.java new file mode 100644 index 0000000..bcc789c --- /dev/null +++ b/src/main/java/com/backend/soullive_a/dto/response/ModelIntroductionResponse.java @@ -0,0 +1,16 @@ +package com.backend.soullive_a.dto.response; + +import com.backend.soullive_a.entity.model.introduction.ModelImageKeyword; +import com.backend.soullive_a.entity.model.introduction.ModelRecentAdvertisement; +import com.backend.soullive_a.entity.model.introduction.ModelRecentWork; +import lombok.Builder; + +import java.util.List; + +@Builder +public record ModelIntroductionResponse( + List modelImageKeywords, + List modelRecentWorks, + List modelRecentAdvertisements +) { +} diff --git a/src/main/java/com/backend/soullive_a/entity/model/introduction/ModelRecentAdvertisement.java b/src/main/java/com/backend/soullive_a/entity/model/introduction/ModelRecentAdvertisement.java index d16745c..93df29e 100644 --- a/src/main/java/com/backend/soullive_a/entity/model/introduction/ModelRecentAdvertisement.java +++ b/src/main/java/com/backend/soullive_a/entity/model/introduction/ModelRecentAdvertisement.java @@ -15,6 +15,13 @@ public class ModelRecentAdvertisement { @Column(name = "MODEL_RECENT_ADVERTISEMENT_ID", nullable = false) private Long id; + @Column(name = "YEAR", nullable = false) + private Integer year; + + @Column(name = "BRAND", nullable = false) + private String brand; + + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "MODEL_ID", nullable = false) private Model model; diff --git a/src/main/java/com/backend/soullive_a/repository/ModelImageKeywordRepository.java b/src/main/java/com/backend/soullive_a/repository/ModelImageKeywordRepository.java new file mode 100644 index 0000000..0a9d834 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/ModelImageKeywordRepository.java @@ -0,0 +1,12 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.dto.response.ModelImageKeywordResponse; +import com.backend.soullive_a.entity.model.introduction.ModelImageKeyword; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ModelImageKeywordRepository extends JpaRepository { + public List findAllById(Long modelId); +} + diff --git a/src/main/java/com/backend/soullive_a/repository/ModelIntroductionRepository.java b/src/main/java/com/backend/soullive_a/repository/ModelIntroductionRepository.java new file mode 100644 index 0000000..f625533 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/ModelIntroductionRepository.java @@ -0,0 +1,12 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.dto.response.ModelImageKeywordResponse; +import com.backend.soullive_a.entity.model.introduction.ModelIntroduction; +import com.backend.soullive_a.entity.model.introduction.ModelRecentWork; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ModelIntroductionRepository extends JpaRepository { +} + diff --git a/src/main/java/com/backend/soullive_a/repository/ModelRecentAdvertisementRepository.java b/src/main/java/com/backend/soullive_a/repository/ModelRecentAdvertisementRepository.java new file mode 100644 index 0000000..27667d5 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/ModelRecentAdvertisementRepository.java @@ -0,0 +1,12 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.entity.model.introduction.ModelRecentAdvertisement; +import com.backend.soullive_a.entity.model.introduction.ModelRecentWork; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ModelRecentAdvertisementRepository extends JpaRepository { + public List findAllById(Long modelId); +} + diff --git a/src/main/java/com/backend/soullive_a/repository/ModelRecentWorkRepository.java b/src/main/java/com/backend/soullive_a/repository/ModelRecentWorkRepository.java new file mode 100644 index 0000000..ba7c5d9 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/ModelRecentWorkRepository.java @@ -0,0 +1,13 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.dto.response.ModelImageKeywordResponse; +import com.backend.soullive_a.entity.model.Model; +import com.backend.soullive_a.entity.model.introduction.ModelRecentWork; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ModelRecentWorkRepository extends JpaRepository { + public List findAllById(Long modelId); +} + diff --git a/src/main/java/com/backend/soullive_a/repository/ModelRepository.java b/src/main/java/com/backend/soullive_a/repository/ModelRepository.java index 41bf98e..6f35486 100644 --- a/src/main/java/com/backend/soullive_a/repository/ModelRepository.java +++ b/src/main/java/com/backend/soullive_a/repository/ModelRepository.java @@ -6,7 +6,6 @@ import java.util.Optional; -@Repository + public interface ModelRepository extends JpaRepository { - Optional findById(Long id); } diff --git a/src/main/java/com/backend/soullive_a/service/ModelIntroductionService.java b/src/main/java/com/backend/soullive_a/service/ModelIntroductionService.java new file mode 100644 index 0000000..e8b3c28 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/service/ModelIntroductionService.java @@ -0,0 +1,10 @@ +package com.backend.soullive_a.service; + +import com.backend.soullive_a.dto.response.ModelIntroductionResponse; + +import java.util.List; + +public interface ModelIntroductionService { + public ModelIntroductionResponse getModelIntroduction(Long modelId); + +} diff --git a/src/main/java/com/backend/soullive_a/service/impl/ModelIntroductionServiceImpl.java b/src/main/java/com/backend/soullive_a/service/impl/ModelIntroductionServiceImpl.java new file mode 100644 index 0000000..a871af1 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/service/impl/ModelIntroductionServiceImpl.java @@ -0,0 +1,39 @@ +package com.backend.soullive_a.service.impl; + +import com.backend.soullive_a.dto.response.ModelImageKeywordResponse; +import com.backend.soullive_a.dto.response.ModelIntroductionResponse; +import com.backend.soullive_a.entity.model.introduction.ModelRecentAdvertisement; +import com.backend.soullive_a.entity.model.introduction.ModelRecentWork; +import com.backend.soullive_a.repository.ModelImageKeywordRepository; +import com.backend.soullive_a.repository.ModelRecentAdvertisementRepository; +import com.backend.soullive_a.repository.ModelRecentWorkRepository; +import com.backend.soullive_a.service.ModelIntroductionService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ModelIntroductionServiceImpl implements ModelIntroductionService { + + private final ModelImageKeywordRepository modelImageKeywordRepository; + private final ModelRecentWorkRepository modelRecentWorkRepository; + private final ModelRecentAdvertisementRepository modelRecentAdvertisementRepository; + + + /** + * 모델 소개 조회 서비스 로직 + * @param modelId + * @return + */ + @Override + public ModelIntroductionResponse getModelIntroduction(Long modelId) { + return ModelIntroductionResponse.builder() + .modelImageKeywords(modelImageKeywordRepository.findAllById(modelId)) + .modelRecentWorks(modelRecentWorkRepository.findAllById(modelId)) + .modelRecentAdvertisements(modelRecentAdvertisementRepository.findAllById(modelId)) + .build(); + } + +} diff --git a/src/main/java/com/backend/soullive_a/service/impl/ModelServiceImpl.java b/src/main/java/com/backend/soullive_a/service/impl/ModelServiceImpl.java index 6d9b1b9..bae49c6 100644 --- a/src/main/java/com/backend/soullive_a/service/impl/ModelServiceImpl.java +++ b/src/main/java/com/backend/soullive_a/service/impl/ModelServiceImpl.java @@ -8,6 +8,7 @@ import com.backend.soullive_a.service.ModelService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -32,6 +33,7 @@ public ModelResponse getModel(Long modelId) { } @Override + @Transactional public ModelResponse createModel(ModelRequest request) { // 중복 검사 로직 추가 Model model = modelRepository.save(Model.builder()