Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/com/pickyfy/pickyfy/domain/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class Place extends BaseTimeEntity {
@Column(nullable = false, precision = 11, scale = 8)
private BigDecimal longitude;

@Column
private Integer likeCount = 0;

@OneToMany(mappedBy = "place", cascade = CascadeType.ALL)
private List<UserSavedPlace> userSavedPlaces = new ArrayList<>();

Expand Down Expand Up @@ -107,4 +110,12 @@ public void updateImages(List<MultipartFile> newImages, S3Service s3Service) {
.build());
}
}

public void increaseLikeCount() {
this.likeCount++;
}

public void decreaseLikeCount() {
this.likeCount--;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ public boolean togglePlaceUser(String email, Long placeId) {

return userSavedPlace.map(savedPlace -> {
userSavedPlaceRepository.delete(savedPlace);
place.decreaseLikeCount();
return false;
}).orElseGet(() -> {
userSavedPlaceRepository.save(new UserSavedPlace(user, place));
place.increaseLikeCount();
return true;
});
}
Expand Down Expand Up @@ -130,6 +132,7 @@ public Long createPlace(PlaceCreateRequest request, List<MultipartFile> imageLis
placeCategoryRepository.save(buildPlaceCategory(category, newPlace));
placeMagazineRepository.save(buildPlaceMagazine(magazine, newPlace));


List<PlaceImage> placeImages = new ArrayList<>();
for (int i = 0; i < Math.min(imageList.size(), 5); i++) {
String imageUrl = s3Service.upload(imageList.get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record NearbyPlaceResponse(
String shortDescription,
BigDecimal latitude,
BigDecimal longitude,
Integer likeCount,
String instagramLink,
String naverLink,
List<String> imageUrls,
Expand Down Expand Up @@ -47,6 +48,7 @@ public static NearbyPlaceResponse from(Place place) {
place.getShortDescription(),
place.getLatitude(),
place.getLongitude(),
place.getLikeCount(),
place.getInstagramLink(),
place.getNaverplaceLink(),
images,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class PlaceSearchResponse{
private String instagramLink;
private BigDecimal latitude;
private BigDecimal longitude;
private Integer likeCount;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private List<String> placeImageUrl;
Expand All @@ -36,6 +37,7 @@ public static PlaceSearchResponse from(PlaceSearchResponseParams params){
.shortDescription(params.place().getShortDescription())
.latitude(params.place().getLatitude())
.longitude(params.place().getLongitude())
.likeCount(params.place().getLikeCount())
.createdAt(params.place().getCreatedAt())
.updatedAt(params.place().getUpdatedAt())
.placeImageUrl(params.placeImageUrls())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void getUserSavePlace_Success() {
assertThat(r.getShortDescription()).isEqualTo("테스트 설명");
assertThat(r.getCategoryName()).isEqualTo("음식점");
assertThat(r.getMagazineTitle()).isEqualTo("테스트 매거진");
assertThat(r.getLikeCount()).isEqualTo(0);
assertThat(r.getPlaceImageUrl()).containsExactly("test-image-url.jpg");
assertThat(r.getInstagramLink()).isEqualTo("instagram.com");
assertThat(r.getNaverLink()).isEqualTo("naver.com");
Expand Down Expand Up @@ -145,9 +146,11 @@ void togglePlaceUser_Success() {
// Then
assertThat(firstToggle).isTrue();
assertThat(userSavedPlaceRepository.findByUserIdAndPlaceId(user.getId(), place.getId())).isPresent();
assertThat(place.getLikeCount()).isEqualTo(1);

// When - 두 번째 토글 (저장 취소)
boolean secondToggle = placeService.togglePlaceUser(user.getEmail(), place.getId());
assertThat(place.getLikeCount()).isEqualTo(0);

// Then
assertThat(secondToggle).isFalse();
Expand Down