Skip to content

Commit

Permalink
공유페이지 url로 조회 API 리팩토링 완료 (Fastcampus-Final-Team3#171)
Browse files Browse the repository at this point in the history
* modify : SecurityConfig에 url조회 api 허용하도록 수정 (Fastcampus-Final-Team3#170)

* refactor : 응답 및 예외 클래스 변경 (Fastcampus-Final-Team3#170)

* modify : MemberController url 수정 (Fastcampus-Final-Team3#170)

* modify : temporary.sql 주석 수정 (Fastcampus-Final-Team3#170)
  • Loading branch information
miyounlee authored Oct 19, 2023
1 parent dcc3aa8 commit 1ba984c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@RestController
@Validated
@RequestMapping("api/members")
@RequestMapping("/api/members")
public class MemberController {
private final MemberService memberService;
private final RefreshTokenService refreshTokenService;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/javajober/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
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입니다."));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/db/temporary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ VALUES ('변백현', '[email protected]', '$2a$10$RdYW3w/9DZ/hU.Nklx1RyOy5RC7yNqQk
('박다은', '[email protected]', '$2a$10$RdYW3w/9DZ/hU.Nklx1RyOy5RC7yNqQk0JqIZXtw6HorY3Trkch86', '010-6789-2671', 'FREE', NOW(), NOW(), NULL),
('최수하', '[email protected]', '$2a$10$RdYW3w/9DZ/hU.Nklx1RyOy5RC7yNqQk0JqIZXtw6HorY3Trkch86', '010-6890-3782', 'FREE', NOW(), NOW(), NULL),
('김지하', '[email protected]', '$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),
Expand Down

0 comments on commit 1ba984c

Please sign in to comment.