Skip to content

Commit

Permalink
[FIX] #63 - 소모임 좋아요 등록/삭제 수정
Browse files Browse the repository at this point in the history
일단 병합 후 넘겨받아 수정 작업 계획
  • Loading branch information
c0smosaur authored Jun 8, 2024
2 parents 7e492fc + 5d4c1ec commit bb58008
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.core.linkup.club.club.response.ClubLikeResponse;
import com.core.linkup.club.club.response.ClubSearchResponse;
import com.core.linkup.club.club.service.ClubService;
import com.core.linkup.common.exception.BaseException;
import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.common.response.BaseResponseStatus;
import com.core.linkup.security.MemberDetails;
Expand Down Expand Up @@ -131,15 +130,4 @@ public BaseResponse<Page<ClubLikeResponse>> findClub(
Page<ClubLikeResponse> response = clubService.findLikeClub(member, pageable, request);
return BaseResponse.response(response);
}

//삭제
@DeleteMapping("/{club_id}/like")
public BaseResponse<Void> deleteClub(
@AuthenticationPrincipal MemberDetails member,
@PathVariable("club_id") Long clubId
) {
Long memberId = member.getId();
clubService.unlikeClub(memberId, clubId);
return BaseResponse.response(BaseResponseStatus.DELETE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,26 @@ public ClubLike toLikeEntity(Long memberId, Long clubId) {
.build();
}

public ClubLikeResponse toLikeResponse(ClubLike clubLike) {
public ClubLikeResponse toUnLikeResponse(boolean liked, String message, Long memberId, Long clubId) {
return ClubLikeResponse.builder()
.clubId(clubId)
.memberId(memberId)
.liked(liked)
.message(message)
.build();
}

public ClubLikeResponse toLikeResponse(ClubLike clubLike, Club club) {
return ClubLikeResponse.builder()
.id(clubLike.getId())
.memberId(clubLike.getMemberId())
.clubId(clubLike.getClubId())
.memberId(clubLike.getMemberId())
.liked(true)
.message("좋아요가 등록되었습니다.")
.clubThumbnail(club.getClubThumbnail())
.clubName(club.getTitle())
.clubIntroduction(club.getIntroduction())
.clubMemberCount(club.getRecruitCount())
.build();
}

Expand All @@ -176,6 +191,7 @@ public ClubLikeResponse toLikeResponse(ClubLike clubLike, Club club, ClubMeeting
.id(clubLike.getId())
.memberId(clubLike.getMemberId())
.clubId(clubLike.getClubId())
.liked(true)
.clubThumbnail(club.getClubThumbnail())
.clubName(club.getTitle())
.clubIntroduction(club.getIntroduction())
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/core/linkup/club/club/entity/ClubLike.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public class ClubLike extends BaseEntity {

private Long clubId;
private Long memberId;
private Boolean liked;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public record ClubLikeResponse(
String clubName,
String clubIntroduction,
Integer clubMemberCount,
LocalDate clubMeetingDate
LocalDate clubMeetingDate,
Boolean liked,
String message
) {
}
18 changes: 8 additions & 10 deletions src/main/java/com/core/linkup/club/club/service/ClubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -217,12 +216,15 @@ public ClubLikeResponse likeClub(Long memberId, Long clubId) {
boolean duplicate = clubRepository.existsByMemberIdAndClubId(memberId, clubId);

if (duplicate) {
throw new BaseException(BaseResponseStatus.DUPLICATE_CLUB_LIKE);
clubRepository.deleteByMemberIdAndClubId(memberId, clubId);
return clubConverter.toUnLikeResponse(false, "좋아요가 취소되었습니다.", memberId, clubId);
} else {
ClubLike clubLike = clubConverter.toLikeEntity(memberId, clubId);
clubLikeRepository.save(clubLike);
Club club = clubRepository.findById(clubId)
.orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_CLUB_ID));
return clubConverter.toLikeResponse(clubLike, club);
}

ClubLike clubLike = clubConverter.toLikeEntity(memberId, clubId);
clubLikeRepository.save(clubLike);
return clubConverter.toLikeResponse(clubLike);
}


Expand All @@ -238,8 +240,4 @@ public Page<ClubLikeResponse> findLikeClub(MemberDetails member, Pageable pageab
});
}

@Transactional
public void unlikeClub(Long memberId, Long clubId) {
clubLikeRepository.deleteByMemberIdAndClubId(memberId, clubId);
}
}

0 comments on commit bb58008

Please sign in to comment.