Skip to content

Commit

Permalink
[#56] feat : 수정 controller, dto
Browse files Browse the repository at this point in the history
  • Loading branch information
mmihye committed Jun 9, 2024
1 parent 3b510ab commit 712cf5b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Journey.Together.domain.place.controller;

import Journey.Together.domain.place.dto.request.PlaceReviewReq;
import Journey.Together.domain.place.dto.request.UpdateReviewDto;
import Journey.Together.domain.place.dto.response.*;
import Journey.Together.domain.place.service.PlaceService;
import Journey.Together.global.common.ApiResponse;
Expand All @@ -10,6 +11,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -40,11 +42,9 @@ public ApiResponse<PlaceDetailRes> getPlaceDetail(@AuthenticationPrincipal Princ
@PostMapping("/review/{placeId}")
public ApiResponse<?> createReivew(@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestPart(required = false) List<MultipartFile> images,
@RequestPart("placeReviewReq") PlaceReviewReq placeReviewReq,
@RequestBody PlaceReviewReq placeReviewReq,
@PathVariable Long placeId) {
if (images == null) {
images = new ArrayList<>(); // images가 null이면 빈 리스트로 초기화
}
images = (images == null) ? new ArrayList<>() : images;
placeService.createReview(principalDetails.getMember(), images,placeReviewReq, placeId);
return ApiResponse.success(Success.CREATE_PLACE_REVIEW_SUCCESS);
}
Expand Down Expand Up @@ -73,4 +73,17 @@ public ApiResponse<MyReview> getPlaceMyReview(
@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable Long reviewId) {
return ApiResponse.success(Success.GET_MY_PLACE_REVIEW_SUCCESS,placeService.getReview(principalDetails.getMember(),reviewId));
}

@PatchMapping("/review/my/{reviewId}")
public ApiResponse<?> updatePlaceMyReview(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestBody UpdateReviewDto updateReviewDto,
@RequestParam(required = false) List<String> deleteImages,
@RequestParam(required = false) List<MultipartFile> addImages,
@PathVariable Long reviewId) {
deleteImages = (deleteImages == null) ? new ArrayList<>() : deleteImages;
addImages = (addImages == null) ? new ArrayList<>() : addImages;
placeService.updateMyPlaceReview(principalDetails.getMember(),updateReviewDto,deleteImages,addImages,reviewId);
return ApiResponse.success(Success.UPDATE_MY_PLACE_REVIEW_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package Journey.Together.domain.place.dto.request;

import jakarta.annotation.Nullable;

import java.time.LocalDate;

public record UpdateReviewDto(
@Nullable
Float grade,
@Nullable
LocalDate date,
@Nullable
String content

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Journey.Together.domain.member.entity.Member;
import Journey.Together.domain.place.dto.request.PlaceReviewReq;
import Journey.Together.domain.place.dto.request.UpdateReviewDto;
import Journey.Together.domain.place.dto.response.*;
import Journey.Together.domain.place.entity.Place;
import Journey.Together.domain.place.repository.DisabilityPlaceCategoryRepository;
Expand Down Expand Up @@ -208,5 +209,13 @@ private MyPlaceReviewDto getMyPlaceReview(PlaceReview placeReview ){
}


public UpdateReviewDto updateMyPlaceReview(Member member, UpdateReviewDto updateReviewDto, List<String> deleteImages, List<MultipartFile> addImages, Long reviewId) {
PlaceReview placeReview = placeReviewRepository.findById(reviewId).orElseThrow(
() -> new ApplicationException(ErrorCode.NOT_FOUND_PLACE_REVIEW_EXCEPTION));

if(placeReview.getMember() != member){
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public enum Success {
DELETE_PLAN_SUCCESS(HttpStatus.OK, "일정 삭제 성공"),
DELETE_CATEGORY_SUCCESS(HttpStatus.OK, "카테고리 삭제 성공"),
DELETE_MY_PLACE_REVIEW_SUCCESS(HttpStatus.OK, "나의 여행지 후기 삭제 성공"),
UPDATE_MY_PLACE_REVIEW_SUCCESS(HttpStatus.OK, "나의 여행지 후기 수정 성공"),
SEARCH_SUCCESS(HttpStatus.OK, "검색 성공"),
PARSING_OG_SUCCESS(HttpStatus.OK, "og 데이터 파싱 결과입니다. 크롤링을 막은 페이지는 기본이미지가 나옵니다."),
UPDATE_PUSH_ALLOWED_SUCCESS(HttpStatus.OK, "푸시알림 수정 성공"),
Expand Down

0 comments on commit 712cf5b

Please sign in to comment.