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 개발 #22

Closed
wants to merge 7 commits into from
Closed
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
@@ -0,0 +1,47 @@
package com.backend.soullive_a.controller;

import com.backend.soullive_a.dto.request.ModelRequest;
import com.backend.soullive_a.dto.response.ModelResponse;
import com.backend.soullive_a.exception.base.BaseResponse;
import com.backend.soullive_a.service.ModelService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

/**
* 모델 조회 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(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();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,53 @@

@Slf4j
@RestController
@RequestMapping("/product")
@RequestMapping("/api/product")
@RequiredArgsConstructor
public class ProductController {

private final ProductService productService;

@PostMapping("")
public BaseResponse<ProductResponse> createProduct(
@RequestBody @Valid CreateProductRequest createProductRequest
@RequestBody @Valid CreateProductRequest createProductRequest
) {
return BaseResponse.<ProductResponse>builder()
.isSuccess(true)
.code(200)
.message("광고 상품을 등록했습니다.")
.data(productService.createProduct(createProductRequest))
.build();
.isSuccess(true)
.code(200)
.message("광고 상품을 등록했습니다.")
.data(productService.createProduct(createProductRequest))
.build();
}

@GetMapping()
public BaseResponse<List<ProductResponse>> getAllProduct() {
return BaseResponse.<List<ProductResponse>>builder()
.isSuccess(true)
.code(200)
.message("모든 광고 상품을 불러왔습니다.")
.data(productService.getAllProduct())
.build();
.isSuccess(true)
.code(200)
.message("모든 광고 상품을 불러왔습니다.")
.data(productService.getAllProduct())
.build();
}

@GetMapping("/{id}")
public BaseResponse<ProductResponse> getProduct(@PathVariable Long id) {
return BaseResponse.<ProductResponse>builder()
.isSuccess(true)
.code(200)
.message("productId = " + id + " 광고 상품을 불러왔습니다.")
.data(productService.getProduct(id))
.build();
.isSuccess(true)
.code(200)
.message("productId = " + id + " 광고 상품을 불러왔습니다.")
.data(productService.getProduct(id))
.build();
}

@DeleteMapping("/{id}")
public BaseResponse<Void> deleteProduct(@PathVariable Long id) {

productService.deleteProduct(id);

return BaseResponse.<Void>builder()
.isSuccess(true)
.code(200)
.message("광고 상품 삭제 성공")
.build();
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/backend/soullive_a/dto/request/ModelRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.backend.soullive_a.dto.request;

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) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.backend.soullive_a.dto.response;

import com.backend.soullive_a.entity.ModelIntroduction;
import lombok.Builder;

import java.time.LocalDateTime;

@Builder
public record ModelResponse(
Long modelId,
String modelName,
LocalDateTime birth,
String job,
String info,
String agency,
Float aiRate

) {}
3 changes: 3 additions & 0 deletions src/main/java/com/backend/soullive_a/entity/Age.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.backend.soullive_a.constant.AgeType;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "AGE")
Expand All @@ -18,6 +20,7 @@ public class Age {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PRODUCT_ID", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Product product;

@Enumerated(EnumType.STRING)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/backend/soullive_a/entity/BrandImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "BRAND_IMAGE")
Expand All @@ -17,6 +19,7 @@ public class BrandImage {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PRODUCT_ID", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Product product;

@Column(name = "BRAND_IMAGE")
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/backend/soullive_a/entity/Gender.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.backend.soullive_a.constant.GenderType;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "GENDER")
Expand All @@ -18,6 +20,7 @@ public class Gender {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PRODUCT_ID", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Product product;

@Enumerated(EnumType.STRING)
Expand Down
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
3 changes: 3 additions & 0 deletions src/main/java/com/backend/soullive_a/entity/ProductImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "PRODUCT_IMAGE")
Expand All @@ -17,6 +19,7 @@ public class ProductImage {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PRODUCT_ID", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Product product;

@Column(name = "PRODUCT_IMAGE", nullable = false)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/backend/soullive_a/entity/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "TARGETRANGE")
Expand All @@ -17,6 +19,7 @@ public class Range {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PRODUCT_ID", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Product product;

@Column(name = "RANGE_VALUE", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.backend.soullive_a.exception.base;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@JsonInclude(Include.NON_EMPTY)
public class BaseResponse<T> {

private boolean isSuccess;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.entity.Age;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -9,4 +10,5 @@
@Repository
public interface AgeRepository extends JpaRepository<Age, Long> {
List<Age> findAllByProductId(Long productId);
Optional<Age> findByProductId(Long productId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.entity.BrandImage;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -9,4 +10,5 @@
@Repository
public interface BrandImageRepository extends JpaRepository<BrandImage, Long> {
List<BrandImage> findAllByProductId(Long productId);
Optional<BrandImage> findByProductId(Long productId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.entity.Gender;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -9,4 +10,5 @@
@Repository
public interface GenderRepository extends JpaRepository<Gender, Long> {
List<Gender> findAllByProductId(Long productId);
Optional<Gender> findByProductId(Long productId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.entity.Model;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ModelRepository extends JpaRepository<Model, Long> {
Optional<Model> findById(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.entity.ProductImage;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -9,4 +10,5 @@
@Repository
public interface ProductImageRepository extends JpaRepository<ProductImage, Long> {
List<ProductImage> findAllByProductId(Long productId);
Optional<ProductImage> findByProductId(Long productId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.entity.Range;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -9,4 +10,5 @@
@Repository
public interface RangeRepository extends JpaRepository<Range, Long> {
List<Range> findAllByProductId(Long productId);
Optional<Range> findByProductId(Long productId);
}
10 changes: 10 additions & 0 deletions src/main/java/com/backend/soullive_a/service/ModelService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.backend.soullive_a.service;

import com.backend.soullive_a.dto.request.ModelRequest;
import com.backend.soullive_a.dto.response.ModelResponse;

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

public ModelResponse createModel(ModelRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface ProductService {
ProductResponse getProduct(Long id);

List<ProductResponse> getAllProduct();

void deleteProduct(Long id);
}
Loading
Loading