Skip to content

Commit

Permalink
Merge pull request #25 from soulive-A/feature/#19-product
Browse files Browse the repository at this point in the history
광고 상품 삭제 api 개발(#23 PR close+rebase 후 다시 Pull request)
  • Loading branch information
lsm-del authored Mar 6, 2024
2 parents 706f28b + d9ba110 commit 72a681a
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,16 @@ public BaseResponse<ProductResponse> getProduct(@PathVariable Long 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();
}
}
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
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
@@ -0,0 +1,43 @@
package com.backend.soullive_a.entity.model;

import com.backend.soullive_a.entity.Product;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "PRODUCT_MODEL")
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ProductModel {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Long id;

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MODEL_ID", nullable = false)
private Model model;

@Column(name = "SEARCH_TIME", nullable = false)
private LocalDateTime searchTime;
}
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
@@ -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
@@ -0,0 +1,8 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.entity.model.ProductModel;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ProductModelRepository extends JpaRepository<ProductModel, Long> {

}
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);
}
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@ public List<ProductResponse> getAllProduct() {
}
return productResponses;
}

@Override
@Transactional
public void deleteProduct(Long id) {
productRepository.deleteById(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//package com.backend.soullive_a.service.impl;
//
//
//
//import com.backend.soullive_a.constant.AgeType;
//import com.backend.soullive_a.constant.GenderType;
//import com.backend.soullive_a.entity.Age;
//import com.backend.soullive_a.entity.BrandImage;
//import com.backend.soullive_a.entity.Gender;
//import com.backend.soullive_a.entity.Product;
//import com.backend.soullive_a.entity.ProductImage;
//import com.backend.soullive_a.entity.Range;
//import com.backend.soullive_a.repository.AgeRepository;
//import com.backend.soullive_a.repository.BrandImageRepository;
//import com.backend.soullive_a.repository.GenderRepository;
//import com.backend.soullive_a.repository.ProductImageRepository;
//import com.backend.soullive_a.repository.ProductRepository;
//import com.backend.soullive_a.repository.RangeRepository;
//import org.junit.jupiter.api.Assertions;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.annotation.Rollback;
//import org.springframework.transaction.annotation.Transactional;
//
//@SpringBootTest
//class ProductServiceImplTest {
//
// @Autowired
// ProductRepository productRepository;
// @Autowired
// AgeRepository ageRepository;
// @Autowired
// BrandImageRepository brandImageRepository;
// @Autowired
// GenderRepository genderRepository;
// @Autowired
// ProductImageRepository productImageRepository;
// @Autowired
// RangeRepository rangeRepository;
//
// @Test
// @Transactional
// @Rollback(value = false)
// void deleteProduct() {
//
// /*
// * given
// */
// // 광고 상품 entity 생성
// Product product = Product.builder()
// .company("큐시즘")
// .brand("소울라이브-A")
// .product("백엔드 개발")
// .characteristic("characteristic")
// .build();
//
// productRepository.save(product);
// // 브랜드 이미지 entity 생성
// BrandImage brandImage = BrandImage.builder()
// .product(product)
// .brandImage("브랜드 이미지 url")
// .build();
// brandImageRepository.save(brandImage);
// // 상품 이미지 entity 생성
// ProductImage productImage = ProductImage.builder()
// .product(product)
// .productImage("상품 이미지 url")
// .build();
// productImageRepository.save(productImage);
// // 성별 entity 생성
// Gender gender = Gender.builder()
// .product(product)
// .gender(GenderType.MALE)
// .build();
// genderRepository.save(gender);
// // 나이 entity 생성
// Age age = Age.builder()
// .product(product)
// .age(AgeType.FIFTY)
// .build();
// ageRepository.save(age);
// // 범주 entity 생성
// Range range = Range.builder()
// .product(product)
// .range("범주 예시")
// .build();
// rangeRepository.save(range);
//
//
// /*
// * when
// */
// productRepository.deleteById(1L);
//
//
// /*
// * then
// */
// Assertions.assertTrue(ageRepository.findByProductId(1L).isEmpty());
// Assertions.assertTrue(brandImageRepository.findByProductId(1L).isEmpty());
// Assertions.assertTrue(genderRepository.findByProductId(1L).isEmpty());
// Assertions.assertTrue(productImageRepository.findByProductId(1L).isEmpty());
// Assertions.assertTrue(rangeRepository.findByProductId(1L).isEmpty());
//
// }
//}
//

0 comments on commit 72a681a

Please sign in to comment.