diff --git a/http/account/AccountControllerHttpRequest.http b/http/account/AccountControllerHttpRequest.http index b4cda30..51268ff 100644 --- a/http/account/AccountControllerHttpRequest.http +++ b/http/account/AccountControllerHttpRequest.http @@ -27,3 +27,8 @@ Authorization: Bearer {{access_token}} // @no-log GET {{host_url}}/api/v1/users/overviews Authorization: Bearer {{access_token}} + +### 3.5 푸시알림 설정 변경(토글) +// @no-log +PATCH {{host_url}}/api/v1/users/notification-allowed +Authorization: Bearer {{access_token}} diff --git a/src/main/java/com/daon/onjung/account/application/controller/command/AccountCommandV1Controller.java b/src/main/java/com/daon/onjung/account/application/controller/command/AccountCommandV1Controller.java index 57bf941..0401db1 100644 --- a/src/main/java/com/daon/onjung/account/application/controller/command/AccountCommandV1Controller.java +++ b/src/main/java/com/daon/onjung/account/application/controller/command/AccountCommandV1Controller.java @@ -1,19 +1,26 @@ package com.daon.onjung.account.application.controller.command; import com.daon.onjung.account.application.dto.request.CreateStoreHistoryRequestDto; +import com.daon.onjung.account.application.dto.response.UpdateUserNotificationAllowedResponseDto; import com.daon.onjung.account.application.usecase.CreateStoreHistoryUseCase; +import com.daon.onjung.account.application.usecase.UpdateUserNotificationAllowedUseCase; +import com.daon.onjung.core.annotation.security.AccountID; import com.daon.onjung.core.dto.ResponseDto; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import java.util.UUID; + @RestController @RequiredArgsConstructor public class AccountCommandV1Controller { private final CreateStoreHistoryUseCase createStoreHistoryUseCase; + private final UpdateUserNotificationAllowedUseCase updateUserNotificationAllowedUseCase; /** * 3.3 가게 히스토리 등록하기 @@ -25,4 +32,16 @@ public ResponseDto createStoreHistory( createStoreHistoryUseCase.execute(requestDto); return ResponseDto.ok(null); } + + /** + * 3.5 푸시알림 설정 변경(토글) + */ + @PatchMapping("/api/v1/users/notification-allowed") + public ResponseDto updateNotificationAllowed( + @AccountID UUID accountId + ) { + return ResponseDto.ok( + updateUserNotificationAllowedUseCase.execute(accountId) + ); + } } diff --git a/src/main/java/com/daon/onjung/account/application/controller/query/AccountQueryV1Controller.java b/src/main/java/com/daon/onjung/account/application/controller/query/AccountQueryV1Controller.java index b4e1b8f..003fc07 100644 --- a/src/main/java/com/daon/onjung/account/application/controller/query/AccountQueryV1Controller.java +++ b/src/main/java/com/daon/onjung/account/application/controller/query/AccountQueryV1Controller.java @@ -58,7 +58,7 @@ public ResponseDto readStoreDetail( } /** - * 3.3 사용자 정보 조회 + * 3.4 사용자 정보 조회 */ @GetMapping("/users/overviews") public ResponseDto readUserOverview( diff --git a/src/main/java/com/daon/onjung/account/application/dto/response/UpdateUserNotificationAllowedResponseDto.java b/src/main/java/com/daon/onjung/account/application/dto/response/UpdateUserNotificationAllowedResponseDto.java new file mode 100644 index 0000000..0916007 --- /dev/null +++ b/src/main/java/com/daon/onjung/account/application/dto/response/UpdateUserNotificationAllowedResponseDto.java @@ -0,0 +1,26 @@ +package com.daon.onjung.account.application.dto.response; + +import com.daon.onjung.account.domain.User; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class UpdateUserNotificationAllowedResponseDto { + + @JsonProperty("notification_allowed") + private final Boolean notificationAllowed; + + @Builder + public UpdateUserNotificationAllowedResponseDto( + Boolean notificationAllowed + ) { + this.notificationAllowed = notificationAllowed; + } + + public static UpdateUserNotificationAllowedResponseDto fromEntity(User user) { + return UpdateUserNotificationAllowedResponseDto.builder() + .notificationAllowed(user.getNotificationAllowed()) + .build(); + } +} diff --git a/src/main/java/com/daon/onjung/account/application/service/UpdateUserNotificationAllowedService.java b/src/main/java/com/daon/onjung/account/application/service/UpdateUserNotificationAllowedService.java new file mode 100644 index 0000000..436818e --- /dev/null +++ b/src/main/java/com/daon/onjung/account/application/service/UpdateUserNotificationAllowedService.java @@ -0,0 +1,41 @@ +package com.daon.onjung.account.application.service; + +import com.daon.onjung.account.application.dto.response.UpdateUserNotificationAllowedResponseDto; +import com.daon.onjung.account.application.usecase.UpdateUserNotificationAllowedUseCase; +import com.daon.onjung.account.domain.User; +import com.daon.onjung.account.repository.mysql.UserRepository; +import com.daon.onjung.core.exception.error.ErrorCode; +import com.daon.onjung.core.exception.type.CommonException; +import com.daon.onjung.security.domain.mysql.Account; +import com.daon.onjung.security.domain.service.AccountService; +import com.daon.onjung.security.repository.mysql.AccountRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class UpdateUserNotificationAllowedService implements UpdateUserNotificationAllowedUseCase { + + private final UserRepository userRepository; + + private final AccountService accountService; + private final AccountRepository accountRepository; + + @Override + @Transactional + public UpdateUserNotificationAllowedResponseDto execute(UUID accountId) { + + // Account 조회 + Account account = userRepository.findById(accountId) + .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESOURCE)); + + // Notification 허용 여부 업데이트 + account = accountService.updateNotificationAllowed(account); + accountRepository.save(account); + + return UpdateUserNotificationAllowedResponseDto.fromEntity((User) account); + } +} diff --git a/src/main/java/com/daon/onjung/account/application/usecase/UpdateUserNotificationAllowedUseCase.java b/src/main/java/com/daon/onjung/account/application/usecase/UpdateUserNotificationAllowedUseCase.java new file mode 100644 index 0000000..aadf781 --- /dev/null +++ b/src/main/java/com/daon/onjung/account/application/usecase/UpdateUserNotificationAllowedUseCase.java @@ -0,0 +1,12 @@ +package com.daon.onjung.account.application.usecase; + +import com.daon.onjung.account.application.dto.response.UpdateUserNotificationAllowedResponseDto; +import com.daon.onjung.core.annotation.bean.UseCase; + +import java.util.UUID; + +@UseCase +public interface UpdateUserNotificationAllowedUseCase { + + UpdateUserNotificationAllowedResponseDto execute(UUID accountId); +} diff --git a/src/main/java/com/daon/onjung/security/domain/mysql/Account.java b/src/main/java/com/daon/onjung/security/domain/mysql/Account.java index fb2eef5..add8ee1 100644 --- a/src/main/java/com/daon/onjung/security/domain/mysql/Account.java +++ b/src/main/java/com/daon/onjung/security/domain/mysql/Account.java @@ -77,8 +77,8 @@ public void updateDeviceToken(String deviceToken) { this.deviceToken = deviceToken; } - public void updateNotificationAllowed(Boolean notificationAllowed) { - this.notificationAllowed = notificationAllowed; + public void updateNotificationAllowed() { + this.notificationAllowed = !this.notificationAllowed; } public abstract ESecurityRole getRole(); diff --git a/src/main/java/com/daon/onjung/security/domain/service/AccountService.java b/src/main/java/com/daon/onjung/security/domain/service/AccountService.java index c9d0f8a..ccff6df 100644 --- a/src/main/java/com/daon/onjung/security/domain/service/AccountService.java +++ b/src/main/java/com/daon/onjung/security/domain/service/AccountService.java @@ -15,4 +15,9 @@ public Account updateDeviceToken(Account account, String deviceToken) { account.updateDeviceToken(deviceToken); return account; } + + public Account updateNotificationAllowed(Account account) { + account.updateNotificationAllowed(); + return account; + } }