Skip to content

Commit

Permalink
feat : AuctionItemLike 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
haroya01 committed Sep 19, 2023
1 parent 78ae370 commit 0d6affa
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,36 +23,36 @@
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<HttpStatus> 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<List<AuctionItemCommentParentDto>> findAuctionItemCommentById(@PathVariable Long id) {
List<AuctionItemCommentParentDto> commentViews = this.auctionItemCommentServiceImpl.findAuctionItemCommentById(id);
List<AuctionItemCommentParentDto> commentViews = this.auctionItemCommentService.findAuctionItemCommentById(id);
return ResponseEntity.ok(commentViews);
}


@Operation(summary = "경매품 댓글 수정 ", description = "경매품 댓글 수정")
@PutMapping({""})
public ResponseEntity<HttpStatus> updateAuctionItemComment(@RequestBody AuctionItemCommentUpdateRequest auctionItemCommentUpdateRequest) {
this.auctionItemCommentServiceImpl.updateAuctionItemComment(auctionItemCommentUpdateRequest);
this.auctionItemCommentService.updateAuctionItemComment(auctionItemCommentUpdateRequest);
return ResponseEntity.status(HttpStatus.OK).build();
}

@Operation(summary = "경매품 댓글 삭제",description = "경매품 댓글 삭제")
@DeleteMapping({""})
public ResponseEntity<HttpStatus> deleteAuctionItemComment(AuctionItemCommentDeleteRequest auctionItemCommentDeleteRequest) {
this.auctionItemCommentServiceImpl.deleteAuctionItemComment(auctionItemCommentDeleteRequest);
this.auctionItemCommentService.deleteAuctionItemComment(auctionItemCommentDeleteRequest);
return ResponseEntity.status(HttpStatus.OK).build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,4 +56,12 @@ public ResponseEntity<HttpStatus> deleteAuctionItemById(@PathVariable Long id) {
this.auctionItemService.deleteAuctionItemById(id);
return ResponseEntity.status(HttpStatus.OK).build();
}

@Operation(summary = "경매품 좋아요", description = "경매품 관심")
@PostMapping("{id}/like")
public ResponseEntity<HttpStatus> likeAuctionItemById(@PathVariable Long id, @RequestBody AuctionItemLikeRequest auctionItemLikeRequest) {
this.auctionItemService.likeAuctionItemById(id, auctionItemLikeRequest);
return ResponseEntity.status(HttpStatus.OK).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<AuctionItemSearchResponse> findItemCategory(@ModelAttribute SearchAuctionItemSortedRequest searchAuctionItemSortedRequest){
AuctionItemSearchResponse result = this.auctionItemSearchServiceImpl.findAuctionItemByRequest(searchAuctionItemSortedRequest);
AuctionItemSearchResponse result = this.auctionItemSearchService.findAuctionItemByRequest(searchAuctionItemSortedRequest);
return ResponseEntity.ok(result);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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<AuctionItemLike, AuctionItemLikePK> {

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,4 +20,6 @@ public interface AuctionItemService {
void checkClosedTime(LocalDateTime closedTime);

void deleteAuctionItemById(Long id);

void likeAuctionItemById(Long id, AuctionItemLikeRequest auctionItemLikeRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ public interface MemberService {

void createMember(Member member);

Member findMemberById(Long Id);
}

0 comments on commit 0d6affa

Please sign in to comment.