Skip to content

Commit 90a0db7

Browse files
authored
Merge pull request #209 from solid-connection/develop
[RELEASE] 250215 릴리즈
2 parents 4dda1da + dc31e4d commit 90a0db7

47 files changed

Lines changed: 498 additions & 549 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/com/example/solidconnection/application/controller/ApplicationController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
import org.springframework.web.bind.annotation.RestController;
2020

2121
@RequiredArgsConstructor
22-
@RequestMapping("/application")
22+
@RequestMapping("/applications")
2323
@RestController
2424
public class ApplicationController {
2525

2626
private final ApplicationSubmissionService applicationSubmissionService;
2727
private final ApplicationQueryService applicationQueryService;
2828

2929
// 지원서 제출하기 api
30-
@PostMapping()
30+
@PostMapping
3131
public ResponseEntity<ApplicationSubmissionResponse> apply(
3232
@AuthorizedUser SiteUser siteUser,
3333
@Valid @RequestBody ApplyRequest applyRequest

src/main/java/com/example/solidconnection/auth/controller/AuthController.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
import com.example.solidconnection.auth.service.oauth.AppleOAuthService;
1717
import com.example.solidconnection.auth.service.oauth.KakaoOAuthService;
1818
import com.example.solidconnection.auth.service.oauth.OAuthSignUpService;
19+
import com.example.solidconnection.custom.exception.CustomException;
20+
import com.example.solidconnection.custom.exception.ErrorCode;
1921
import com.example.solidconnection.custom.resolver.AuthorizedUser;
20-
import com.example.solidconnection.custom.resolver.ExpiredToken;
21-
import com.example.solidconnection.custom.security.authentication.ExpiredTokenAuthentication;
2222
import com.example.solidconnection.siteuser.domain.AuthType;
2323
import com.example.solidconnection.siteuser.domain.SiteUser;
2424
import jakarta.validation.Valid;
2525
import lombok.RequiredArgsConstructor;
2626
import org.springframework.http.ResponseEntity;
27+
import org.springframework.security.core.Authentication;
2728
import org.springframework.web.bind.annotation.PatchMapping;
2829
import org.springframework.web.bind.annotation.PostMapping;
2930
import org.springframework.web.bind.annotation.RequestBody;
@@ -93,9 +94,13 @@ public ResponseEntity<SignInResponse> signUp(
9394

9495
@PostMapping("/sign-out")
9596
public ResponseEntity<Void> signOut(
96-
@ExpiredToken ExpiredTokenAuthentication expiredToken
97+
Authentication authentication
9798
) {
98-
authService.signOut(expiredToken.getToken());
99+
String token = authentication.getCredentials().toString();
100+
if (token == null) {
101+
throw new CustomException(ErrorCode.AUTHENTICATION_FAILED, "토큰이 없습니다.");
102+
}
103+
authService.signOut(token);
99104
return ResponseEntity.ok().build();
100105
}
101106

@@ -109,9 +114,13 @@ public ResponseEntity<Void> quit(
109114

110115
@PostMapping("/reissue")
111116
public ResponseEntity<ReissueResponse> reissueToken(
112-
@ExpiredToken ExpiredTokenAuthentication expiredToken
117+
Authentication authentication
113118
) {
114-
ReissueResponse reissueResponse = authService.reissue(expiredToken.getSubject());
119+
String token = authentication.getCredentials().toString();
120+
if (token == null) {
121+
throw new CustomException(ErrorCode.AUTHENTICATION_FAILED, "토큰이 없습니다.");
122+
}
123+
ReissueResponse reissueResponse = authService.reissue(token);
115124
return ResponseEntity.ok(reissueResponse);
116125
}
117126
}

src/main/java/com/example/solidconnection/auth/service/EmailSignInService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public SignInResponse signIn(EmailSignInRequest signInRequest) {
3535
throw new CustomException(USER_NOT_FOUND, "이메일과 비밀번호를 확인해주세요.");
3636
}
3737

38-
private void validatePassword(String rawPassword, String encodedPassword) throws CustomException {
38+
private void validatePassword(String rawPassword, String encodedPassword) {
3939
if (!passwordEncoder.matches(rawPassword, encodedPassword)) {
4040
throw new CustomException(USER_NOT_FOUND, "이메일과 비밀번호를 확인해주세요.");
4141
}
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
package com.example.solidconnection.community.board.controller;
22

3+
import com.example.solidconnection.community.post.dto.PostListResponse;
4+
import com.example.solidconnection.community.post.service.PostQueryService;
35
import com.example.solidconnection.type.BoardCode;
46
import lombok.RequiredArgsConstructor;
57
import org.springframework.http.ResponseEntity;
68
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
710
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RequestParam;
812
import org.springframework.web.bind.annotation.RestController;
913

1014
import java.util.ArrayList;
1115
import java.util.List;
1216

1317
@RestController
1418
@RequiredArgsConstructor
15-
@RequestMapping("/communities")
19+
@RequestMapping("/boards")
1620
public class BoardController {
1721

22+
private final PostQueryService postQueryService;
23+
1824
// todo: 회원별로 접근 가능한 게시판 목록 조회 기능 개발
19-
@GetMapping()
25+
@GetMapping
2026
public ResponseEntity<?> findAccessibleCodes() {
2127
List<String> accessibleCodeList = new ArrayList<>();
2228
for (BoardCode boardCode : BoardCode.values()) {
2329
accessibleCodeList.add(String.valueOf(boardCode));
2430
}
2531
return ResponseEntity.ok().body(accessibleCodeList);
2632
}
33+
34+
@GetMapping("/{code}")
35+
public ResponseEntity<?> findPostsByCodeAndCategory(
36+
@PathVariable(value = "code") String code,
37+
@RequestParam(value = "category", defaultValue = "전체") String category) {
38+
List<PostListResponse> postsByCodeAndPostCategory = postQueryService
39+
.findPostsByCodeAndPostCategory(code, category);
40+
return ResponseEntity.ok().body(postsByCodeAndPostCategory);
41+
}
2742
}

src/main/java/com/example/solidconnection/community/comment/controller/CommentController.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,36 @@
2121

2222
@RestController
2323
@RequiredArgsConstructor
24-
@RequestMapping("/posts")
24+
@RequestMapping("/comments")
2525
public class CommentController {
2626

2727
private final CommentService commentService;
2828

29-
@PostMapping("/{post_id}/comments")
29+
@PostMapping
3030
public ResponseEntity<?> createComment(
3131
@AuthorizedUser SiteUser siteUser,
32-
@PathVariable("post_id") Long postId,
3332
@Valid @RequestBody CommentCreateRequest commentCreateRequest
3433
) {
35-
CommentCreateResponse response = commentService.createComment(siteUser, postId, commentCreateRequest);
34+
CommentCreateResponse response = commentService.createComment(siteUser, commentCreateRequest);
3635
return ResponseEntity.ok().body(response);
3736
}
3837

39-
@PatchMapping("/{post_id}/comments/{comment_id}")
38+
@PatchMapping("/{comment_id}")
4039
public ResponseEntity<?> updateComment(
4140
@AuthorizedUser SiteUser siteUser,
42-
@PathVariable("post_id") Long postId,
4341
@PathVariable("comment_id") Long commentId,
4442
@Valid @RequestBody CommentUpdateRequest commentUpdateRequest
4543
) {
46-
CommentUpdateResponse response = commentService.updateComment(siteUser, postId, commentId, commentUpdateRequest);
44+
CommentUpdateResponse response = commentService.updateComment(siteUser, commentId, commentUpdateRequest);
4745
return ResponseEntity.ok().body(response);
4846
}
4947

50-
@DeleteMapping("/{post_id}/comments/{comment_id}")
48+
@DeleteMapping("/{comment_id}")
5149
public ResponseEntity<?> deleteCommentById(
5250
@AuthorizedUser SiteUser siteUser,
53-
@PathVariable("post_id") Long postId,
5451
@PathVariable("comment_id") Long commentId
5552
) {
56-
CommentDeleteResponse response = commentService.deleteCommentById(siteUser, postId, commentId);
53+
CommentDeleteResponse response = commentService.deleteCommentById(siteUser, commentId);
5754
return ResponseEntity.ok().body(response);
5855
}
5956
}

src/main/java/com/example/solidconnection/community/comment/dto/CommentCreateRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
import com.example.solidconnection.community.post.domain.Post;
55
import com.example.solidconnection.siteuser.domain.SiteUser;
66
import jakarta.validation.constraints.NotBlank;
7+
import jakarta.validation.constraints.NotNull;
78
import jakarta.validation.constraints.Size;
89

910
public record CommentCreateRequest(
11+
@NotNull(message = "게시글 ID를 설정해주세요.")
12+
Long postId,
13+
1014
@NotBlank(message = "댓글 내용은 빈 값일 수 없습니다.")
1115
@Size(min = 1, max = 255, message = "댓글 내용은 최소 1자 이상, 최대 255자 이하여야 합니다.")
1216
String content,

src/main/java/com/example/solidconnection/community/comment/service/CommentService.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import com.example.solidconnection.community.comment.dto.CommentUpdateResponse;
99
import com.example.solidconnection.community.comment.dto.PostFindCommentResponse;
1010
import com.example.solidconnection.community.comment.repository.CommentRepository;
11-
import com.example.solidconnection.custom.exception.CustomException;
1211
import com.example.solidconnection.community.post.domain.Post;
1312
import com.example.solidconnection.community.post.repository.PostRepository;
13+
import com.example.solidconnection.custom.exception.CustomException;
1414
import com.example.solidconnection.siteuser.domain.SiteUser;
15+
import com.example.solidconnection.siteuser.repository.SiteUserRepository;
1516
import lombok.RequiredArgsConstructor;
1617
import org.springframework.stereotype.Service;
1718
import org.springframework.transaction.annotation.Transactional;
@@ -22,13 +23,15 @@
2223
import static com.example.solidconnection.custom.exception.ErrorCode.CAN_NOT_UPDATE_DEPRECATED_COMMENT;
2324
import static com.example.solidconnection.custom.exception.ErrorCode.INVALID_COMMENT_LEVEL;
2425
import static com.example.solidconnection.custom.exception.ErrorCode.INVALID_POST_ACCESS;
26+
import static com.example.solidconnection.custom.exception.ErrorCode.USER_NOT_FOUND;
2527

2628
@Service
2729
@RequiredArgsConstructor
2830
public class CommentService {
2931

3032
private final CommentRepository commentRepository;
3133
private final PostRepository postRepository;
34+
private final SiteUserRepository siteUserRepository;
3235

3336
@Transactional(readOnly = true)
3437
public List<PostFindCommentResponse> findCommentsByPostId(SiteUser siteUser, Long postId) {
@@ -43,15 +46,23 @@ private Boolean isOwner(Comment comment, SiteUser siteUser) {
4346
}
4447

4548
@Transactional
46-
public CommentCreateResponse createComment(SiteUser siteUser, Long postId, CommentCreateRequest commentCreateRequest) {
47-
Post post = postRepository.getById(postId);
49+
public CommentCreateResponse createComment(SiteUser siteUser, CommentCreateRequest commentCreateRequest) {
50+
Post post = postRepository.getById(commentCreateRequest.postId());
4851

4952
Comment parentComment = null;
5053
if (commentCreateRequest.parentId() != null) {
5154
parentComment = commentRepository.getById(commentCreateRequest.parentId());
5255
validateCommentDepth(parentComment);
5356
}
54-
Comment createdComment = commentRepository.save(commentCreateRequest.toEntity(siteUser, post, parentComment));
57+
58+
/*
59+
* todo: siteUser를 영속 상태로 만들 수 있도록 컨트롤러에서 siteUserId 를 넘겨줄 것인지,
60+
* siteUser 에 postList 를 FetchType.EAGER 로 설정할 것인지,
61+
* post 와 siteUser 사이의 양방향을 끊을 것인지 생각해봐야한다.
62+
*/
63+
SiteUser siteUser1 = siteUserRepository.findById(siteUser.getId()).orElseThrow(() -> new CustomException(USER_NOT_FOUND));
64+
Comment comment = commentCreateRequest.toEntity(siteUser1, post, parentComment);
65+
Comment createdComment = commentRepository.save(comment);
5566

5667
return CommentCreateResponse.from(createdComment);
5768
}
@@ -64,8 +75,7 @@ private void validateCommentDepth(Comment parentComment) {
6475
}
6576

6677
@Transactional
67-
public CommentUpdateResponse updateComment(SiteUser siteUser, Long postId, Long commentId, CommentUpdateRequest commentUpdateRequest) {
68-
Post post = postRepository.getById(postId);
78+
public CommentUpdateResponse updateComment(SiteUser siteUser, Long commentId, CommentUpdateRequest commentUpdateRequest) {
6979
Comment comment = commentRepository.getById(commentId);
7080
validateDeprecated(comment);
7181
validateOwnership(comment, siteUser);
@@ -82,8 +92,7 @@ private void validateDeprecated(Comment comment) {
8292
}
8393

8494
@Transactional
85-
public CommentDeleteResponse deleteCommentById(SiteUser siteUser, Long postId, Long commentId) {
86-
Post post = postRepository.getById(postId);
95+
public CommentDeleteResponse deleteCommentById(SiteUser siteUser, Long commentId) {
8796
Comment comment = commentRepository.getById(commentId);
8897
validateOwnership(comment, siteUser);
8998

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.example.solidconnection.community.post.controller;
22

3-
import com.example.solidconnection.community.post.dto.PostListResponse;
4-
import com.example.solidconnection.custom.resolver.AuthorizedUser;
53
import com.example.solidconnection.community.post.dto.PostCreateRequest;
64
import com.example.solidconnection.community.post.dto.PostCreateResponse;
75
import com.example.solidconnection.community.post.dto.PostDeleteResponse;
@@ -13,6 +11,7 @@
1311
import com.example.solidconnection.community.post.service.PostCommandService;
1412
import com.example.solidconnection.community.post.service.PostLikeService;
1513
import com.example.solidconnection.community.post.service.PostQueryService;
14+
import com.example.solidconnection.custom.resolver.AuthorizedUser;
1615
import com.example.solidconnection.siteuser.domain.SiteUser;
1716
import jakarta.validation.Valid;
1817
import lombok.RequiredArgsConstructor;
@@ -33,41 +32,29 @@
3332

3433
@RestController
3534
@RequiredArgsConstructor
36-
@RequestMapping("/communities")
35+
@RequestMapping("/posts")
3736
public class PostController {
3837

3938
private final PostQueryService postQueryService;
4039
private final PostCommandService postCommandService;
4140
private final PostLikeService postLikeService;
4241

43-
@GetMapping("/{code}")
44-
public ResponseEntity<?> findPostsByCodeAndCategory(
45-
@PathVariable(value = "code") String code,
46-
@RequestParam(value = "category", defaultValue = "전체") String category) {
47-
48-
List<PostListResponse> postsByCodeAndPostCategory = postQueryService
49-
.findPostsByCodeAndPostCategory(code, category);
50-
return ResponseEntity.ok().body(postsByCodeAndPostCategory);
51-
}
52-
53-
@PostMapping(value = "/{code}/posts")
42+
@PostMapping
5443
public ResponseEntity<?> createPost(
5544
@AuthorizedUser SiteUser siteUser,
56-
@PathVariable("code") String code,
5745
@Valid @RequestPart("postCreateRequest") PostCreateRequest postCreateRequest,
5846
@RequestParam(value = "file", required = false) List<MultipartFile> imageFile
5947
) {
6048
if (imageFile == null) {
6149
imageFile = Collections.emptyList();
6250
}
63-
PostCreateResponse post = postCommandService.createPost(siteUser, code, postCreateRequest, imageFile);
51+
PostCreateResponse post = postCommandService.createPost(siteUser, postCreateRequest, imageFile);
6452
return ResponseEntity.ok().body(post);
6553
}
6654

67-
@PatchMapping(value = "/{code}/posts/{post_id}")
55+
@PatchMapping(value = "/{post_id}")
6856
public ResponseEntity<?> updatePost(
6957
@AuthorizedUser SiteUser siteUser,
70-
@PathVariable("code") String code,
7158
@PathVariable("post_id") Long postId,
7259
@Valid @RequestPart("postUpdateRequest") PostUpdateRequest postUpdateRequest,
7360
@RequestParam(value = "file", required = false) List<MultipartFile> imageFile
@@ -76,48 +63,44 @@ public ResponseEntity<?> updatePost(
7663
imageFile = Collections.emptyList();
7764
}
7865
PostUpdateResponse postUpdateResponse = postCommandService.updatePost(
79-
siteUser, code, postId, postUpdateRequest, imageFile
66+
siteUser, postId, postUpdateRequest, imageFile
8067
);
8168
return ResponseEntity.ok().body(postUpdateResponse);
8269
}
8370

84-
@GetMapping("/{code}/posts/{post_id}")
71+
@GetMapping("/{post_id}")
8572
public ResponseEntity<?> findPostById(
8673
@AuthorizedUser SiteUser siteUser,
87-
@PathVariable("code") String code,
8874
@PathVariable("post_id") Long postId
8975
) {
90-
PostFindResponse postFindResponse = postQueryService.findPostById(siteUser, code, postId);
76+
PostFindResponse postFindResponse = postQueryService.findPostById(siteUser, postId);
9177
return ResponseEntity.ok().body(postFindResponse);
9278
}
9379

94-
@DeleteMapping(value = "/{code}/posts/{post_id}")
80+
@DeleteMapping(value = "/{post_id}")
9581
public ResponseEntity<?> deletePostById(
9682
@AuthorizedUser SiteUser siteUser,
97-
@PathVariable("code") String code,
9883
@PathVariable("post_id") Long postId
9984
) {
100-
PostDeleteResponse postDeleteResponse = postCommandService.deletePostById(siteUser, code, postId);
85+
PostDeleteResponse postDeleteResponse = postCommandService.deletePostById(siteUser, postId);
10186
return ResponseEntity.ok().body(postDeleteResponse);
10287
}
10388

104-
@PostMapping(value = "/{code}/posts/{post_id}/like")
89+
@PostMapping(value = "/{post_id}/like")
10590
public ResponseEntity<?> likePost(
10691
@AuthorizedUser SiteUser siteUser,
107-
@PathVariable("code") String code,
10892
@PathVariable("post_id") Long postId
10993
) {
110-
PostLikeResponse postLikeResponse = postLikeService.likePost(siteUser, code, postId);
94+
PostLikeResponse postLikeResponse = postLikeService.likePost(siteUser, postId);
11195
return ResponseEntity.ok().body(postLikeResponse);
11296
}
11397

114-
@DeleteMapping(value = "/{code}/posts/{post_id}/like")
98+
@DeleteMapping(value = "/{post_id}/like")
11599
public ResponseEntity<?> dislikePost(
116100
@AuthorizedUser SiteUser siteUser,
117-
@PathVariable("code") String code,
118101
@PathVariable("post_id") Long postId
119102
) {
120-
PostDislikeResponse postDislikeResponse = postLikeService.dislikePost(siteUser, code, postId);
103+
PostDislikeResponse postDislikeResponse = postLikeService.dislikePost(siteUser, postId);
121104
return ResponseEntity.ok().body(postDislikeResponse);
122105
}
123106
}

src/main/java/com/example/solidconnection/community/post/dto/PostCreateRequest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import jakarta.validation.constraints.Size;
1010

1111
public record PostCreateRequest(
12+
@NotNull(message = "게시글 카테고리를 설정해주세요.")
13+
String boardCode,
14+
1215
@NotNull(message = "게시글 카테고리를 설정해주세요.")
1316
String postCategory,
1417

0 commit comments

Comments
 (0)