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 5, 2024
1 parent 432f1ec commit 13b7826
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public BaseResponse<ModelResponse> getModel(@PathVariable Long modelId) {
* @param request
* @return
*/
@PostMapping("/")
@PostMapping("")
public BaseResponse<ModelResponse> createModel(@RequestBody @Valid ModelRequest request) {
System.out.println("@");
return BaseResponse.<ModelResponse>builder()
.isSuccess(true)
.code(200)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
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);
}
}
//package com.backend.soullive_a.controller;
//
//import com.backend.soullive_a.dto.request.ModelIntroduceRequest;
//import com.backend.soullive_a.dto.response.ModelIntroductionResponse;
//import com.backend.soullive_a.dto.response.ModelResponse;
//import com.backend.soullive_a.exception.base.BaseResponse;
//import com.backend.soullive_a.service.ModelIntroductionService;
//import jakarta.validation.Valid;
//import lombok.RequiredArgsConstructor;
//import org.springframework.web.bind.annotation.*;
//
//@RestController
//@RequiredArgsConstructor
//@RequestMapping("/api/model/introduction")
//public class ModelIntroductionController {
//
// private final ModelIntroductionService modelIntroductionService;
//
// /**
// * 모델소개 조회 api
// * @param modelId
// * @return
// */
// @GetMapping("/{modelId}")
// public BaseResponse<ModelIntroductionResponse> getModelIntroduction(@PathVariable Long modelId) {
// return BaseResponse.<ModelIntroductionResponse>builder()
// .isSuccess(true)
// .code(2006)
// .message("모델소개 정보 조회에 성공했습니다.")
// .data(modelIntroductionService.getModelIntroduction(modelId))
// .build();
// }
//
// @PostMapping("/{modelId}")
// public BaseResponse<ModelIntroductionResponse> createModelIntroduction(
// @PathVariable Long modelId,
// @RequestBody @Valid ModelIntroduceRequest request) {
// return BaseResponse.<ModelIntroductionResponse>builder()
// .isSuccess(true)
// .code(2006)
// .message("모델소개 정보 생성에 성공했습니다.")
// .data(modelIntroductionService.createModelIntroduction(request, modelId))
// .build();
// }
//}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.backend.soullive_a.service;

import com.backend.soullive_a.dto.request.ModelIntroduceRequest;
import com.backend.soullive_a.dto.response.ModelIntroductionResponse;

import java.util.List;

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

public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest request, Long modelId);
}
//package com.backend.soullive_a.service;
//
//import com.backend.soullive_a.dto.request.ModelIntroduceRequest;
//import com.backend.soullive_a.dto.response.ModelIntroductionResponse;
//
//import java.util.List;
//
//public interface ModelIntroductionService {
// public ModelIntroductionResponse getModelIntroduction(Long modelId);
//
// public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest request, Long modelId);
//}
Original file line number Diff line number Diff line change
@@ -1,60 +1,68 @@
package com.backend.soullive_a.service.impl;

import com.backend.soullive_a.dto.request.ModelIntroduceRequest;
import com.backend.soullive_a.dto.response.ModelIntroductionResponse;
import com.backend.soullive_a.entity.model.Model;
import com.backend.soullive_a.entity.model.introduction.ModelImageKeyword;
import com.backend.soullive_a.exception.custom.NotFoundUserException;
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.repository.ModelRepository;
import com.backend.soullive_a.service.ModelIntroductionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;


@Service
@RequiredArgsConstructor
public class ModelIntroductionServiceImpl implements ModelIntroductionService {

private final ModelImageKeywordRepository modelImageKeywordRepository;
private final ModelRecentWorkRepository modelRecentWorkRepository;
private final ModelRecentAdvertisementRepository modelRecentAdvertisementRepository;
private final ModelRepository modelRepository;

/**
* 모델 소개 조회 서비스 로직
* @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();
}

/**
* 모델소개 생성 서비스 로직
* @param modelId
* @return
*/
@Override
public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest request, Long modelId) {
Model model = modelRepository.findById(modelId)
.orElseThrow(() -> new NotFoundUserException());

return ModelIntroductionResponse.builder()
.modelImageKeywords(request.modelImageKeywords())
.modelRecentWorks(request.modelRecentWorks())
.modelRecentAdvertisements(request.modelRecentAdvertisements())
.build();


}


}
//package com.backend.soullive_a.service.impl;
//
//import com.backend.soullive_a.dto.request.ModelIntroduceRequest;
//import com.backend.soullive_a.dto.response.ModelIntroductionResponse;
//import com.backend.soullive_a.entity.model.Model;
//import com.backend.soullive_a.entity.model.introduction.ModelImageKeyword;
//import com.backend.soullive_a.entity.model.introduction.ModelIntroduction;
//import com.backend.soullive_a.exception.custom.NotFoundUserException;
//import com.backend.soullive_a.repository.*;
//import com.backend.soullive_a.service.ModelIntroductionService;
//import lombok.RequiredArgsConstructor;
//import org.springframework.stereotype.Service;
//
//
//@Service
//@RequiredArgsConstructor
//public class ModelIntroductionServiceImpl implements ModelIntroductionService {
//
// private final ModelImageKeywordRepository modelImageKeywordRepository;
// private final ModelRecentWorkRepository modelRecentWorkRepository;
// private final ModelRecentAdvertisementRepository modelRecentAdvertisementRepository;
// private final ModelRepository modelRepository;
// private final ModelIntroductionRepository modelIntroductionRepository;
//
// /**
// * 모델 소개 조회 서비스 로직
// * @param modelId
// * @return
// */
// @Override
// public ModelIntroductionResponse getModelIntroduction(Long modelId) {
// Model model = modelRepository.findById(modelId)
// .orElseThrow(() -> new NotFoundUserException());
//
// return ModelIntroductionResponse.builder()
// .modelImageKeywords(modelImageKeywordRepository.findAllById(modelId))
// .modelRecentWorks(modelRecentWorkRepository.findAllById(modelId))
// .modelRecentAdvertisements(modelRecentAdvertisementRepository.findAllById(modelId))
// .build();
// }
//
// /**
// * 모델소개 생성 서비스 로직
// * @param modelId
// * @return
// */
// @Override
// public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest request, Long modelId) {
// Model model = modelRepository.findById(modelId)
// .orElseThrow(() -> new NotFoundUserException());
//
// ModelIntroduction modelIntroduction = modelIntroductionRepository.save(
// ModelIntroduction.builder()
// .model(model)
// .build()
// );
//
// return ModelIntroductionResponse.builder()
// .modelImageKeywords(request.modelImageKeywords())
// .modelRecentWorks(request.modelRecentWorks())
// .modelRecentAdvertisements(request.modelRecentAdvertisements())
// .build();
//
//
// }
//
//
//}

0 comments on commit 13b7826

Please sign in to comment.