Skip to content

Commit 8371e6a

Browse files
Merge pull request #6 from ModernWeb-Team3/feat/auth-user/fixing
✨ feat: 검색,토큰 재발급,로그아웃 기능 구현
2 parents 887faae + 4a7a81f commit 8371e6a

27 files changed

Lines changed: 296 additions & 259 deletions

File tree

src/main/java/kr/unideal/server/backend/domain/comment/controller/dto/CommentController.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public ApiResponse<?> getComments(@PathVariable Long postId) {
4343
@PatchMapping("/comments/{commentId}/private")
4444
public ApiResponse<String> toggleCommentPrivate(@CurrentUserId Long userId,
4545
@PathVariable Long commentId) {
46-
boolean newSecretStatus = commentService.toggleCommentSecret(userId, commentId);
46+
boolean newSecretStatus = commentService.setCommentSecret(userId, commentId);
4747
String message = newSecretStatus ? "비밀글로 설정되었습니다." : "비밀글 해제되었습니다.";
4848
return ApiResponse.ok(message);
4949
}
@@ -66,21 +66,4 @@ public ApiResponse<String> deleteComment(@CurrentUserId Long userId,
6666
return ApiResponse.ok("댓글이 삭제되었습니다.");
6767
}
6868

69-
70-
// 대댓글 수정
71-
@PatchMapping("comments/{commentId}/replies")
72-
public ApiResponse<String> updateReply(@CurrentUserId Long userId,
73-
@PathVariable Long commentId,
74-
@RequestBody CommentUpdatedRequest request) {
75-
commentService.updateReply(userId, commentId, request);
76-
return ApiResponse.ok("대댓글이 수정되었습니다.");
77-
}
78-
79-
// 대댓글 삭제
80-
@DeleteMapping("comments/{commentId}/replies")
81-
public ApiResponse<String> deleteReply(@CurrentUserId Long userId,
82-
@PathVariable Long commentId) {
83-
commentService.deleteComment(userId, commentId);
84-
return ApiResponse.ok("대댓글이 삭제되었습니다.");
85-
}
8669
}

