diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemCommentController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemCommentController.java index e572086..2433bf0 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemCommentController.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemCommentController.java @@ -8,6 +8,7 @@ import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.Comment.AuctionItemCommentParentDto; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentRequest; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentUpdateRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Comment.AuctionItemCommentService; import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Comment.AuctionItemCommentServiceImpl; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -22,21 +23,21 @@ public class AuctionItemCommentController { private final AuctionItemCommentRepository auctionItemCommentRepository; - private final AuctionItemCommentServiceImpl auctionItemCommentServiceImpl; + private final AuctionItemCommentService auctionItemCommentService; @Operation(summary = "댓글 쓰기 ", description = "경매품 댓글 쓰기") @ResponseStatus(HttpStatus.CREATED) @PostMapping({"{id}"}) public ResponseEntity createAuctionItemComment(@PathVariable Long id, @RequestBody AuctionItemCommentRequest auctionItemCommentRequest) { Long memberId = auctionItemCommentRequest.getUserId(); - this.auctionItemCommentServiceImpl.createAuctionItemComment(auctionItemCommentRequest, id, memberId); + this.auctionItemCommentService.createAuctionItemComment(auctionItemCommentRequest, id, memberId); return ResponseEntity.status(HttpStatus.CREATED).build(); } @Operation(summary = "경매품에 대한 댓글 보기", description = "경매품에 대한 경매품 댓글 보기") @GetMapping({"{id}"}) public ResponseEntity> findAuctionItemCommentById(@PathVariable Long id) { - List commentViews = this.auctionItemCommentServiceImpl.findAuctionItemCommentById(id); + List commentViews = this.auctionItemCommentService.findAuctionItemCommentById(id); return ResponseEntity.ok(commentViews); } @@ -44,14 +45,14 @@ public ResponseEntity> findAuctionItemCommentB @Operation(summary = "경매품 댓글 수정 ", description = "경매품 댓글 수정") @PutMapping({""}) public ResponseEntity updateAuctionItemComment(@RequestBody AuctionItemCommentUpdateRequest auctionItemCommentUpdateRequest) { - this.auctionItemCommentServiceImpl.updateAuctionItemComment(auctionItemCommentUpdateRequest); + this.auctionItemCommentService.updateAuctionItemComment(auctionItemCommentUpdateRequest); return ResponseEntity.status(HttpStatus.OK).build(); } @Operation(summary = "경매품 댓글 삭제",description = "경매품 댓글 삭제") @DeleteMapping({""}) public ResponseEntity deleteAuctionItemComment(AuctionItemCommentDeleteRequest auctionItemCommentDeleteRequest) { - this.auctionItemCommentServiceImpl.deleteAuctionItemComment(auctionItemCommentDeleteRequest); + this.auctionItemCommentService.deleteAuctionItemComment(auctionItemCommentDeleteRequest); return ResponseEntity.status(HttpStatus.OK).build(); } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemController.java index cf21edc..db0130e 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemController.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemController.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import javax.validation.Valid; import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemLikeRequest; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemResponse; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.CreateAuctionItemRequest; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.UpdateAuctionItemRequest; @@ -55,4 +56,12 @@ public ResponseEntity deleteAuctionItemById(@PathVariable Long id) { this.auctionItemService.deleteAuctionItemById(id); return ResponseEntity.status(HttpStatus.OK).build(); } + + @Operation(summary = "경매품 좋아요", description = "경매품 관심") + @PostMapping("{id}/like") + public ResponseEntity likeAuctionItemById(@PathVariable Long id, @RequestBody AuctionItemLikeRequest auctionItemLikeRequest) { + this.auctionItemService.likeAuctionItemById(id, auctionItemLikeRequest); + return ResponseEntity.status(HttpStatus.OK).build(); + } + } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemSearchController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemSearchController.java index 0863947..b681d19 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemSearchController.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemSearchController.java @@ -4,14 +4,11 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemRepository; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemFirstView; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemPaginationDto; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemSearchResponse; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item.AuctionItemServiceImpl; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search.AuctionItemSearchServiceImpl; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item.AuctionItemService; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search.AuctionItemSearchService; + import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; @@ -24,14 +21,14 @@ @RequiredArgsConstructor public class AuctionItemSearchController { - private final AuctionItemServiceImpl auctionItemServiceImpl; + private final AuctionItemService auctionItemService; private final AuctionItemRepository AuctionItemRepository; - private final AuctionItemSearchServiceImpl auctionItemSearchServiceImpl; + private final AuctionItemSearchService auctionItemSearchService; @Operation(summary = "Search AuctionItem", description = "경매품 검색하기") @GetMapping("") public ResponseEntity findItemCategory(@ModelAttribute SearchAuctionItemSortedRequest searchAuctionItemSortedRequest){ - AuctionItemSearchResponse result = this.auctionItemSearchServiceImpl.findAuctionItemByRequest(searchAuctionItemSortedRequest); + AuctionItemSearchResponse result = this.auctionItemSearchService.findAuctionItemByRequest(searchAuctionItemSortedRequest); return ResponseEntity.ok(result); } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemLike.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemLike.java new file mode 100644 index 0000000..0c57558 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemLike.java @@ -0,0 +1,36 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity; + +import lombok.*; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.global.commons.BaseTimeEntity; + +import javax.persistence.*; + +@Getter +@Setter +@Entity +@Table(name = "AuctionItemLike") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class AuctionItemLike extends BaseTimeEntity { + + @EmbeddedId + private AuctionItemLikePK id; + + @MapsId("auctionItemId") + @ManyToOne + @JoinColumn(name = "auctionItemId") + private AuctionItem auctionItem; + + @MapsId("memberId") + @ManyToOne + @JoinColumn(name = "memberId") + private Member member; + + @Builder + public AuctionItemLike(AuctionItemLikePK id, AuctionItem auctionItem, Member member) { + this.id = id; + this.auctionItem = auctionItem; + this.member = member; + } + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemLikePK.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemLikePK.java new file mode 100644 index 0000000..24999d5 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemLikePK.java @@ -0,0 +1,17 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity; + + +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Embeddable; +import java.io.Serializable; + +@Data +@Embeddable +@NoArgsConstructor +public class AuctionItemLikePK implements Serializable { + private Long auctionItemId; + private Long memberId; + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemLikeRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemLikeRepository.java new file mode 100644 index 0000000..3ec2acf --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemLikeRepository.java @@ -0,0 +1,10 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemLike; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemLikePK; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +public interface AuctionItemLikeRepository extends JpaRepository { + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemLikeRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemLikeRequest.java new file mode 100644 index 0000000..017aa26 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemLikeRequest.java @@ -0,0 +1,13 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +public class AuctionItemLikeRequest { + + @NotNull + private Long memberId; + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemService.java index d73d764..2bc45f2 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemService.java @@ -1,5 +1,6 @@ package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item; import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemLikeRequest; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemResponse; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.CreateAuctionItemRequest; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.UpdateAuctionItemRequest; @@ -19,4 +20,6 @@ public interface AuctionItemService { void checkClosedTime(LocalDateTime closedTime); void deleteAuctionItemById(Long id); + + void likeAuctionItemById(Long id, AuctionItemLikeRequest auctionItemLikeRequest); } \ No newline at end of file diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemServiceImpl.java index 909b07e..1bb921c 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemServiceImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemServiceImpl.java @@ -5,7 +5,11 @@ import lombok.RequiredArgsConstructor; import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemLike; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemLikePK; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemLikeRepository; import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemRepository; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemLikeRequest; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemResponse; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.CreateAuctionItemRequest; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.UpdateAuctionItemRequest; @@ -27,12 +31,13 @@ public class AuctionItemServiceImpl implements AuctionItemService { private final MemberRepository memberRepository; private final CategoryRepository categoryRepository; private final MemberService memberService; + private final AuctionItemLikeRepository auctionItemLikeRepository; @Override @Transactional public void createAuctionItem(CreateAuctionItemRequest createAuctionItemRequest) { checkClosedTime(createAuctionItemRequest.getClosedTime()); - Member memberEntity = memberService.findMemberById(createAuctionItemRequest.getMember()); + Member memberEntity = memberRepository.findById(createAuctionItemRequest.getMember()).orElseThrow(RuntimeException::new); Category categoryEntity = categoryService.findCategoryByName(createAuctionItemRequest.getCategory()); AuctionItem auctionItem = createAuctionItemRequest.toEntity(); @@ -89,4 +94,29 @@ public void deleteAuctionItemById(Long id) { auctionItem.removeAuctionItem(auctionItem); auctionItemRepository.save(auctionItem); } + + @Override + @Transactional + public void likeAuctionItemById(Long id, AuctionItemLikeRequest auctionItemLikeRequest) { + AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); + Member member = memberRepository.findById(auctionItemLikeRequest.getMemberId()).orElseThrow(RuntimeException::new); + + AuctionItemLikePK auctionItemLikePK = new AuctionItemLikePK(); + auctionItemLikePK.setAuctionItemId(id); + auctionItemLikePK.setMemberId(auctionItemLikeRequest.getMemberId()); + + AuctionItemLike auctionItemLike = auctionItemLikeRepository.findById(auctionItemLikePK).orElse(null); + + if(auctionItemLike != null ){ + auctionItemLikeRepository.delete(auctionItemLike); + auctionItem.setLike_count(auctionItem.getLike_count() - 1); + auctionItemRepository.save(auctionItem); + } + else { + auctionItemLike = AuctionItemLike.builder().id(auctionItemLikePK).auctionItem(auctionItem).member(member).build(); + auctionItemLikeRepository.save(auctionItemLike); + auctionItem.setLike_count(auctionItem.getLike_count() + 1); + auctionItemRepository.save(auctionItem); + } + } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/IAuctionItemSearchService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/IAuctionItemSearchService.java deleted file mode 100644 index a32d7aa..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/IAuctionItemSearchService.java +++ /dev/null @@ -1,16 +0,0 @@ -package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search; - -import java.awt.print.Pageable; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemRepository; -import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; -import org.springframework.data.domain.Page; - -public interface IAuctionItemSearchService { - - public AuctionItemRepository findAllByMemberAddress(Member member, Pageable pageable); - - public AuctionItemRepository findAllByCategory(String category, Pageable pageable); - - public Page findAllByTimeLine(Pageable pageable); -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/GeneralMemberService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/GeneralMemberService.java index f18dbda..3b40916 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/GeneralMemberService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/GeneralMemberService.java @@ -18,8 +18,4 @@ public void createMember(Member member) { memberRepository.save(member); } - @Override - public Member findMemberById(Long Id) { - return memberRepository.findById(Id).orElseThrow(RuntimeException::new); - } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/MemberService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/MemberService.java index 224e255..29ecdc0 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/MemberService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/MemberService.java @@ -6,5 +6,4 @@ public interface MemberService { void createMember(Member member); - Member findMemberById(Long Id); }