Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

최근 조회한 모델,모델 추천 API 추가 + swagger 문서 수정 #31

Merged
merged 18 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.backend.soullive_a.controller;

import com.backend.soullive_a.dto.request.ModelRequest;
import com.backend.soullive_a.dto.response.ModelRecommendResponse;
import com.backend.soullive_a.dto.response.ModelResponse;
import com.backend.soullive_a.dto.response.RecentModelResponse;
import com.backend.soullive_a.exception.base.BaseResponse;
import com.backend.soullive_a.service.ModelService;
import jakarta.validation.Valid;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "모델 API", description = "모델 조회,생성,최근 조회한 모델 API입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/model")
Expand All @@ -19,31 +23,38 @@ public class ModelController {
* @param modelName
* @return
*/
@Operation(summary = "모델 조회 API", description = "모델 기본 정보를 조회하는 API입니다.")
@GetMapping("")
public BaseResponse<ModelResponse> getModel(@RequestParam String modelName) {
public BaseResponse<ModelResponse> getModel(@RequestParam String modelName, @RequestParam Long productId) {
return BaseResponse.<ModelResponse>builder()
.isSuccess(true)
.code(200)
.message("모델 조회에 성공했습니다.")
.data(modelService.getModel(modelName))
.data(modelService.getModel(modelName,productId))
.build();

}

/**
* 모델 등록 api
* @param request
* @return
*/
@PostMapping("")
public BaseResponse<ModelResponse> createModel(@RequestBody @Valid ModelRequest request) {
System.out.println("@");
return BaseResponse.<ModelResponse>builder()
.isSuccess(true)
.code(200)
.message("모델 생성에 성공했습니다.")
.data(modelService.createModel(request))
.build();
@Operation(summary = "최근 조회 모델 API", description = "최근 조회한 모델들을 조회하는 API입니다.")
@GetMapping("/recent/{productId}")
public BaseResponse<List<RecentModelResponse>> getRecentModel(@Parameter(name = "상품 id",description = "상품 기본키(필수)",
required = true) @PathVariable Long productId){
return BaseResponse.<List<RecentModelResponse>>builder()
.isSuccess(true)
.code(200)
.message("최근 조회한 모델 조회 성공")
.data(modelService.getRecentModel(productId))
.build();
}

@Operation(summary = "모델 추천 API", description = "모델을 추천 받는 API이다.")
@GetMapping("/recommendation")
public BaseResponse<List<ModelRecommendResponse>> getRecommendModel(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“/recommendation/singer" 를 하면 가수 리스트가 반환되도록 하는 식으로
가수, 배우, 유튜버로 나누는게 좋아보여요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러면 API를 3개를 만들어야 하는데 job이라는 구분자로 구분하는 경우에 비해 장점이 어떤 것이 있는지 궁금합니다!

Copy link
Member

@sominyun sominyun Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 job이라는 구분자로 하나의 api에서 쓰고 있는게 아니라 이 api는 모든 모델을 반환하는 api 아닌가요..?
모델을 다 반환하면 프론트에서 직업에 따라 구분해서 리스트를 만들고 그 리스트를 이용해서 값을 넣어야합니다 그러기 위해서 프론트에서 15명이 있는 리스트를 직업별로 나누는 로직을 만들어어하는데 그건 프론트의 역할이 아니고 백이 데이터를 구분해서 주어야한다고 봐요..!
만약에 api를 한개쓰고 싶은거라면 @RequestParam 을 쓰거나 “api/recommendation/ {job}" 로 해서 직업별로 구분하되 input 값을 프론트와 일치시켜서 singer,actor,idol 로만 입력을 받을 수 있게 해야할 것같아요

return BaseResponse.<List<ModelRecommendResponse>>builder()
.isSuccess(true)
.code(200)
.message("모델 추천 성공")
.data(modelService.getRecommendModel())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

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 io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "모델 소개 API", description = "모델 소개 API입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/model/introduction")
Expand All @@ -22,6 +22,7 @@ public class ModelIntroductionController {
* @param modelName
* @return
*/
@Operation(summary = "모델 소개 API", description = "모델 소개 정보를 조회하는 API입니다.")
@GetMapping("")
public BaseResponse<ModelIntroductionResponse> getModelIntroduction(@RequestParam String modelName) {
return BaseResponse.<ModelIntroductionResponse>builder()
Expand All @@ -33,17 +34,7 @@ public BaseResponse<ModelIntroductionResponse> getModelIntroduction(@RequestPara
}


// @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
@@ -0,0 +1,26 @@
package com.backend.soullive_a.controller;

import com.backend.soullive_a.dto.response.model.issue.ModelIssueResponse;
import com.backend.soullive_a.exception.base.BaseResponse;
import com.backend.soullive_a.service.ModelIssueService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/model/issue")
public class ModelIssueController {
private final ModelIssueService modelIssueService;
@GetMapping()
public BaseResponse<ModelIssueResponse> getIssue(@RequestParam String modelName) {
return BaseResponse.<ModelIssueResponse>builder()
.code(200)
.message("부정이슈 조회에 성공했습니다.")
.isSuccess(true)
.data(modelIssueService.getIssue(modelName))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
import com.backend.soullive_a.dto.response.model.popularity.ModelPopularityResponse;
import com.backend.soullive_a.exception.base.BaseResponse;
import com.backend.soullive_a.service.ModelPopularityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "모델 화제성 API", description = "모델 화제성 API입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/model/popularity")
public class ModelPopularityController {

private final ModelPopularityService modelPopularityService;

@Operation(summary = "모델 화제성 API", description = "모델 화제성 정보를 조회하는 API입니다.")
@GetMapping("")
public BaseResponse<ModelPopularityResponse> getModelPopularity(
@RequestParam String name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import com.backend.soullive_a.dto.response.ProductResponse;
import com.backend.soullive_a.exception.base.BaseResponse;
import com.backend.soullive_a.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "광고 상품 API", description = "광고 상품 API입니다.")
@Slf4j
@RestController
@RequestMapping("api/product")
Expand All @@ -19,6 +21,7 @@ public class ProductController {

private final ProductService productService;

@Operation(summary = "광고 상품 생성 API", description = "광고 상품을 생성하는 API입니다.")
@PostMapping("")
public BaseResponse<ProductResponse> createProduct(
@RequestBody @Valid CreateProductRequest createProductRequest
Expand All @@ -30,7 +33,7 @@ public BaseResponse<ProductResponse> createProduct(
.data(productService.createProduct(createProductRequest))
.build();
}

@Operation(summary = "모든 광고 상품 조회 API", description = "모든 광고 상품을 조회 API입니다.")
@GetMapping()
public BaseResponse<List<ProductResponse>> getAllProduct() {
return BaseResponse.<List<ProductResponse>>builder()
Expand All @@ -40,7 +43,7 @@ public BaseResponse<List<ProductResponse>> getAllProduct() {
.data(productService.getAllProduct())
.build();
}

@Operation(summary = "특정 광고 상품 조회 API", description = "특정 광고 상품을 조회 API입니다.")
@GetMapping("/{id}")
public BaseResponse<ProductResponse> getProduct(@PathVariable Long id) {
return BaseResponse.<ProductResponse>builder()
Expand All @@ -50,7 +53,7 @@ public BaseResponse<ProductResponse> getProduct(@PathVariable Long id) {
.data(productService.getProduct(id))
.build();
}

@Operation(summary = "특정 광고 상품 삭제 API", description = "특정 광고 상품을 삭제 API입니다.")
@DeleteMapping("/{id}")
public BaseResponse<Void> deleteProduct(@PathVariable Long id) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.backend.soullive_a.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "모델 추천 응답 model")
public record ModelRecommendResponse(
@Schema(name = "imageUrl", example = "https://soullive-bucket.s3.ap-northeast-2.amazonaws.com/heeae_profile.png", description = "모델 이미지 url입니다.")
String imageUrl,
@Schema(name = "name", example = "김희애", description = "모델 이름입니다.")
String name,
@Schema(name = "job", example = "텔런트/영화배우", description = "모델 직업(구분자)입니다.")
String job
) {

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

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "최근 조회한 모델 model 객체")
public record RecentModelResponse(
@Schema(name = "modelId", example = "1", description = "모델 기본키")
Long modelId,
@Schema(name = "imageUrl", example = "https://soullive-bucket.s3.ap-northeast-2.amazonaws.com/heeae_profile.png", description = "모델 이미지 url입니다.")
String imageUrl,
@Schema(name = "modelName", example = "한지민", description = "모델 이름입니다.")
String modelName,
@Schema(name = "aiRate", example = "3.0", description = "ai 추천 점수입니다.")
Float aiRate,
@Schema(name = "job", example = "배우", description = "직업에 대한 값입니다.")
String job
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

직업이 빠져있는것같아요~ 직업도 추가해주세요


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.backend.soullive_a.dto.response.model.issue;

import lombok.Builder;

import java.util.List;

@Builder
public record ModelIssueResponse(
String scoreUrl,
String aiComment,
Integer crime,
List<ModelNewsResponse> modelNewsResponseList
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.backend.soullive_a.dto.response.model.issue;

import jakarta.persistence.Column;
import lombok.Builder;

import java.time.LocalDate;

@Builder
public record ModelNewsResponse(
String company,
LocalDate newsDate,
String title,
String newsUrl
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.backend.soullive_a.entity.model.issue;

import com.backend.soullive_a.entity.model.Model;
import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class ModelIssue {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MODEL_ISSUE_ID", nullable = false)
private Long id;

@Column(name = "SCORE_URL", nullable = false)
private String scoreUrl;

@Column(name = "AI_COMMENT", nullable = false)
private String aiComment;

@Column(name = "CRIME", nullable = false)
private Integer crime;

@OneToOne
@JoinColumn(name = "MODEL_ID", nullable = false)
private Model model;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.backend.soullive_a.entity.model.issue;

import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;

@Getter
@Entity
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class ModelNews {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MODEL_NEWS_ID", nullable = false)
private Long id;

@Column(name = "COMPANY", nullable = false)
private String company;

@Column(name = "NEWS_DATE", nullable = false)
private LocalDate newsDate;

@Column(name = "TITLE", nullable = false)
private String title;

@Column(name = "NEWS_URL", nullable = false)
private String newsUrl;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MODEL_ISSUE_ID", nullable = false)
private ModelIssue modelIssue;

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.dto.response.ModelRecommendResponse;
import com.backend.soullive_a.entity.model.Model;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;


public interface ModelRepository extends JpaRepository<Model, Long> {

public Optional<Model> findByModelName(String modelName);

@Query("select "
+ "new com.backend.soullive_a.dto.response.ModelRecommendResponse(m.imageUrl,m.modelName,m.job) "
+ "From Model m ")
List<ModelRecommendResponse> findAllRecommendModel();
}
Loading
Loading