src/main/java/kr/unideal/server/backend/domain/comment/entity/Comment.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,18 @@ public class Comment extends BaseTimeEntity {
2727
@Column(nullable = false)
2828
private boolean secret = false;
2929

30-
// 어떤 게시글(Post)에 달린 댓글인지
3130
@ManyToOne(fetch = FetchType.LAZY)
3231
@JoinColumn(name = "post_id")
3332
private Post post;
3433

35-
// 부모 댓글 (null이면 일반 댓글, 값이 있으면 대댓글)
3634
@ManyToOne(fetch = FetchType.LAZY)
3735
@JoinColumn(name = "parent_id")
3836
private Comment parent;
3937

40-
// 대댓글 목록
4138
@Builder.Default
4239
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
4340
private List<Comment> replies = new ArrayList<>();
4441

45-
4642
@ManyToOne(fetch = FetchType.LAZY)
4743
@JoinColumn(name = "user_id", nullable = false)
4844
private User user;

src/main/java/kr/unideal/server/backend/domain/comment/service/CommentService.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ public void registerReply(CommentRequest request, Long parentCommentId, Long use
8989
}
9090

9191

92-
// 대댓글 수정
93-
@Transactional
94-
public void updateReply(Long userId, Long commentId, CommentUpdatedRequest request) {
95-
Comment comment = getAuthorizedComment(userId, commentId);
96-
comment.updateContent(request.content(), request.isPrivate());
97-
98-
}
99-
10092
// 특정 게시글의 댓글 조회
10193
public List<CommentResponse> getComments(Long postId) {
10294
List<CommentResponse> comments = getAllCommentsByPostId(postId);
@@ -130,21 +122,9 @@ public Comment getCommentsByCommentId(Long commentId) {
130122
.orElseThrow(() -> new CustomException(COMMENT_NOT_FOUND));
131123
}
132124

125+
// 상태 변경
133126
@Transactional
134-
public void setCommentSecret(Long userId, Long commentId, boolean secret) {
135-
Comment comment = commentRepository.findById(commentId)
136-
.orElseThrow(() -> new CustomException(COMMENT_NOT_FOUND));
137-
138-
// 권한 체크 (작성자 본인인지 확인)
139-
if (!comment.getUser().getId().equals(userId)) {
140-
throw new CustomException(ErrorCode.ACCESS_DENY);
141-
}
142-
143-
comment.setSecret(secret);
144-
}
145-
146-
@Transactional
147-
public boolean toggleCommentSecret(Long userId, Long commentId) {
127+
public boolean setCommentSecret(Long userId, Long commentId) {
148128
Comment comment = commentRepository.findById(commentId)
149129
.orElseThrow(() -> new CustomException(COMMENT_NOT_FOUND));
150130

src/main/java/kr/unideal/server/backend/domain/post/controller/dto/PostController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public ApiResponse<List<PostListResponse>> getAllPosts() {
5151
@GetMapping("/{postId}")
5252
public ApiResponse<PostResponse> getPost(@PathVariable Long postId) {
5353
PostResponse response = postService.getPost(postId);
54-
5554
return ApiResponse.ok(response);
5655
}
5756

@@ -64,6 +63,11 @@ public ApiResponse<List<PostResponse>> getPostsByCategory(@RequestParam String c
6463
}
6564

6665
// 검색
66+
@GetMapping("/search")
67+
public ApiResponse<List<PostListResponse>> searchPosts(@RequestParam String keyword) {
68+
List<PostListResponse> posts = postService.searchPosts(keyword);
69+
return ApiResponse.ok(posts);
70+
}
6771

6872

6973
}

src/main/java/kr/unideal/server/backend/domain/post/controller/dto/request/PostRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
@Getter
88
public class PostRequest {
99

10-
// 이미지 여러장 list로 카테고리는 enum , 상품명, 설명, 거래장소 (enum) , 가격
1110
private String name;
1211
private String detail;
1312
private Integer price;

src/main/java/kr/unideal/server/backend/domain/post/controller/dto/response/PostListResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
@Builder
77
public record PostListResponse(
88

9-
109
String thumbnail, // 썸네일 이미지 URL
1110
String name, // 상품명
1211
String location,

src/main/java/kr/unideal/server/backend/domain/post/controller/dto/response/PostResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package kr.unideal.server.backend.domain.post.controller.dto.response;
22

3-
import kr.unideal.server.backend.domain.comment.controller.dto.response.CommentResponse;
43
import lombok.Builder;
54
import lombok.Getter;
65

src/main/java/kr/unideal/server/backend/domain/post/entity/Category.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public String getDescription() {
2222
return description;
2323
}
2424

25-
/**
26-
* 한글 설명으로 Category 찾기
27-
* JSON 직렬화 시 클라이언트로 "책", "의류" 등 description을 주고,
28-
* 다시 받았을 때 이 메서드가 매핑해 줍니다.
29-
*/
3025
@JsonCreator
3126
public static Category fromDescription(String desc) {
3227
String cleaned = desc.trim().replaceAll("^\"|\"$", "");

src/main/java/kr/unideal/server/backend/domain/post/entity/Image.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public class Image {
1616
@GeneratedValue(strategy = GenerationType.IDENTITY)
1717
private Long id;
1818

19-
private String url; // 이미지 저장된 경로 또는 URL
19+
private String url;
2020

2121
@ManyToOne(fetch = FetchType.LAZY)
2222
@JoinColumn(name = "post_id")
23-
private Post post; // 이미지가 속한 게시글
23+
private Post post;
2424
}

src/main/java/kr/unideal/server/backend/domain/post/entity/Post.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,9 @@ public class Post extends BaseTimeEntity {
5252

5353
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
5454
private List<Comment> commentList = new ArrayList<>();
55-
56-
public void updatePost(String name, String detail, Integer price, Status status) {
57-
this.name = name;
58-
this.detail = detail;
59-
this.price = price;
60-
this.status = status;
61-
}
62-
63-
public void updateStatus(Status status) {
64-
this.status=status;
65-
}
66-
55+
56+
57+
// 도메인 메서드
6758
public void clearImages() {
6859
for (Image image : imageList) {
6960
image.setPost(null); // 연관관계 제거
@@ -76,7 +67,7 @@ public void addImage(Image image) {
7667
image.setPost(this);
7768
}
7869

79-
public void updatePost(String name, String detail, Integer price, Status status, Category category,Campus location) {
70+
public void updatePost(String name, String detail, Integer price, Status status, Category category, Campus location) {
8071
this.name = name;
8172
this.detail = detail;
8273
this.price = price;

0 commit comments

Comments
 (0)