-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from ecolink-JOIN/feature/push
[Feat] 푸시 알림 동의 변경 API 추가
- Loading branch information
Showing
8 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/join/core/avatar/controller/PushController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.join.core.avatar.controller; | ||
|
||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.join.core.auth.domain.UserPrincipal; | ||
import com.join.core.avatar.controller.specification.PushControllerSpecification; | ||
import com.join.core.avatar.domain.AvatarCommand; | ||
import com.join.core.avatar.service.PushService; | ||
import com.join.core.common.response.ApiResponse; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("${api.prefix}/avatars/push") | ||
public class PushController implements PushControllerSpecification { | ||
|
||
private final PushService pushService; | ||
|
||
|
||
@PreAuthorize("isAuthenticated()") | ||
@PutMapping | ||
public ApiResponse<Void> changePushConsent(@AuthenticationPrincipal UserPrincipal principal, | ||
@RequestBody AvatarCommand.ChangePushConsent command) { | ||
pushService.updatePushConsent(principal.getUserId(), command); | ||
return ApiResponse.ok(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/join/core/avatar/controller/specification/PushControllerSpecification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.join.core.avatar.controller.specification; | ||
|
||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
import com.join.core.auth.domain.UserPrincipal; | ||
import com.join.core.avatar.domain.AvatarCommand; | ||
import com.join.core.common.response.ApiResponse; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
public interface PushControllerSpecification { | ||
|
||
@Tag(name = "${swagger.tag.sign-up}") | ||
@Tag(name = "${swagger.tag.user}") | ||
@Operation(summary = "푸시 알림 동의 API - 인증 필요", | ||
description = "푸시 알림 동의 API - 인증 필요", | ||
security = {@SecurityRequirement(name = "session-token")}) | ||
@PreAuthorize("isAuthenticated()") | ||
@PutMapping | ||
ApiResponse<Void> changePushConsent(@AuthenticationPrincipal UserPrincipal principal, | ||
@RequestBody AvatarCommand.ChangePushConsent command); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.join.core.avatar.service; | ||
|
||
import com.join.core.avatar.domain.AvatarCommand; | ||
|
||
public interface PushService { | ||
|
||
void updatePushConsent(Long userId, AvatarCommand.ChangePushConsent command); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/join/core/avatar/service/PushServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.join.core.avatar.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.join.core.auth.domain.User; | ||
import com.join.core.auth.service.UserReader; | ||
import com.join.core.avatar.domain.AvatarCommand; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Service | ||
public class PushServiceImpl implements PushService { | ||
|
||
private final UserReader userReader; | ||
|
||
@Transactional | ||
@Override | ||
public void updatePushConsent(Long userId, AvatarCommand.ChangePushConsent command) { | ||
User user = userReader.getUser(userId); | ||
user.updatePushConsent(command.isConsent(), command.getFcmToken()); | ||
} | ||
|
||
} |