Skip to content

Commit

Permalink
✨ Feature/#81 - 3.5 푸시알림 설정 변경(토글) API 구현 (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
dongkyeomjang authored Nov 21, 2024
1 parent 0af0815 commit e089392
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 3 deletions.
5 changes: 5 additions & 0 deletions http/account/AccountControllerHttpRequest.http
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Original file line number Diff line number Diff line change
@@ -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 가게 히스토리 등록하기
Expand All @@ -25,4 +32,16 @@ public ResponseDto<Void> createStoreHistory(
createStoreHistoryUseCase.execute(requestDto);
return ResponseDto.ok(null);
}

/**
* 3.5 푸시알림 설정 변경(토글)
*/
@PatchMapping("/api/v1/users/notification-allowed")
public ResponseDto<UpdateUserNotificationAllowedResponseDto> updateNotificationAllowed(
@AccountID UUID accountId
) {
return ResponseDto.ok(
updateUserNotificationAllowedUseCase.execute(accountId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ResponseDto<ReadStoreDetailResponseDto> readStoreDetail(
}

/**
* 3.3 사용자 정보 조회
* 3.4 사용자 정보 조회
*/
@GetMapping("/users/overviews")
public ResponseDto<ReadUserOverviewsResponseDto> readUserOverview(
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit e089392

Please sign in to comment.