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 900e8f8 commit 3d2cb78
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,41 @@
import com.backend.soullive_a.service.ModelService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class ModelController {
private final ModelService modelService;

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

}

/**
* 모델 등록 api
* @param request
* @return
*/
@PostMapping("/api/model")
public BaseResponse<ModelResponse> createModel(@RequestBody @Valid ModelRequest request) {
return BaseResponse.<ModelResponse>builder()
.isSuccess(true)
.code(200)
.message("모델 생성에 성공했습니다.")
.data(modelService.createModel(request))
.build();

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

public record ModelRequest(Long modelId) {
import jakarta.validation.constraints.NotNull;

import java.time.LocalDateTime;

public record ModelRequest(
@NotNull String modelName,
@NotNull LocalDateTime birth,
@NotNull String job,
String info,
@NotNull String agency,
@NotNull Float aiRate) {
}
2 changes: 1 addition & 1 deletion src/main/java/com/backend/soullive_a/entity/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Model {
@Column(name = "JOB", nullable = false)
private String job;

@Column(name = "INFO", nullable = false)
@Column(name = "INFO")
private String info;

@Column(name = "AGENCY", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
import com.backend.soullive_a.dto.response.ModelResponse;

public interface ModelService {
public ModelResponse getModel(ModelRequest request);
public ModelResponse getModel(Long modelId );

public ModelResponse createModel(ModelRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class ModelServiceImpl implements ModelService {
private final ModelRepository modelRepository;

@Override
public ModelResponse getModel(ModelRequest request) {
Model model = modelRepository.findById(request.modelId())
public ModelResponse getModel(Long modelId) {
Model model = modelRepository.findById(modelId)
.orElseThrow(() -> new RuntimeException("존재하지 않는 아이디"));

return ModelResponse.builder()
Expand All @@ -30,4 +30,28 @@ public ModelResponse getModel(ModelRequest request) {
.build();
}

@Override
public ModelResponse createModel(ModelRequest request) {
// 중복 검사 로직 추가
System.out.println("S?");
modelRepository.save(Model.builder()
.modelName(request.modelName())
.birth(request.birth())
.job(request.job())
.info(request.info())
.agency(request.agency())
.aiRate(request.aiRate())
.build());

return ModelResponse.builder()
.modelId(99L) // 수정해야함. 일단 무시.
.modelName(request.modelName())
.birth(request.birth())
.job(request.job())
.info(request.info())
.agency(request.agency())
.aiRate(request.aiRate())
.build();
}

}

0 comments on commit 3d2cb78

Please sign in to comment.