Skip to content

Commit

Permalink
[feat] 모델소개 get api 개발 (#28)
Browse files Browse the repository at this point in the history
* feat #18 : 커스텀에러 코드 적용, 자잘한 버그 수정

* feat : #18 모델소개 조회 api 생성

* refactor : #18 식별관계로 변경

* feat : #18 모델 조회 및 생성 api

* 왜안돼?

* bug : 분리 실패

* fix : #18 Entity -> dto 전부 변환

* refactor : #18 service 로직 내에서 entity -> dto 변환

* feat : 더미sql 추가

* fix : 모델소개 생성 api 주석 처리

* fix : #18 data.sql 원복

* feat : #18 모델 이름으로 조회하도록 변경
  • Loading branch information
j2noo authored Mar 6, 2024
1 parent a95512e commit 041ce89
Show file tree
Hide file tree
Showing 24 changed files with 456 additions and 153 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
@@ -1,36 +1,38 @@
//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();
// }
//

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


// @PostMapping("/{modelId}")
// public BaseResponse<ModelIntroductionResponse> createModelIntroduction(
// @PathVariable Long modelId,
Expand All @@ -42,4 +44,6 @@
// .data(modelIntroductionService.createModelIntroduction(request, modelId))
// .build();
// }
//}

}

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

public record ModelIntroduceRequest(
List<ModelImageKeyword> modelImageKeywords,
List<ModelRecentWork> modelRecentWorks,
List<ModelRecentAdvertisement> modelRecentAdvertisements) {

List<String> keywords,
List<ModelRecentWorkRequest> modelRecentWorks,
List<ModelRecentAdvertisementRequest> modelRecentAdvertisements) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.backend.soullive_a.dto.request;


public record ModelRecentAdvertisementRequest(
String imageUrl,

Integer year,
String brand
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.backend.soullive_a.dto.request;

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

public record ModelRecentWorkRequest(
String imageUrl,

Integer year,
String category,
String title,
String genre,
String role

) {
}
18 changes: 13 additions & 5 deletions src/main/java/com/backend/soullive_a/dto/request/ModelRequest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.backend.soullive_a.dto.request;

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

import java.time.LocalDate;

public record ModelRequest(
@NotNull String modelName,
@NotNull LocalDate birth,
@NotNull String job,

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

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


Float aiRate) {

}
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.Model;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Builder;

@Builder
public record ModelImageKeywordResponse(
// Long id,
String keyord
// Model model //필요한가?
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

@Builder
public record ModelIntroductionResponse(
List<ModelImageKeyword> modelImageKeywords,
List<ModelRecentWork> modelRecentWorks,
List<ModelRecentAdvertisement> modelRecentAdvertisements

List<String> modelImageKeywords,
List<ModelRecentWorkResponse> modelRecentWorks,
List<ModelRecentAdvertisementResponse> modelRecentAdvertisements
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.backend.soullive_a.dto.response;

import com.backend.soullive_a.entity.model.Model;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Builder;

@Builder
public record ModelRecentAdvertisementResponse(
String imageUrl,
Integer year,
String brand

) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.backend.soullive_a.dto.response;

import com.backend.soullive_a.entity.model.Model;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Builder;

@Builder
public record ModelRecentWorkResponse(
String imageUrl,

Integer year,
String category,
String title,
String genre,
String role

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
@Builder
public record ModelResponse(
Long modelId,
String imageUrl,
String modelName,
LocalDate birth,

String age,

String job,
String info,
String agency,
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/backend/soullive_a/entity/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public class Model {
@Column(name = "MODEL_ID", nullable = false)
private Long id;


@Column(name = "IMAGE_URL", nullable = false)
private String imageUrl;

@Column(name = "MODEL_NAME", nullable = false)
private String modelName;

@Column(name = "BIRTH", nullable = false)
private LocalDate birth;


@Column(name = "AGE", nullable = false)
private String age;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class ModelRecentAdvertisement {
@Column(name = "MODEL_RECENT_ADVERTISEMENT_ID", nullable = false)
private Long id;

@Column(name = "IMAGE_URL", nullable = false)
private String imageUrl;


@Column(name = "YEAR", nullable = false)
private Integer year;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class ModelRecentWork {
@Column(name = "MODEL_RECENT_WORK_ID", nullable = false)
private Long id;

@Column(name = "IMAGE_URL", nullable = false)
private String imageUrl;

@Column(name = "YEAR", nullable = false)
private Integer year;

Expand All @@ -30,9 +33,6 @@ public class ModelRecentWork {
@Column(name = "ROLE", nullable = false)
private String role;

@Column(name = "IS_MAIN_ACTOR", nullable = false)
private Boolean isMainActor;

@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
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,11 +1,15 @@
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.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);
public List<ModelImageKeyword> findAllByModel(Model model);

}

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,7 @@
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.ModelRecentAdvertisement;
import com.backend.soullive_a.entity.model.introduction.ModelRecentWork;
Expand All @@ -7,6 +10,8 @@
import java.util.List;

public interface ModelRecentAdvertisementRepository extends JpaRepository<ModelRecentAdvertisement, Long> {
public List<ModelRecentAdvertisement> findAllById(Long modelId);

public List<ModelRecentAdvertisement> findAllByModel(Model model);

}

Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
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.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);

public List<ModelRecentWork> findAllByModel(Model model);

}

Loading

0 comments on commit 041ce89

Please sign in to comment.