Skip to content

Commit

Permalink
Merge pull request #156 from IT-Cotato/feature/155-refactor-place-api
Browse files Browse the repository at this point in the history
Feature: 장소 api 변경(#155)
  • Loading branch information
yooooonshine authored Jan 13, 2025
2 parents 4ca5cba + b5bea92 commit 9c2f2a6
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -20,8 +21,9 @@
import middle_point_search.backend.common.dto.ErrorResponse;
import middle_point_search.backend.common.util.MemberLoader;
import middle_point_search.backend.domains.member.domain.Member;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceSaveOrUpdateRequest;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlacesFindResponse;
import middle_point_search.backend.domains.place.dto.request.SavePlaceRequest;
import middle_point_search.backend.domains.place.dto.request.UpdatePlaceRequest;
import middle_point_search.backend.domains.place.dto.response.FindPlacesResponse;
import middle_point_search.backend.domains.place.service.PlaceService;

@Tag(name = "PLACE API", description = "회원 장소에 대한 API입니다.")
Expand Down Expand Up @@ -69,7 +71,7 @@ public class PlaceController {
)
public ResponseEntity<DataResponse<Void>> placeSave(
@PathVariable("roomId") Long roomId,
@RequestBody @Valid PlaceSaveOrUpdateRequest request
@RequestBody @Valid SavePlaceRequest request
) {
Member member = memberLoader.getMember();

Expand All @@ -78,12 +80,59 @@ public ResponseEntity<DataResponse<Void>> placeSave(
return ResponseEntity.ok(DataResponse.ok());
}

@PatchMapping("/rooms/{roomId}")
@Operation(
summary = "장소 변경하기",
description = """
placeId, 주소와 좌표를 사용하여 장소 변경
AccessToken 필요.""",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공"
),
@ApiResponse(
responseCode = "400",
description = "요청 파라미터가 잘못되었습니다.[C-202]",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "401",
description = "인증에 실패하였습니다.[C-101]",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "402",
description = "Access Token을 재발급해야합니다.[A-004]",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "403",
description = "해당 방의 회원이 아닙니다.[MR-003]",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
}
)
public ResponseEntity<DataResponse<Void>> updatePlace(
@PathVariable("roomId") Long roomId,
@RequestBody @Valid UpdatePlaceRequest request
) {
Member member = memberLoader.getMember();

placeService.updatePlace(roomId, member, request);

return ResponseEntity.ok(DataResponse.ok());
}

@GetMapping("/rooms/{roomId}")
@Operation(
summary = "장소 조회하기",
description = """
저장한 장소들 조회하기.
내가 저장한 장소들과 다른 회원이 저장한 장소들을 모두 조회한다.
AccessToken 필요.""",
responses = {
@ApiResponse(
Expand Down Expand Up @@ -112,16 +161,17 @@ public ResponseEntity<DataResponse<Void>> placeSave(
),
}
)
public ResponseEntity<DataResponse<PlacesFindResponse>> placesFind(
public ResponseEntity<DataResponse<FindPlacesResponse>> placesFind(
@PathVariable("roomId") Long roomId
) {
Long memberId = memberLoader.getMemberId();

PlacesFindResponse response = placeService.findPlaces(memberId, roomId);
FindPlacesResponse response = placeService.findPlaces(memberId, roomId);

return ResponseEntity.ok(DataResponse.from(response));
}


@DeleteMapping("/{placeId}")
@Operation(
summary = "장소 삭제하기",
Expand Down Expand Up @@ -166,3 +216,4 @@ public ResponseEntity<DataResponse<Void>> placeDelete(
return ResponseEntity.ok(DataResponse.ok());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import middle_point_search.backend.domains.member.domain.Member;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceSaveOrUpdateRequest;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceVO;
import middle_point_search.backend.domains.place.dto.request.SavePlaceRequest;
import middle_point_search.backend.domains.room.domain.Room;

@Entity
Expand Down Expand Up @@ -64,39 +63,27 @@ private Place(String siDo, String siGunGu, String roadNameAddress, Double addres
this.googlePlaceId = googlePlaceId;
}

public static Place from(PlaceSaveOrUpdateRequest placeSaveOrUpdateRequest, Room room, Member member,
String googlePlaceId) {
String siDo = placeSaveOrUpdateRequest.getSiDo();
String siGunGu = placeSaveOrUpdateRequest.getSiGunGu();
String roadNameAddress = placeSaveOrUpdateRequest.getRoadNameAddress();
Double addressLatitude = placeSaveOrUpdateRequest.getAddressLat();
Double addressLongitude = placeSaveOrUpdateRequest.getAddressLong();

return new Place(siDo, siGunGu, roadNameAddress, addressLatitude, addressLongitude, room, member,
googlePlaceId);
}

public PlaceVO toVO() {
return new PlaceVO(
this.id,
this.siDo,
this.siGunGu,
this.roadNameAddress,
this.addressLatitude,
this.addressLongitude
public static Place
from(
SavePlaceRequest request,
Room room,
Member member,
String googlePlaceId
) {
return new Place(
request.getSiDo(),
request.getSiGunGu(),
request.getRoadNameAddress(),
request.getAddressLat(),
request.getAddressLong(),
room,
member,
googlePlaceId
);
}

private void addRoom(Room room) {
this.room = room;
room.getPlaces().add(this);
}

public void update(PlaceSaveOrUpdateRequest request) {
this.siDo = request.getSiDo();
this.siGunGu = request.getSiGunGu();
this.roadNameAddress = request.getRoadNameAddress();
this.addressLatitude = request.getAddressLat();
this.addressLongitude = request.getAddressLong();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package middle_point_search.backend.domains.place.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SavePlaceRequest {

@NotBlank(message = "siDo는 비어 있을 수 없습니다.")
private String siDo;

@NotBlank(message = "siGunGu는 비어 있을 수 없습니다.")
private String siGunGu;

@NotBlank(message = "roadNameAddress는 비어 있을 수 없습니다.")
private String roadNameAddress;

@NotNull(message = "addressLat는 비어 있을 수 없습니다.")
private Double addressLat;

@NotNull(message = "addressLong는 비어 있을 수 없습니다.")
private Double addressLong;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package middle_point_search.backend.domains.place.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UpdatePlaceRequest {

@NotNull(message = "placeId는 비어 있을 수 없습니다.")
private Long placeId;

@NotBlank(message = "siDo는 비어 있을 수 없습니다.")
private String siDo;

@NotBlank(message = "siGunGu는 비어 있을 수 없습니다.")
private String siGunGu;

@NotBlank(message = "roadNameAddress는 비어 있을 수 없습니다.")
private String roadNameAddress;

@NotNull(message = "addressLat는 비어 있을 수 없습니다.")
private Double addressLat;

@NotNull(message = "addressLong는 비어 있을 수 없습니다.")
private Double addressLong;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package middle_point_search.backend.domains.place.dto.response;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;
import middle_point_search.backend.domains.place.domain.Place;

@Getter
@AllArgsConstructor
public class FindPlacesResponse {

private final Boolean myLocationExistence;
private final List<PlaceVO> myLocations;
private final Boolean friendLocationExistence;
private final List<PlaceVO> friendLocations;

@Getter
@AllArgsConstructor
public static class PlaceVO {
private final Long placeId;
private final String siDo;
private final String siGunGu;
private final String roadNameAddress;
private final Double addressLat;
private final Double addressLong;

public static PlaceVO from(Place place) {
return new PlaceVO(
place.getId(),
place.getSiDo(),
place.getSiGunGu(),
place.getRoadNameAddress(),
place.getAddressLatitude(),
place.getAddressLongitude()
);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import middle_point_search.backend.domains.place.domain.Place;

Expand All @@ -11,4 +14,24 @@ public interface PlaceRepository extends JpaRepository<Place, Long> {
List<Place> findAllByRoom_Id(Long roomId);

void deleteByIdAndRoom_Id(Long placeId, Long roomId);

@Modifying
@Query("UPDATE Place p " +
"SET p.member.id = :memberId, " +
" p.siDo = :siDo, " +
" p.siGunGu = :siGunGu, " +
" p.roadNameAddress = :roadNameAddress, " +
" p.addressLatitude = :addressLat, " +
" p.addressLongitude = :addressLong, " +
" p.googlePlaceId = :googlePlaceId " +
"WHERE p.id = :placeId")
void updatePlace(
@Param("memberId") Long memberId,
@Param("placeId") Long placeId,
@Param("googlePlaceId") String googlePlaceId,
@Param("siDo") String siDo,
@Param("siGunGu") String siGunGu,
@Param("roadNameAddress") String roadNameAddress,
@Param("addressLat") Double addressLat,
@Param("addressLong") Double addressLong);
}
Loading

0 comments on commit 9c2f2a6

Please sign in to comment.