Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public CommonResponse<UserPlaceCreateResponseDto> createPlaceList(
}

@GetMapping
@Operation(summary = "내 장소 리스트 요약 조회", description = "장소 관련 목록(리스트)만 반환합니다(개수 포함).")
@Operation(summary = "내가 저장한 리스트 요약 조회", description = "장소 관련 목록(리스트)만 반환합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "404", description = "유저를 찾을 수 없음"),
Expand All @@ -69,9 +69,9 @@ public CommonResponse<List<UserPlaceSummaryDto>> getMyPlaceSummaries(
return CommonResponse.success(summaries);
}

@DeleteMapping
@DeleteMapping("/zones")
@Operation(
summary = "장소에서 웨이블존 제거",
summary = "내가 저장한 리스트에서 웨이블존 제거",
description = "RequestBody로 placeId, waybleZoneId를 받아 지정한 장소에서 웨이블존을 제거합니다."
)
@ApiResponses({
Expand All @@ -84,27 +84,27 @@ public CommonResponse<String> removeZoneFromPlace(
@RequestBody @Valid UserPlaceRemoveRequestDto request
) {
userPlaceService.removeZoneFromPlace(userId, request.placeId(), request.waybleZoneId());
return CommonResponse.success("제거되었습니다.");
return CommonResponse.success("성공적으로 제거되었습니다.");
}

@PostMapping("/zones")
@Operation(summary = "리스트에 웨이블존 추가",
description = "placeId와 waybleZoneId 배열을 받아 여러 웨이블존을 리스트에 추가합니다.")
@Operation(summary = "웨이블존에 저장한 리스트 추가 (여러개 가능)",
description = "웨이블존에 사용자가 요청한 리스트들을 추가합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "웨이블존 추가 성공"),
@ApiResponse(responseCode = "200", description = "웨이블존에 리스트 추가 성공"),
@ApiResponse(responseCode = "404", description = "유저/리스트/웨이블존을 찾을 수 없음")
})
public CommonResponse<String> addZonesToPlace(
@Parameter(hidden = true) @CurrentUser Long userId,
@RequestBody @Valid UserPlaceAddZonesRequestDto request
) {
userPlaceService.addZonesToPlace(userId, request.placeId(), request.waybleZoneIds());
return CommonResponse.success("리스트에 웨이블존이 추가되었습니다.");
int added = userPlaceService.addZoneToPlaces(userId, request.placeIds(), request.waybleZoneId());
return CommonResponse.success(String.format("%d개 리스트에 추가되었습니다.", added));
}

@GetMapping("/zones")
@Operation(summary = "특정 장소 내 웨이블존 목록 조회(페이징)",
description = "placeId로 해당 장소 내부의 웨이블존 카드 목록을 반환합니다. (page는 0부터 시작.)")
@Operation(summary = "저장한 리스트 내 웨이블존 목록 조회(페이징)",
description = "placeId로 해당 장소 내부의 웨이블존 목록을 반환합니다. (page는 0부터 시작.)")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "404", description = "유저/장소를 찾을 수 없음"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import java.util.List;

public record UserPlaceAddZonesRequestDto(
@NotNull Long placeId,
@NotEmpty List<Long> waybleZoneIds
@NotEmpty List<@NotNull Long> placeIds,
@NotNull Long waybleZoneId
) {}

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/com/wayble/server/user/dto/UserResponseDto.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum UserErrorCase implements ErrorCase {
NICKNAME_DUPLICATED(409,1013, "이미 사용 중인 닉네임입니다."),
PLACE_NOT_FOUND(404, 1014, "저장된 장소를 찾을 수 없습니다."),
PLACE_MAPPING_NOT_FOUND(404, 1015, "해당 장소에 해당 웨이블존이 없습니다."),
PLACE_TITLE_DUPLICATED(400, 1016, "동일한 이름의 리스트가 이미 있습니다.");
PLACE_TITLE_DUPLICATED(409, 1016, "동일한 이름의 리스트가 이미 있습니다.");

private final Integer httpStatusCode;
private final Integer errorCode;
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/com/wayble/server/user/service/UserPlaceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.wayble.server.common.exception.ApplicationException;
import com.wayble.server.user.dto.UserPlaceCreateRequestDto;
import com.wayble.server.user.dto.UserPlaceRequestDto;
import com.wayble.server.user.dto.UserPlaceSummaryDto;
import com.wayble.server.user.entity.User;
import com.wayble.server.user.entity.UserPlace;
Expand Down Expand Up @@ -59,18 +58,21 @@ public Long createPlaceList(Long userId, UserPlaceCreateRequestDto request) {
}

@Transactional
public void addZonesToPlace(Long userId, Long placeId, List<Long> waybleZoneIds) {
UserPlace place = userPlaceRepository.findByIdAndUser_Id(placeId, userId)
.orElseThrow(() -> new ApplicationException(UserErrorCase.PLACE_NOT_FOUND));
public int addZoneToPlaces(Long userId, List<Long> placeIds, Long waybleZoneId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new ApplicationException(UserErrorCase.USER_NOT_FOUND));

WaybleZone zone = waybleZoneRepository.findById(waybleZoneId)
.orElseThrow(() -> new ApplicationException(UserErrorCase.WAYBLE_ZONE_NOT_FOUND));

Set<Long> uniqueIds = new LinkedHashSet<>(waybleZoneIds);
Set<Long> uniquePlaceIds = new LinkedHashSet<>(placeIds);

int added = 0;
for (Long zoneId : uniqueIds) {
WaybleZone zone = waybleZoneRepository.findById(zoneId)
.orElseThrow(() -> new ApplicationException(UserErrorCase.WAYBLE_ZONE_NOT_FOUND));
for (Long placeId : uniquePlaceIds) {
UserPlace place = userPlaceRepository.findByIdAndUser_Id(placeId, user.getId())
.orElseThrow(() -> new ApplicationException(UserErrorCase.PLACE_NOT_FOUND));

boolean exists = mappingRepository.existsByUserPlace_IdAndWaybleZone_Id(placeId, zoneId);
boolean exists = mappingRepository.existsByUserPlace_IdAndWaybleZone_Id(placeId, waybleZoneId);
if (exists) continue;

mappingRepository.save(UserPlaceWaybleZoneMapping.builder()
Expand All @@ -79,16 +81,18 @@ public void addZonesToPlace(Long userId, Long placeId, List<Long> waybleZoneIds)
.build());

place.increaseCount();
zone.addLikes(1);
waybleZoneRepository.save(zone);
userPlaceRepository.save(place);

zone.addLikes(1); // 리스트 하나에 추가될 때마다 +1
added++;
}

if (added > 0) userPlaceRepository.save(place);
if (added > 0) {
waybleZoneRepository.save(zone);
}
return added;
}


@Transactional(readOnly = true)
public List<UserPlaceSummaryDto> getMyPlaceSummaries(Long userId, String sort) {
userRepository.findById(userId)
Expand Down