Skip to content

Commit

Permalink
refactor : 응답 및 예외 클래스 변경 (Fastcampus-Final-Team3#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyounlee committed Oct 19, 2023
1 parent 46da04c commit d0804a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public ResponseEntity<ApiResponse.Response<SpaceWallTemporaryResponse>> hasSpace
}

@GetMapping("/wall/{memberId}/{addSpaceId}/{spaceWallId}")
public ResponseEntity<ApiUtils.ApiResponse<SpaceWallResponse>> find (
public ResponseEntity<ApiResponse.Response<SpaceWallResponse>> find (
@PathVariable final Long memberId, @PathVariable final Long addSpaceId, @PathVariable final Long spaceWallId){

SpaceWallResponse data = spaceWallFindService.find(memberId, addSpaceId, spaceWallId, FlagType.SAVED);

return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.SPACE_WALL_READ_SUCCESS, data));
return ApiResponse.response(ApiStatus.OK, "공유페이지 조회를 성공했습니다.", data);
}

@GetMapping("/wall-temporary/{memberId}/{addSpaceId}/{spaceWallId}")
Expand All @@ -78,12 +78,12 @@ public ResponseEntity<ApiUtils.ApiResponse<SpaceWallResponse>> findPending(
return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.SPACE_WALL_TEMPORARY_READ_SUCCESS, data));
}

@GetMapping("/wall/{shareURL}")
public ResponseEntity<ApiUtils.ApiResponse<SpaceWallResponse>> findByShareURL(@PathVariable final String shareURL) {
@GetMapping("/wall/shareURL/{shareURL}")
public ResponseEntity<ApiResponse.Response<SpaceWallResponse>> findByShareURL(@PathVariable final String shareURL) {

SpaceWallResponse data = spaceWallFindService.findByShareURL(shareURL);

return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.SPACE_WALL_READ_SUCCESS, data));
return ApiResponse.response(ApiStatus.OK, "공유페이지 조회를 성공했습니다.", data);
}

@GetMapping("/wall/has-duplicate/{shareURL}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.javajober.spaceWall.repository;

import com.javajober.exception.ApiStatus;
import com.javajober.exception.ApplicationException;
import com.javajober.spaceWall.domain.FlagType;
import com.javajober.spaceWall.domain.SpaceWall;
import org.springframework.data.jpa.repository.Query;
Expand Down Expand Up @@ -39,16 +41,16 @@ default List<SpaceWall> findSpaceWallsOrThrow(final Long memberId, final Long ad
default SpaceWall getById(final Long memberId, final Long spaceWallId) {
return findSpaceWalls(memberId, spaceWallId).stream()
.findFirst()
.orElseThrow(() -> new Exception404(ErrorMessage.ADD_SPACE_NOT_FOUND));
.orElseThrow(() -> new ApplicationException(ApiStatus.NOT_FOUND, "존재하지 않는 스페이스입니다."));
}

default SpaceWall findSpaceWall(Long id, Long addSpaceId, Long memberId, FlagType flag) {
return findByIdAndAddSpaceIdAndMemberIdAndFlag(id, addSpaceId, memberId, flag)
.orElseThrow(() -> new Exception404(ErrorMessage.SPACE_WALL_NOT_FOUND));
.orElseThrow(() -> new ApplicationException(ApiStatus.NOT_FOUND, "공유페이지를 찾을 수 없습니다."));
}

default SpaceWall getByShareURL(final String shareURL) {
return findByShareURL(shareURL)
.orElseThrow(() -> new Exception404(ErrorMessage.SHARE_URL_NOT_FOUND));
.orElseThrow(() -> new ApplicationException(ApiStatus.NOT_FOUND, "존재하지 않은 share url입니다."));
}
}

0 comments on commit d0804a4

Please sign in to comment.