Skip to content

Commit

Permalink
feat : #18 모델소개 조회 api 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
j2noo committed Mar 4, 2024
1 parent f62c0ef commit b225cc6
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<ModelImageKeyword> modelImageKeywords,
List<ModelRecentWork> modelRecentWorks,
List<ModelRecentAdvertisement> modelRecentAdvertisements
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ModelImageKeyword, Long> {
public List<ModelImageKeyword> findAllById(Long modelId);
}

Original file line number Diff line number Diff line change
@@ -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<ModelIntroduction, Long> {
}

Original file line number Diff line number Diff line change
@@ -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<ModelRecentAdvertisement, Long> {
public List<ModelRecentAdvertisement> findAllById(Long modelId);
}

Original file line number Diff line number Diff line change
@@ -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<ModelRecentWork, Long> {
public List<ModelRecentWork> findAllById(Long modelId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.util.Optional;

@Repository

public interface ModelRepository extends JpaRepository<Model, Long> {
Optional<Model> findById(Long id);
}
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +33,7 @@ public ModelResponse getModel(Long modelId) {
}

@Override
@Transactional
public ModelResponse createModel(ModelRequest request) {
// 중복 검사 로직 추가
Model model = modelRepository.save(Model.builder()
Expand Down

0 comments on commit b225cc6

Please sign in to comment.