-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: product review 생성 조회 * feat: category - product 연관관계 추가 * feat: 카테고리 내 상품 조회 * fix: 빠진 파일 추가 * style: 아 맞다 정렬 * feat: 상품리뷰 - 상품리뷰사진 연관 관계 생성 * refactor: 평균 평점을 리뷰 추가할 때 계산하도록 변경 * feat: 충돌 해결 * feat: 수정사항 삭제 * feat: review 생성 * style: 아 맞다 정렬 * feature: 위시리스트 등록 - 재고와 무관하게 경우 위시리스트 가능하게 #57 * feature: 위시리스트 조회 #57 --------- Co-authored-by: canyos <[email protected]> Co-authored-by: canyos <[email protected]>
- Loading branch information
1 parent
71d656e
commit 6a56050
Showing
13 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/poomasi/domain/wishlist/controller/WishListPlatformController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package poomasi.domain.wishlist.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import poomasi.domain.wishlist.dto.WishListDeleteRequest; | ||
import poomasi.domain.wishlist.dto.request.WishListAddRequest; | ||
import poomasi.domain.wishlist.service.WishListPlatformService; | ||
|
||
@RequestMapping("/api/v1/wish-list") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class WishListPlatformController { | ||
private final WishListPlatformService wishListPlatformService; | ||
|
||
@PostMapping("/add") | ||
public ResponseEntity<?> addWishList(@RequestBody WishListAddRequest request) { | ||
wishListPlatformService.addWishList(request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PostMapping("/delete") | ||
public ResponseEntity<?> deleteWishList(@RequestBody WishListDeleteRequest request) { | ||
wishListPlatformService.deleteWishList(request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@GetMapping("/find") | ||
public ResponseEntity<?> findWishListByMemberId(@RequestBody Long memberId) { | ||
// FIXME : memberID는 SecurityContextHolder에서 가져오도록 수정 | ||
return ResponseEntity.ok(wishListPlatformService.findWishListByMemberId(memberId)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/poomasi/domain/wishlist/dto/WishListDeleteRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package poomasi.domain.wishlist.dto; | ||
|
||
public record WishListDeleteRequest( | ||
Long memberId, | ||
Long productId | ||
) { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/poomasi/domain/wishlist/dto/WishListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package poomasi.domain.wishlist.dto; | ||
|
||
import poomasi.domain.wishlist.entity.WishList; | ||
|
||
public record WishListResponse( | ||
Long productId, | ||
String productName, | ||
Long price, | ||
String imageUrl, | ||
String description | ||
) { | ||
public static WishListResponse fromEntity(WishList wishList) { | ||
return new WishListResponse( | ||
wishList.getProduct().getId(), | ||
wishList.getProduct().getName(), | ||
wishList.getProduct().getPrice(), | ||
wishList.getProduct().getImageUrl(), | ||
wishList.getProduct().getDescription() | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/poomasi/domain/wishlist/dto/request/WishListAddRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package poomasi.domain.wishlist.dto.request; | ||
|
||
import poomasi.domain.member.entity.Member; | ||
import poomasi.domain.product.entity.Product; | ||
import poomasi.domain.wishlist.entity.WishList; | ||
|
||
public record WishListAddRequest( | ||
Long memberId, | ||
Long productId | ||
) { | ||
public WishList toEntity(Member member, Product product) { | ||
return WishList.builder() | ||
.member(member) | ||
.product(product) | ||
.build(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/poomasi/domain/wishlist/entity/WishList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package poomasi.domain.wishlist.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Comment; | ||
import org.hibernate.annotations.CurrentTimestamp; | ||
import org.hibernate.annotations.SQLDelete; | ||
import org.hibernate.annotations.Where; | ||
import poomasi.domain.member.entity.Member; | ||
import poomasi.domain.product.entity.Product; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@SQLDelete(sql = "UPDATE product SET deleted_at = current_timestamp WHERE id = ?") | ||
public class WishList { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Comment("회원") | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
@Comment("상품") | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "product_id") | ||
private Product product; | ||
|
||
@Comment("등록일시") | ||
@CurrentTimestamp | ||
private LocalDateTime createdAt; | ||
|
||
@Comment("삭제일시") | ||
private LocalDateTime deletedAt; | ||
|
||
@Builder | ||
public WishList(Member member, Product product) { | ||
this.member = member; | ||
this.product = product; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/poomasi/domain/wishlist/repository/WishListRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package poomasi.domain.wishlist.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import poomasi.domain.wishlist.entity.WishList; | ||
|
||
import java.util.List; | ||
|
||
public interface WishListRepository extends JpaRepository<WishList, Long> { | ||
List<WishList> findByMemberId(Long memberId); | ||
|
||
void deleteByMemberIdAndProductId(Long memberId, Long productId); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/poomasi/domain/wishlist/service/WishListPlatformService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package poomasi.domain.wishlist.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import poomasi.domain.wishlist.dto.WishListDeleteRequest; | ||
import poomasi.domain.wishlist.dto.WishListResponse; | ||
import poomasi.domain.wishlist.dto.request.WishListAddRequest; | ||
import poomasi.domain.wishlist.entity.WishList; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class WishListPlatformService { | ||
private final WishListService wishListService; | ||
|
||
@Transactional | ||
public void addWishList(WishListAddRequest request) { | ||
wishListService.addWishList(request); | ||
} | ||
|
||
@Transactional | ||
public void deleteWishList(WishListDeleteRequest request) { | ||
wishListService.deleteWishList(request); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<WishListResponse> findWishListByMemberId(Long memberId) { | ||
return wishListService.findWishListByMemberId(memberId).stream() | ||
.map(WishListResponse::fromEntity) | ||
.toList(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/poomasi/domain/wishlist/service/WishListService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package poomasi.domain.wishlist.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import poomasi.domain.member.entity.Member; | ||
import poomasi.domain.member.service.MemberService; | ||
import poomasi.domain.product.entity.Product; | ||
import poomasi.domain.product.service.ProductService; | ||
import poomasi.domain.wishlist.dto.WishListDeleteRequest; | ||
import poomasi.domain.wishlist.dto.request.WishListAddRequest; | ||
import poomasi.domain.wishlist.entity.WishList; | ||
import poomasi.domain.wishlist.repository.WishListRepository; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class WishListService { | ||
private final WishListRepository wishListRepository; | ||
private final MemberService memberService; | ||
private final ProductService productService; | ||
|
||
@Transactional | ||
public void addWishList(WishListAddRequest request) { | ||
Member member = memberService.findMemberById(request.memberId()); | ||
Product product = productService.findProductById(request.productId()); | ||
wishListRepository.save(request.toEntity(member, product)); | ||
} | ||
|
||
@Transactional | ||
public void deleteWishList(WishListDeleteRequest request) { | ||
wishListRepository.deleteByMemberIdAndProductId(request.memberId(), request.productId()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<WishList> findWishListByMemberId(Long memberId) { | ||
return wishListRepository.findByMemberId(memberId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters