Skip to content

Commit

Permalink
Merge pull request #38 from HyeJiJUN11/feature/32-Comment
Browse files Browse the repository at this point in the history
feat: ๋Œ“๊ธ€/์•Œ๋ฆผ API ๊ตฌํ˜„
  • Loading branch information
peeerr authored Oct 4, 2024
2 parents 7a2ebb1 + 18d218a commit 632740d
Show file tree
Hide file tree
Showing 20 changed files with 624 additions and 187 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.potatocake.everymoment.controller;

import com.potatocake.everymoment.dto.SuccessResponse;
import com.potatocake.everymoment.dto.request.CommentRequest;
import com.potatocake.everymoment.security.MemberDetails;
import com.potatocake.everymoment.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/comments")
public class CommentController {

private final CommentService commentService;

//๋Œ“๊ธ€ ์ˆ˜์ •
@PatchMapping("/{commentId}")
public ResponseEntity<SuccessResponse<Void>> updateComment(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long commentId,
@RequestBody CommentRequest commentRequest) {
Long memberId = memberDetails.getId();

commentService.updateComment(memberId, commentId, commentRequest);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

//๋Œ“๊ธ€ ์‚ญ์ œ
@DeleteMapping("/{commentId}")
public ResponseEntity<SuccessResponse<Void>> deleteComment(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long commentId) {
Long memberId = memberDetails.getId();

commentService.deleteComment(memberId, commentId);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}
}
203 changes: 120 additions & 83 deletions src/main/java/com/potatocake/everymoment/controller/DiaryController.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.potatocake.everymoment.controller;

import com.potatocake.everymoment.dto.SuccessResponse;
import com.potatocake.everymoment.dto.request.CommentRequest;
import com.potatocake.everymoment.dto.request.DiaryAutoCreateRequest;
import com.potatocake.everymoment.dto.request.DiaryFilterRequest;
import com.potatocake.everymoment.dto.request.DiaryManualCreateRequest;
import com.potatocake.everymoment.dto.response.CommentsResponse;
import com.potatocake.everymoment.dto.response.FriendDiariesResponse;
import com.potatocake.everymoment.dto.response.FriendDiaryResponse;
import com.potatocake.everymoment.dto.response.MemberDetailResponse;
import com.potatocake.everymoment.dto.response.MyDiariesResponse;
import com.potatocake.everymoment.dto.response.MyDiaryResponse;
import com.potatocake.everymoment.dto.response.NotificationResponse;
import com.potatocake.everymoment.security.MemberDetails;
import com.potatocake.everymoment.service.CommentService;
import com.potatocake.everymoment.service.DiaryService;
import com.potatocake.everymoment.service.FriendDiaryService;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
Expand All @@ -33,36 +39,37 @@ public class DiaryController {

private final DiaryService diaryService;
private final FriendDiaryService friendDiaryService;
private final CommentService commentService;

//์ž๋™ ์ผ๊ธฐ ์ž‘์„ฑ
@PostMapping("/auto")
public ResponseEntity<SuccessResponse<NotificationResponse>> createDiaryAuto(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestBody DiaryAutoCreateRequest diaryAutoCreateRequest) {
NotificationResponse notificationResponse = diaryService.createDiaryAuto(diaryAutoCreateRequest);
SuccessResponse<NotificationResponse> response = SuccessResponse.<NotificationResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(notificationResponse)
.build();
return ResponseEntity.ok(response);
Long memberId = memberDetails.getId();

NotificationResponse response = diaryService.createDiaryAuto(memberId, diaryAutoCreateRequest);

return ResponseEntity.ok()
.body(SuccessResponse.ok(response));
}

//์ˆ˜๊ธฐ ์ผ๊ธฐ ์ž‘์„ฑ
@PostMapping("/manual")
public ResponseEntity<SuccessResponse<Void>> createDiaryManual(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestBody DiaryManualCreateRequest diaryManualCreateRequest) {
diaryService.createDiaryManual(diaryManualCreateRequest);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(null)
.build();
return ResponseEntity.ok(response);
Long memberId = memberDetails.getId();
diaryService.createDiaryManual(memberId, diaryManualCreateRequest);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

//๋‚ด ์ผ๊ธฐ ์ „์ฒด ์กฐํšŒ(ํƒ€์ž„๋ผ์ธ)
@GetMapping("/my")
public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String emoji,
@RequestParam(required = false) Long category,
Expand All @@ -73,6 +80,7 @@ public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
@RequestParam(defaultValue = "0") int key,
@RequestParam(defaultValue = "10") int size
) {
Long memberId = memberDetails.getId();
DiaryFilterRequest diaryFilterRequest = DiaryFilterRequest.builder()
.keyword(keyword)
.emoji(emoji)
Expand All @@ -85,79 +93,82 @@ public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
.size(size)
.build();

MyDiariesResponse myDiariesResponse = diaryService.getMyDiaries(diaryFilterRequest);
SuccessResponse<MyDiariesResponse> response = SuccessResponse.<MyDiariesResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(myDiariesResponse)
.build();
return ResponseEntity.ok(response);
MyDiariesResponse response = diaryService.getMyDiaries(memberId, diaryFilterRequest);

return ResponseEntity.ok()
.body(SuccessResponse.ok(response));
}

//๋‚ด ์ผ๊ธฐ ์ƒ์„ธ ์กฐํšŒ
@GetMapping("/my/{id}")
public ResponseEntity<SuccessResponse<MyDiaryResponse>> getMyDiary(@PathVariable Long id) {
MyDiaryResponse myDiaryResponse = diaryService.getMyDiary(id);
SuccessResponse<MyDiaryResponse> response = SuccessResponse.<MyDiaryResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(myDiaryResponse)
.build();
return ResponseEntity.ok(response);
@GetMapping("/my/{diaryId}")
public ResponseEntity<SuccessResponse<MyDiaryResponse>> getMyDiary(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long diaryId) {
Long memberId = memberDetails.getId();

MyDiaryResponse response = diaryService.getMyDiary(memberId, diaryId);

return ResponseEntity.ok()
.body(SuccessResponse.ok(response));
}

//์ผ๊ธฐ ์ˆ˜์ •
@PatchMapping("/{id}")
public ResponseEntity<SuccessResponse<Void>> updateDiary(@PathVariable Long id,
@RequestBody DiaryManualCreateRequest diaryManualCreateRequest) {
diaryService.updateDiary(id, diaryManualCreateRequest);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(null)
.build();
return ResponseEntity.ok(response);
@PatchMapping("/{diaryId}")
public ResponseEntity<SuccessResponse<Void>> updateDiary(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long diaryId,
@RequestBody DiaryManualCreateRequest diaryManualCreateRequest) {
Long memberId = memberDetails.getId();

diaryService.updateDiary(memberId, diaryId, diaryManualCreateRequest);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

//์ผ๊ธฐ ์‚ญ์ œ
@DeleteMapping("/{id}")
public ResponseEntity<SuccessResponse<Void>> deleteDiary(@PathVariable Long id) {
diaryService.deleteDiary(id);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(null)
.build();
return ResponseEntity.ok(response);
@DeleteMapping("/{diaryId}")
public ResponseEntity<SuccessResponse<Void>> deleteDiary(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long diaryId) {
Long memberId = memberDetails.getId();

diaryService.deleteDiary(memberId, diaryId);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

//๋ถ๋งˆํฌ ์„ค์ • ํ† ๊ธ€
@PatchMapping("/{id}/bookmark")
public ResponseEntity<SuccessResponse<Void>> toggleBookmark(@PathVariable Long id) {
diaryService.toggleBookmark(id);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(null)
.build();
return ResponseEntity.ok(response);
@PatchMapping("/{diaryId}/bookmark")
public ResponseEntity<SuccessResponse<Void>> toggleBookmark(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long diaryId) {
Long memberId = memberDetails.getId();

diaryService.toggleBookmark(memberId, diaryId);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

//๊ณต๊ฐœ ์„ค์ • ํ† ๊ธ€
@PatchMapping("/{id}/privacy")
public ResponseEntity<SuccessResponse<Void>> togglePrivacy(@PathVariable Long id) {
diaryService.togglePrivacy(id);
SuccessResponse<Void> response = SuccessResponse.<Void>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(null)
.build();
return ResponseEntity.ok(response);
@PatchMapping("/{diaryId}/privacy")
public ResponseEntity<SuccessResponse<Void>> togglePrivacy(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long diaryId) {
Long memberId = memberDetails.getId();

diaryService.togglePrivacy(memberId, diaryId);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

//์ „์ฒด ์นœ๊ตฌ ์ผ๊ธฐ ์กฐํšŒ
@GetMapping("/friend")
public ResponseEntity<SuccessResponse<FriendDiariesResponse>> getFriendDiaries(
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String emoji,
@RequestParam(required = false) Long category,
Expand All @@ -168,6 +179,7 @@ public ResponseEntity<SuccessResponse<FriendDiariesResponse>> getFriendDiaries(
@RequestParam(defaultValue = "0") int key,
@RequestParam(defaultValue = "10") int size
) {
Long memberId = memberDetails.getId();
DiaryFilterRequest diaryFilterRequest = DiaryFilterRequest.builder()
.keyword(keyword)
.emoji(emoji)
Expand All @@ -180,24 +192,49 @@ public ResponseEntity<SuccessResponse<FriendDiariesResponse>> getFriendDiaries(
.size(size)
.build();

FriendDiariesResponse diaries = friendDiaryService.getFriendDiaries(diaryFilterRequest);
SuccessResponse<FriendDiariesResponse> response = SuccessResponse.<FriendDiariesResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(diaries)
.build();
return ResponseEntity.ok(response);
FriendDiariesResponse response = friendDiaryService.getFriendDiaries(memberId, diaryFilterRequest);

return ResponseEntity.ok()
.body(SuccessResponse.ok(response));
}

//์นœ๊ตฌ ์ผ๊ธฐ ์ƒ์ œ ์กฐํšŒ
@GetMapping("/friend/{id}")
public ResponseEntity<SuccessResponse<FriendDiaryResponse>> getFriendDiary(@PathVariable Long id) {
FriendDiaryResponse diary = friendDiaryService.getFriendDiary(id);
SuccessResponse<FriendDiaryResponse> response = SuccessResponse.<FriendDiaryResponse>builder()
.code(HttpStatus.OK.value())
.message("success")
.info(diary)
.build();
return ResponseEntity.ok(response);
@GetMapping("/friend/{diaryId}")
public ResponseEntity<SuccessResponse<FriendDiaryResponse>> getFriendDiary(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long diaryId) {
Long memberId = memberDetails.getId();

FriendDiaryResponse response = friendDiaryService.getFriendDiary(memberId, diaryId);

return ResponseEntity.ok()
.body(SuccessResponse.ok(response));
}

//๋Œ“๊ธ€ ์กฐํšŒ
@GetMapping("/{diaryId}/comments")
public ResponseEntity<SuccessResponse<CommentsResponse>> getComments(
@PathVariable Long diaryId,
@RequestParam(defaultValue = "0") int key,
@RequestParam(defaultValue = "10") int size
) {
CommentsResponse response = commentService.getComments(diaryId, key, size);

return ResponseEntity.ok()
.body(SuccessResponse.ok(response));
}

//๋Œ“๊ธ€ ์ž‘์„ฑ
@PostMapping("/{diaryId}/comments")
public ResponseEntity<SuccessResponse<Void>> createComment(
@AuthenticationPrincipal MemberDetails memberDetails,
@PathVariable Long diaryId,
@RequestBody CommentRequest commentRequest) {
Long memberId = memberDetails.getId();

commentService.createComment(memberId, diaryId, commentRequest);

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}
}
Loading

0 comments on commit 632740d

Please sign in to comment.