From 9353c4acf188f170355dd934e51384f89434a18b Mon Sep 17 00:00:00 2001 From: jcw1031 Date: Sun, 5 May 2024 19:46:17 +0900 Subject: [PATCH] refactor: change api endpoint of bookmarks --- .../controller/BookmarkController.java | 39 +++++++++++++++++++ .../likeknu/controller/DeviceController.java | 25 +----------- 2 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 src/main/java/ac/knu/likeknu/controller/BookmarkController.java diff --git a/src/main/java/ac/knu/likeknu/controller/BookmarkController.java b/src/main/java/ac/knu/likeknu/controller/BookmarkController.java new file mode 100644 index 0000000..f183c44 --- /dev/null +++ b/src/main/java/ac/knu/likeknu/controller/BookmarkController.java @@ -0,0 +1,39 @@ +package ac.knu.likeknu.controller; + +import ac.knu.likeknu.controller.dto.base.ResponseDto; +import ac.knu.likeknu.controller.dto.device.request.BookmarkRequest; +import ac.knu.likeknu.service.BookmarkService; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequestMapping("/api/bookmarks") +@RestController +public class BookmarkController { + + private final BookmarkService bookmarkService; + + public BookmarkController(BookmarkService bookmarkService) { + this.bookmarkService = bookmarkService; + } + + @PostMapping("/{deviceId}") + public ResponseDto createNewBookmark( + @PathVariable("deviceId") String deviceId, @RequestBody BookmarkRequest request + ) { + bookmarkService.addAnnouncementBookmark(deviceId, request.announcementId()); + return ResponseDto.of("The bookmark has been created successfully."); + } + + @DeleteMapping("/{deviceId}/{announcementId}") + public ResponseDto removeBookmark( + @PathVariable("deviceId") String deviceId, + @PathVariable("announcementId") String announcementId + ) { + bookmarkService.removeAnnouncementBookmark(deviceId, announcementId); + return ResponseDto.of("The bookmark has been removed successfully."); + } +} diff --git a/src/main/java/ac/knu/likeknu/controller/DeviceController.java b/src/main/java/ac/knu/likeknu/controller/DeviceController.java index 236677f..717f4e9 100644 --- a/src/main/java/ac/knu/likeknu/controller/DeviceController.java +++ b/src/main/java/ac/knu/likeknu/controller/DeviceController.java @@ -1,7 +1,6 @@ package ac.knu.likeknu.controller; import ac.knu.likeknu.controller.dto.base.ResponseDto; -import ac.knu.likeknu.controller.dto.device.request.BookmarkRequest; import ac.knu.likeknu.controller.dto.device.request.CampusModificationRequest; import ac.knu.likeknu.controller.dto.device.request.ChangeNotificationRequest; import ac.knu.likeknu.controller.dto.device.request.DeviceRegistrationRequest; @@ -9,11 +8,8 @@ import ac.knu.likeknu.controller.dto.device.request.SubscribeTagsUpdateRequest; import ac.knu.likeknu.controller.dto.device.response.SubscribeTagListResponse; import ac.knu.likeknu.controller.dto.device.response.TurnOnNotificationResponse; -import ac.knu.likeknu.service.BookmarkService; import ac.knu.likeknu.service.DeviceService; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -28,11 +24,9 @@ public class DeviceController { private final DeviceService deviceService; - private final BookmarkService bookmarkService; - public DeviceController(DeviceService deviceService, BookmarkService bookmarkService) { + public DeviceController(DeviceService deviceService) { this.deviceService = deviceService; - this.bookmarkService = bookmarkService; } @PostMapping @@ -47,23 +41,6 @@ public ResponseDto modifyCampus(@RequestBody CampusModificationRequest r return ResponseDto.of("Campus has been changed successfully."); } - @PostMapping("/{deviceId}/bookmarks") - public ResponseDto createNewBookmark( - @PathVariable("deviceId") String deviceId, @RequestBody BookmarkRequest request - ) { - bookmarkService.addAnnouncementBookmark(deviceId, request.announcementId()); - return ResponseDto.of("The bookmark has been created successfully."); - } - - @DeleteMapping("/{deviceId}/bookmarks/{announcementId}") - public ResponseDto removeBookmark( - @PathVariable("deviceId") String deviceId, - @PathVariable("announcementId") String announcementId - ) { - bookmarkService.removeAnnouncementBookmark(deviceId, announcementId); - return ResponseDto.of("The bookmark has been removed successfully."); - } - @PostMapping("/token") public ResponseDto registerTokenByDevice(@RequestBody DeviceTokenRequest request) { deviceService.registerTokenByDevice(request);