Skip to content

Commit

Permalink
refactor: change api endpoint of bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw1031 committed May 5, 2024
1 parent 204b373 commit 9353c4a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
39 changes: 39 additions & 0 deletions src/main/java/ac/knu/likeknu/controller/BookmarkController.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> removeBookmark(
@PathVariable("deviceId") String deviceId,
@PathVariable("announcementId") String announcementId
) {
bookmarkService.removeAnnouncementBookmark(deviceId, announcementId);
return ResponseDto.of("The bookmark has been removed successfully.");
}
}
25 changes: 1 addition & 24 deletions src/main/java/ac/knu/likeknu/controller/DeviceController.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
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;
import ac.knu.likeknu.controller.dto.device.request.DeviceTokenRequest;
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;
Expand All @@ -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
Expand All @@ -47,23 +41,6 @@ public ResponseDto<String> modifyCampus(@RequestBody CampusModificationRequest r
return ResponseDto.of("Campus has been changed successfully.");
}

@PostMapping("/{deviceId}/bookmarks")
public ResponseDto<String> 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<String> 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<String> registerTokenByDevice(@RequestBody DeviceTokenRequest request) {
deviceService.registerTokenByDevice(request);
Expand Down

0 comments on commit 9353c4a

Please sign in to comment.