Skip to content

Commit

Permalink
feat : #18 모델 이름으로 조회하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
j2noo committed Mar 6, 2024
1 parent c31b501 commit b10e5ab
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class ModelController {

/**
* 모델 조회 api
* @param modelId
* @param modelName
* @return
*/
@GetMapping("/{modelId}")
public BaseResponse<ModelResponse> getModel(@PathVariable Long modelId) {
@GetMapping("")
public BaseResponse<ModelResponse> getModel(@RequestParam String modelName) {
return BaseResponse.<ModelResponse>builder()
.isSuccess(true)
.code(200)
.message("모델 조회에 성공했습니다.")
.data(modelService.getModel(modelId))
.data(modelService.getModel(modelName))
.build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public class ModelIntroductionController {

/**
* 모델소개 조회 api
* @param modelId
* @param modelName
* @return
*/
@GetMapping("/{modelId}")
public BaseResponse<ModelIntroductionResponse> getModelIntroduction(@PathVariable Long modelId) {
@GetMapping("")
public BaseResponse<ModelIntroductionResponse> getModelIntroduction(@RequestParam String modelName) {
return BaseResponse.<ModelIntroductionResponse>builder()
.isSuccess(true)
.code(2006)
.message("모델소개 정보 조회에 성공했습니다.")
.data(modelIntroductionService.getModelIntroduction(modelId))
.data(modelIntroductionService.getModelIntroduction(modelName))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.backend.soullive_a.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

import java.time.LocalDate;
Expand All @@ -8,12 +9,14 @@ public record ModelRequest(

String imageUrl,
String modelName,
LocalDate birth,
String age,
String job,
LocalDate birth,
String age,
String job,

String info,
String agency,
Float aiRate) {
String agency,


Float aiRate) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@


public interface ModelRepository extends JpaRepository<Model, Long> {
public Optional<Model> findByModelName(String modelName);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.backend.soullive_a.repository;
package com.backend.soullive_a.repository.model.introduction;


import com.backend.soullive_a.entity.model.Model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.backend.soullive_a.repository;
package com.backend.soullive_a.repository.model.introduction;

import com.backend.soullive_a.entity.model.Model;
import com.backend.soullive_a.entity.model.introduction.ModelIntroduction;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ModelIntroductionRepository extends JpaRepository<ModelIntroduction, Long> {
public ModelIntroduction findByModelModelName(String name);
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.backend.soullive_a.repository;
package com.backend.soullive_a.repository.model.introduction;


import com.backend.soullive_a.entity.model.Model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.backend.soullive_a.repository;
package com.backend.soullive_a.repository.model.introduction;

import com.backend.soullive_a.entity.model.Model;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;

public interface ModelIntroductionService {
public ModelIntroductionResponse getModelIntroduction(Long modelId);
public ModelIntroductionResponse getModelIntroduction(String modelName);

public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest request, Long modelId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.backend.soullive_a.dto.response.ModelResponse;

public interface ModelService {
public ModelResponse getModel(Long modelId );
public ModelResponse getModel(String modelName );

public ModelResponse createModel(ModelRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.backend.soullive_a.dto.request.ModelIntroduceRequest;
import com.backend.soullive_a.dto.request.ModelRecentAdvertisementRequest;
import com.backend.soullive_a.dto.request.ModelRecentWorkRequest;
import com.backend.soullive_a.dto.response.ModelImageKeywordResponse;
import com.backend.soullive_a.dto.response.ModelIntroductionResponse;
import com.backend.soullive_a.dto.response.ModelRecentAdvertisementResponse;
import com.backend.soullive_a.dto.response.ModelRecentWorkResponse;
Expand All @@ -15,16 +14,18 @@
import com.backend.soullive_a.entity.model.introduction.ModelRecentWork;
import com.backend.soullive_a.exception.custom.NotFoundUserException;
import com.backend.soullive_a.repository.*;
import com.backend.soullive_a.repository.model.introduction.ModelImageKeywordRepository;
import com.backend.soullive_a.repository.model.introduction.ModelIntroductionRepository;
import com.backend.soullive_a.repository.model.introduction.ModelRecentAdvertisementRepository;
import com.backend.soullive_a.repository.model.introduction.ModelRecentWorkRepository;
import com.backend.soullive_a.service.ModelIntroductionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


@Slf4j
Expand All @@ -45,8 +46,8 @@ public class ModelIntroductionServiceImpl implements ModelIntroductionService {
* @return
*/
@Override
public ModelIntroductionResponse getModelIntroduction(Long modelId) {
Model model = modelRepository.findById(modelId)
public ModelIntroductionResponse getModelIntroduction(String modelName) {
Model model = modelRepository.findByModelName(modelName)
.orElseThrow(() -> new NotFoundUserException());

List<ModelImageKeyword> modelImageKeywords = modelImageKeywordRepository.findAllByModel(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class ModelServiceImpl implements ModelService {
private final ModelRepository modelRepository;

@Override
public ModelResponse getModel(Long modelId) {
Model model = modelRepository.findById(modelId)
public ModelResponse getModel(String modelName) {
System.out.println(modelName);
Model model = modelRepository.findByModelName(modelName)
.orElseThrow(() -> new NotFoundUserException());

return ModelResponse.builder()
Expand Down

0 comments on commit b10e5ab

Please sign in to comment.