diff --git a/src/main/java/com/umc/commonplant/domain/alarm/controller/AlarmController.java b/src/main/java/com/umc/commonplant/domain/alarm/controller/AlarmController.java index 5ac1cea..018484b 100644 --- a/src/main/java/com/umc/commonplant/domain/alarm/controller/AlarmController.java +++ b/src/main/java/com/umc/commonplant/domain/alarm/controller/AlarmController.java @@ -22,13 +22,14 @@ public class AlarmController { @PostMapping("/api/fcm") public ResponseEntity pushMessage(@RequestBody FCMMessageTestDto fcmTestDto) throws IOException { - // log.info(fcmTestDto.getTargetToken() + " " +fcmTestDto.getTitle() + " " + fcmTestDto.getBody()); - log.info(fcmTestDto.getTitle() + " " + fcmTestDto.getBody()); + log.info(fcmTestDto.getTargetToken() + " " +fcmTestDto.getTitle() + " " + fcmTestDto.getBody()); + // log.info(fcmTestDto.getTitle() + " " + fcmTestDto.getBody()); fcmService.sendMessageTo( - //fcmTestDto.getTargetToken(), + fcmTestDto.getTargetToken(), fcmTestDto.getTitle(), - fcmTestDto.getBody()); + fcmTestDto.getBody() + ); return ResponseEntity.ok().build(); } diff --git a/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageDto.java b/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageDto.java index e067540..2715810 100644 --- a/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageDto.java +++ b/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageDto.java @@ -28,6 +28,7 @@ public static class Message { private Notification notification; private String token; private Data data; + private Apns apns; } /** @@ -55,4 +56,28 @@ public static class Data { private String description; } + /** + * iOS 알림 추가 설정: 소리 등등 + */ + @Builder + @AllArgsConstructor + @Getter + public static class Aps { + private String sound; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Payload { + private Aps aps; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Apns { + private Payload payload; + } + } diff --git a/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageTestDto.java b/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageTestDto.java index 5167111..676eaa1 100644 --- a/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageTestDto.java +++ b/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageTestDto.java @@ -11,9 +11,6 @@ public class FCMMessageTestDto { private String title; private String body; - // private String targetToken; + private String targetToken; - public FCMMessageTestDto(){ - - } } diff --git a/src/main/java/com/umc/commonplant/domain/alarm/service/FCMService.java b/src/main/java/com/umc/commonplant/domain/alarm/service/FCMService.java index 47aeeef..5c5901b 100644 --- a/src/main/java/com/umc/commonplant/domain/alarm/service/FCMService.java +++ b/src/main/java/com/umc/commonplant/domain/alarm/service/FCMService.java @@ -55,19 +55,23 @@ private String getAccessToken() throws IOException { * @return * @throws JsonProcessingException */ - // private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { - private String makeMessage(String title, String body) throws JsonProcessingException { + private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { + // private String makeMessage(String title, String body) throws JsonProcessingException { FCMMessageDto fcmMessage = FCMMessageDto.builder() .message(FCMMessageDto.Message.builder() - //.token(targetToken) + .token(targetToken) .notification(FCMMessageDto.Notification.builder() .title(title) .body(body) .image(null) .build() ) - .build() - ) + .apns(FCMMessageDto.Apns.builder() + .payload(FCMMessageDto.Payload.builder() + .aps(FCMMessageDto.Aps.builder().sound("default").build()) + .build()) + .build()) + .build()) .validate_only(false) .build(); @@ -81,10 +85,10 @@ private String makeMessage(String title, String body) throws JsonProcessingExcep * @param body * @throws IOException */ - // public void sendMessageTo(String targetToken, String title, String body) throws IOException { - public void sendMessageTo(String title, String body) throws IOException { - // String message = makeMessage(targetToken, title, body); - String message = makeMessage(title, body); + public void sendMessageTo(String targetToken, String title, String body) throws IOException { + // public void sendMessageTo(String title, String body) throws IOException { + String message = makeMessage(targetToken, title, body); + // String message = makeMessage(title, body); OkHttpClient client = new OkHttpClient(); diff --git a/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java b/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java index aa94a63..ddabf06 100644 --- a/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java +++ b/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java @@ -1,7 +1,10 @@ package com.umc.commonplant.domain.oauth.controller; +import com.umc.commonplant.domain.Jwt.JwtService; import com.umc.commonplant.domain.oauth.service.OAuthService; import com.umc.commonplant.global.dto.JsonResponse; +import com.umc.commonplant.global.exception.BadRequestException; +import com.umc.commonplant.global.exception.ErrorResponseStatus; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; @@ -15,6 +18,7 @@ @RestController public class OAuthController implements OAuthSwagger{ private final OAuthService oAuthService; + private final JwtService jwtService; @GetMapping("/login/{provider}") public ResponseEntity login(@RequestParam("accessToken") String accessToken, @PathVariable String provider){ @@ -27,4 +31,14 @@ public ResponseEntity login(@RequestParam("accessToken") String ac return ResponseEntity.ok(new JsonResponse(true, 2001, "no User Info", email)); } } + + @GetMapping("/api/token") + public ResponseEntity validToken(){ + String token = jwtService.getJwt(); + boolean isValid = jwtService.validateToken(token); + + return isValid ? + ResponseEntity.ok(new JsonResponse(true, 200, "유효한 토큰입니다", isValid)) + : ResponseEntity.ok(new JsonResponse(false, 2004, "토큰을 확인하세요", null)); + } } diff --git a/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthSwagger.java b/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthSwagger.java index f771d4a..f542627 100644 --- a/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthSwagger.java +++ b/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthSwagger.java @@ -14,4 +14,7 @@ public interface OAuthSwagger { @Parameter(name = "accessToken", description = "OAuth 서버가 발급한 액세스토큰", required = true) @Parameter(name = "provider", description = "소셜로그인", example = "kakao", required = true) public ResponseEntity login(@RequestParam("accessToken") String accessToken, @PathVariable String provider); + + @Operation(summary = "토큰 유효성 검증", description = "토큰 유효성 검증") + public ResponseEntity validToken(); } diff --git a/src/main/java/com/umc/commonplant/domain/user/dto/UserDto.java b/src/main/java/com/umc/commonplant/domain/user/dto/UserDto.java index e98fc9a..a1e1eaa 100644 --- a/src/main/java/com/umc/commonplant/domain/user/dto/UserDto.java +++ b/src/main/java/com/umc/commonplant/domain/user/dto/UserDto.java @@ -22,6 +22,8 @@ public static class join{ private String name; @Schema(description = "소셜로그인", example = "kakao") private String provider; + @Schema(description = "회원번호", example = "0123456789") + private String providerId; } @NotBlank(message = "사용할 이름을 입력해주세요.") @Pattern(regexp = "^[가-힣a-zA-Z0-9]{2,10}$" , message = "이름은 특수문자를 포함하지 않은 2~10자리여야 합니다.") diff --git a/src/main/java/com/umc/commonplant/domain/user/entity/User.java b/src/main/java/com/umc/commonplant/domain/user/entity/User.java index ae7e33c..6a6055a 100644 --- a/src/main/java/com/umc/commonplant/domain/user/entity/User.java +++ b/src/main/java/com/umc/commonplant/domain/user/entity/User.java @@ -46,10 +46,11 @@ public class User extends BaseTime { private String uuid; @Builder - public User(String name, String email, String provider, String imgUrl, String uuid){ + public User(String name, String email, String provider, String providerId, String imgUrl, String uuid){ this.name = name; this.email = email; this.provider = provider; + this.providerId = providerId; this.imgUrl = imgUrl; this.uuid = uuid; } diff --git a/src/main/java/com/umc/commonplant/domain/user/repository/UserRepository.java b/src/main/java/com/umc/commonplant/domain/user/repository/UserRepository.java index 75c33e4..83ba77b 100644 --- a/src/main/java/com/umc/commonplant/domain/user/repository/UserRepository.java +++ b/src/main/java/com/umc/commonplant/domain/user/repository/UserRepository.java @@ -10,6 +10,7 @@ public interface UserRepository extends JpaRepository { Optional findByname(String name); Optional findByEmail(String email); Optional findByUuid(String uuid); + Optional findByProviderId(String providerId); @Query("select u from User u where u.email=?1 and u.provider=?2") User findByEmail(String email, String loginType); diff --git a/src/main/java/com/umc/commonplant/domain/user/service/UserService.java b/src/main/java/com/umc/commonplant/domain/user/service/UserService.java index 4b2ac6e..d6d3469 100644 --- a/src/main/java/com/umc/commonplant/domain/user/service/UserService.java +++ b/src/main/java/com/umc/commonplant/domain/user/service/UserService.java @@ -27,6 +27,11 @@ public class UserService { public User getUser(String uuid){ // User 조회 return userRepository.findByUuid(uuid).orElseThrow(() -> new BadRequestException((NOT_FOUND_USER))); } + + public User getUserByProviderId(String providerId){ + return userRepository.findByProviderId(providerId).orElseThrow(() -> new BadRequestException(NOT_FOUND_USER)); + } + public User saveUser(UserDto.join req){ User user = User.builder() .name(req.getName()) @@ -48,8 +53,9 @@ public String joinUser(UserDto.join req, MultipartFile image){ .imgUrl(imageUrl) .uuid(uuid) .email(req.getEmail()) - .provider(req.getProvider()). - build(); + .provider(req.getProvider()) + .providerId(req.getProviderId()) + .build(); userRepository.save(user); return jwtService.createToken(user.getUuid());