From 4df40d5babf276c057e7627cc218564386260166 Mon Sep 17 00:00:00 2001 From: HyungJoon Date: Thu, 5 Dec 2024 20:58:19 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feature=20-=20Additional=20User=20A?= =?UTF-8?q?PIs=20(#48)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Article Command Role * feat: Update Notification Status In User API * feat: Update Device Token In User API * feat: Connection Controller & Service --- .../command/ArticleCommandV1Controller.java | 6 +-- .../command/UserCommandV1Controller.java | 42 +++++++++++++++++++ .../dto/request/UpdateUserDeviceTokenDto.java | 12 ++++++ .../UpdateUserNotificationStatusDto.java | 12 ++++++ .../service/UpdateUserDeviceTokenService.java | 32 ++++++++++++++ .../UpdateUserNotificationStatusService.java | 31 ++++++++++++++ .../usecase/UpdateUserDeviceTokenUseCase.java | 18 ++++++++ .../UpdateUserNotificationStatusUseCase.java | 18 ++++++++ 8 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/dto/request/UpdateUserDeviceTokenDto.java create mode 100644 server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/dto/request/UpdateUserNotificationStatusDto.java create mode 100644 server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/service/UpdateUserDeviceTokenService.java create mode 100644 server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/service/UpdateUserNotificationStatusService.java create mode 100644 server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/usecase/UpdateUserDeviceTokenUseCase.java create mode 100644 server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/usecase/UpdateUserNotificationStatusUseCase.java diff --git a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/article/controller/command/ArticleCommandV1Controller.java b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/article/controller/command/ArticleCommandV1Controller.java index 49d72f6..dbe01b7 100644 --- a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/article/controller/command/ArticleCommandV1Controller.java +++ b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/article/controller/command/ArticleCommandV1Controller.java @@ -30,7 +30,7 @@ public class ArticleCommandV1Controller { * @param requestDto 요청 DTO * @return 응답 DTO */ - @PreAuthorize("hasAnyRole('USER', 'EXPERT', 'ADMIN')") + @PreAuthorize("hasAnyRole('EXPERT', 'ADMIN')") @PostMapping public ResponseDto createArticle( @AccountID UUID accountId, @@ -49,7 +49,7 @@ public ResponseDto createArticle( * @param requestDto 요청 DTO * @return 응답 DTO */ - @PreAuthorize("hasAnyRole('USER', 'EXPERT', 'ADMIN')") + @PreAuthorize("hasAnyRole('EXPERT', 'ADMIN')") @PutMapping("/{articleId}") public ResponseDto updateArticle( @AccountID UUID accountId, @@ -68,7 +68,7 @@ public ResponseDto updateArticle( * @param articleId 칼럼 ID * @return 응답 DTO */ - @PreAuthorize("hasAnyRole('USER', 'EXPERT', 'ADMIN')") + @PreAuthorize("hasAnyRole('EXPERT', 'ADMIN')") @DeleteMapping("/{articleId}") public ResponseDto deleteArticle( @AccountID UUID accountId, diff --git a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/controller/command/UserCommandV1Controller.java b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/controller/command/UserCommandV1Controller.java index e49d4a0..747428f 100644 --- a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/controller/command/UserCommandV1Controller.java +++ b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/controller/command/UserCommandV1Controller.java @@ -4,7 +4,11 @@ import lombok.RequiredArgsConstructor; import org.dongguk.dscd.wooahan.api.core.annotation.common.AccountID; import org.dongguk.dscd.wooahan.api.core.dto.ResponseDto; +import org.dongguk.dscd.wooahan.api.user.dto.request.UpdateUserDeviceTokenDto; +import org.dongguk.dscd.wooahan.api.user.dto.request.UpdateUserNotificationStatusDto; import org.dongguk.dscd.wooahan.api.user.dto.request.UpdateUserNotificationTimeDto; +import org.dongguk.dscd.wooahan.api.user.usecase.UpdateUserDeviceTokenUseCase; +import org.dongguk.dscd.wooahan.api.user.usecase.UpdateUserNotificationStatusUseCase; import org.dongguk.dscd.wooahan.api.user.usecase.UpdateUserNotificationTimeUseCase; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PutMapping; @@ -20,6 +24,8 @@ public class UserCommandV1Controller { private final UpdateUserNotificationTimeUseCase updateUserNotificationTimeUseCase; + private final UpdateUserNotificationStatusUseCase updateUserNotificationStatusUseCase; + private final UpdateUserDeviceTokenUseCase updateUserDeviceTokenUseCase; /** * 4-2. 사용자 알림 시간 수정 @@ -38,4 +44,40 @@ public ResponseDto updateUserNotificationTime( return ResponseDto.ok(null); } + + /** + * 4-3. 사용자 알림 상태 수정 + * + * @param accountId 계정 ID + * @param requestDto 요청 DTO + * @return 응답 DTO + */ + @PreAuthorize("hasRole('USER')") + @PutMapping("/notification-status") + public ResponseDto updateUserNotificationTime( + @AccountID UUID accountId, + @RequestBody @Valid UpdateUserNotificationStatusDto requestDto + ) { + updateUserNotificationStatusUseCase.execute(accountId, requestDto); + + return ResponseDto.ok(null); + } + + /** + * 4-4. 사용자 기기 토큰 수정 + * + * @param accountId 계정 ID + * @param requestDto 요청 DTO + * @return 응답 DTO + */ + @PreAuthorize("hasRole('USER')") + @PutMapping("/device-token") + public ResponseDto updateUserNotificationTime( + @AccountID UUID accountId, + @RequestBody @Valid UpdateUserDeviceTokenDto requestDto + ) { + updateUserDeviceTokenUseCase.execute(accountId, requestDto); + + return ResponseDto.ok(null); + } } diff --git a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/dto/request/UpdateUserDeviceTokenDto.java b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/dto/request/UpdateUserDeviceTokenDto.java new file mode 100644 index 0000000..121a047 --- /dev/null +++ b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/dto/request/UpdateUserDeviceTokenDto.java @@ -0,0 +1,12 @@ +package org.dongguk.dscd.wooahan.api.user.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; + +public record UpdateUserDeviceTokenDto( + + @JsonProperty("device_token") + @NotNull + String deviceToken +) { +} diff --git a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/dto/request/UpdateUserNotificationStatusDto.java b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/dto/request/UpdateUserNotificationStatusDto.java new file mode 100644 index 0000000..e20c8c0 --- /dev/null +++ b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/dto/request/UpdateUserNotificationStatusDto.java @@ -0,0 +1,12 @@ +package org.dongguk.dscd.wooahan.api.user.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; + +public record UpdateUserNotificationStatusDto( + + @JsonProperty("is_allowed_notification") + @NotNull + Boolean isAllowedNotification +) { +} diff --git a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/service/UpdateUserDeviceTokenService.java b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/service/UpdateUserDeviceTokenService.java new file mode 100644 index 0000000..822b506 --- /dev/null +++ b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/service/UpdateUserDeviceTokenService.java @@ -0,0 +1,32 @@ +package org.dongguk.dscd.wooahan.api.user.service; + +import lombok.RequiredArgsConstructor; +import org.dongguk.dscd.wooahan.api.core.exception.error.ErrorCode; +import org.dongguk.dscd.wooahan.api.core.exception.type.CommonException; +import org.dongguk.dscd.wooahan.api.user.domain.mysql.User; +import org.dongguk.dscd.wooahan.api.user.dto.request.UpdateUserDeviceTokenDto; +import org.dongguk.dscd.wooahan.api.user.repository.mysql.UserRepository; +import org.dongguk.dscd.wooahan.api.user.usecase.UpdateUserDeviceTokenUseCase; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class UpdateUserDeviceTokenService implements UpdateUserDeviceTokenUseCase { + + private final UserRepository userRepository; + + @Override + @Transactional + public void execute( + UUID accountId, + UpdateUserDeviceTokenDto requestDto + ) { + User user = userRepository.findById(accountId) + .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_USER)); + + user.updateDeviceToken(requestDto.deviceToken()); + } +} diff --git a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/service/UpdateUserNotificationStatusService.java b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/service/UpdateUserNotificationStatusService.java new file mode 100644 index 0000000..21ceff3 --- /dev/null +++ b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/service/UpdateUserNotificationStatusService.java @@ -0,0 +1,31 @@ +package org.dongguk.dscd.wooahan.api.user.service; + +import lombok.RequiredArgsConstructor; +import org.dongguk.dscd.wooahan.api.core.exception.error.ErrorCode; +import org.dongguk.dscd.wooahan.api.core.exception.type.CommonException; +import org.dongguk.dscd.wooahan.api.user.domain.mysql.User; +import org.dongguk.dscd.wooahan.api.user.dto.request.UpdateUserNotificationStatusDto; +import org.dongguk.dscd.wooahan.api.user.dto.request.UpdateUserNotificationTimeDto; +import org.dongguk.dscd.wooahan.api.user.repository.mysql.UserRepository; +import org.dongguk.dscd.wooahan.api.user.usecase.UpdateUserNotificationStatusUseCase; +import org.dongguk.dscd.wooahan.api.user.usecase.UpdateUserNotificationTimeUseCase; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class UpdateUserNotificationStatusService implements UpdateUserNotificationStatusUseCase { + + private final UserRepository userRepository; + + @Override + @Transactional + public void execute(UUID accountId, UpdateUserNotificationStatusDto requestDto) { + User user = userRepository.findById(accountId) + .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_USER)); + + user.updateIsAllowedNotification(requestDto.isAllowedNotification()); + } +} diff --git a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/usecase/UpdateUserDeviceTokenUseCase.java b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/usecase/UpdateUserDeviceTokenUseCase.java new file mode 100644 index 0000000..d3e6f8e --- /dev/null +++ b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/usecase/UpdateUserDeviceTokenUseCase.java @@ -0,0 +1,18 @@ +package org.dongguk.dscd.wooahan.api.user.usecase; + +import org.dongguk.dscd.wooahan.api.user.dto.request.UpdateUserDeviceTokenDto; + +import java.util.UUID; + +public interface UpdateUserDeviceTokenUseCase { + /** + * 사용자 알림 시간 수정 + * @param accountId 계정 ID + * @param requestDto 요청 DTO + */ + void execute( + UUID accountId, + UpdateUserDeviceTokenDto requestDto + ); + +} diff --git a/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/usecase/UpdateUserNotificationStatusUseCase.java b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/usecase/UpdateUserNotificationStatusUseCase.java new file mode 100644 index 0000000..fbaa409 --- /dev/null +++ b/server-api/src/main/java/org/dongguk/dscd/wooahan/api/user/usecase/UpdateUserNotificationStatusUseCase.java @@ -0,0 +1,18 @@ +package org.dongguk.dscd.wooahan.api.user.usecase; + +import org.dongguk.dscd.wooahan.api.user.dto.request.UpdateUserNotificationStatusDto; + +import java.util.UUID; + +public interface UpdateUserNotificationStatusUseCase { + /** + * 사용자 알림 시간 수정 + * @param accountId 계정 ID + * @param requestDto 요청 DTO + */ + void execute( + UUID accountId, + UpdateUserNotificationStatusDto requestDto + ); + +}