From 1ba984c95ea218ced61995b1ae695e2513d996e6 Mon Sep 17 00:00:00 2001 From: miyeon lee Date: Thu, 19 Oct 2023 17:58:54 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=B5=EC=9C=A0=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20url=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=20API=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=20=EC=99=84=EB=A3=8C=20(#171)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * modify : SecurityConfig에 url조회 api 허용하도록 수정 (#170) * refactor : 응답 및 예외 클래스 변경 (#170) * modify : MemberController url 수정 (#170) * modify : temporary.sql 주석 수정 (#170) --- .../javajober/member/controller/MemberController.java | 2 +- .../java/com/javajober/security/SecurityConfig.java | 1 + .../spaceWall/controller/SpaceWallController.java | 10 +++++----- .../spaceWall/repository/SpaceWallRepository.java | 8 +++++--- src/main/resources/db/temporary.sql | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/javajober/member/controller/MemberController.java b/src/main/java/com/javajober/member/controller/MemberController.java index b6b89918..508ad3b1 100644 --- a/src/main/java/com/javajober/member/controller/MemberController.java +++ b/src/main/java/com/javajober/member/controller/MemberController.java @@ -23,7 +23,7 @@ @RestController @Validated -@RequestMapping("api/members") +@RequestMapping("/api/members") public class MemberController { private final MemberService memberService; private final RefreshTokenService refreshTokenService; diff --git a/src/main/java/com/javajober/security/SecurityConfig.java b/src/main/java/com/javajober/security/SecurityConfig.java index 535ad3c7..da57669a 100644 --- a/src/main/java/com/javajober/security/SecurityConfig.java +++ b/src/main/java/com/javajober/security/SecurityConfig.java @@ -40,6 +40,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .antMatchers("/members/login").permitAll() .antMatchers("/members/signup").permitAll() .antMatchers("/healthCheck").permitAll() + .antMatchers("/api/wall/shareURL/**").permitAll() .anyRequest().authenticated() .and() .exceptionHandling() diff --git a/src/main/java/com/javajober/spaceWall/controller/SpaceWallController.java b/src/main/java/com/javajober/spaceWall/controller/SpaceWallController.java index 710eef69..07648f42 100644 --- a/src/main/java/com/javajober/spaceWall/controller/SpaceWallController.java +++ b/src/main/java/com/javajober/spaceWall/controller/SpaceWallController.java @@ -61,12 +61,12 @@ public ResponseEntity> hasSpace } @GetMapping("/wall/{memberId}/{addSpaceId}/{spaceWallId}") - public ResponseEntity> find ( + public ResponseEntity> 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}") @@ -78,12 +78,12 @@ public ResponseEntity> findPending( return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.SPACE_WALL_TEMPORARY_READ_SUCCESS, data)); } - @GetMapping("/wall/{shareURL}") - public ResponseEntity> findByShareURL(@PathVariable final String shareURL) { + @GetMapping("/wall/shareURL/{shareURL}") + public ResponseEntity> 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}") diff --git a/src/main/java/com/javajober/spaceWall/repository/SpaceWallRepository.java b/src/main/java/com/javajober/spaceWall/repository/SpaceWallRepository.java index c3bf3b9c..01967eb8 100644 --- a/src/main/java/com/javajober/spaceWall/repository/SpaceWallRepository.java +++ b/src/main/java/com/javajober/spaceWall/repository/SpaceWallRepository.java @@ -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; @@ -39,16 +41,16 @@ default List 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입니다.")); } } \ No newline at end of file diff --git a/src/main/resources/db/temporary.sql b/src/main/resources/db/temporary.sql index 985b7cda..e773b14a 100644 --- a/src/main/resources/db/temporary.sql +++ b/src/main/resources/db/temporary.sql @@ -17,7 +17,7 @@ VALUES ('변백현', 'baek2@gmail.com', '$2a$10$RdYW3w/9DZ/hU.Nklx1RyOy5RC7yNqQk ('박다은', 'daeun138@gmail.com', '$2a$10$RdYW3w/9DZ/hU.Nklx1RyOy5RC7yNqQk0JqIZXtw6HorY3Trkch86', '010-6789-2671', 'FREE', NOW(), NOW(), NULL), ('최수하', 'sooha139@gmail.com', '$2a$10$RdYW3w/9DZ/hU.Nklx1RyOy5RC7yNqQk0JqIZXtw6HorY3Trkch86', '010-6890-3782', 'FREE', NOW(), NOW(), NULL), ('김지하', 'jinha140@gmail.com', '$2a$10$RdYW3w/9DZ/hU.Nklx1RyOy5RC7yNqQk0JqIZXtw6HorY3Trkch86', '010-6901-4893', 'FREE', NOW(), NOW(), NULL); -// password : abcd1234@ +-- password : abcd1234@ INSERT INTO add_space (space_title, space_type, representative_name, member_id, created_at, updated_at, deleted_at) VALUES ('변백현', 'PERSONAL','변백현', 1, NOW(), NOW(), NULL),