Skip to content

Commit

Permalink
✨ Feature - Additional User APIs (#48)
Browse files Browse the repository at this point in the history
* chore: Article Command Role

* feat: Update Notification Status In User API

* feat: Update Device Token In User API

* feat: Connection Controller & Service
  • Loading branch information
HyungJoonSon authored Dec 5, 2024
1 parent 9368745 commit 4df40d5
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +24,8 @@
public class UserCommandV1Controller {

private final UpdateUserNotificationTimeUseCase updateUserNotificationTimeUseCase;
private final UpdateUserNotificationStatusUseCase updateUserNotificationStatusUseCase;
private final UpdateUserDeviceTokenUseCase updateUserDeviceTokenUseCase;

/**
* 4-2. 사용자 알림 시간 수정
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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
);

}
Original file line number Diff line number Diff line change
@@ -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
);

}

0 comments on commit 4df40d5

Please sign in to comment.