Skip to content

Commit

Permalink
Merge pull request #129 from Link-MIND/test
Browse files Browse the repository at this point in the history
[Merge] ํšŒ์›ํƒˆํ‡ด, ํ‘ธ์‹œ์•Œ๋ฆผ ๋ถ™์ด๊ธฐ
  • Loading branch information
sss4920 authored Jan 17, 2024
2 parents 956e8fc + ea11a9b commit e20f294
Show file tree
Hide file tree
Showing 30 changed files with 820 additions and 390 deletions.
4 changes: 4 additions & 0 deletions linkmind/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ dependencies {

implementation 'io.sentry:sentry-spring-boot-starter:5.7.0'

//sqs
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.1")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sqs'
}


tasks.named('test') {
useJUnitPlatform()
}
40 changes: 0 additions & 40 deletions linkmind/src/main/java/com/app/toaster/config/fcm/FCMConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public ApiResponse signOut(@UserId Long userId) {

@DeleteMapping("/withdraw")
@ResponseStatus(HttpStatus.OK)
public ApiResponse withdraw(@UserId Long userId) {
authService.withdraw(userId);
public ApiResponse withdraw(@UserId Long userId, @RequestHeader("Authorization") String socialAccessToken) {
authService.withdraw(userId,socialAccessToken);
return ApiResponse.success(Success.DELETE_USER_SUCCESS);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public record GetTimerResponseDto (String categoryName,
String remindTime,
ArrayList<Integer> remindDates) {
public static GetTimerResponseDto of(Reminder reminder){
if(reminder.getCategory() == null)
return new GetTimerResponseDto("์ „์ฒด", reminder.getRemindTime().toString(), reminder.getRemindDates());
return new GetTimerResponseDto(reminder.getCategory().getTitle(), reminder.getRemindTime().toString(), reminder.getRemindDates());
}
}
1 change: 1 addition & 0 deletions linkmind/src/main/java/com/app/toaster/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ public String getFcmToken() {
public void updateProfile(String profile){
this.profile = profile;
}

}
3 changes: 2 additions & 1 deletion linkmind/src/main/java/com/app/toaster/exception/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public enum Error {
UNPROCESSABLE_CREATE_TIMER_EXCEPTION(HttpStatus.UNPROCESSABLE_ENTITY, "์ด๋ฏธ ํƒ€์ด๋จธ๊ฐ€ ์กด์žฌํ•˜๋Š” ํด๋ฆฝ์ž…๋‹ˆ๋‹ค."),
UNPROCESSABLE_ENTITY_CREATE_CLIP_EXCEPTION(HttpStatus.UNPROCESSABLE_ENTITY, "ํด๋ฆฝ์€ ์ตœ๋Œ€ 50๊ฐœ๊นŒ์ง€๋งŒ ๋“ฑ๋ก๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค."),
UNPROCESSABLE_PRESIGNEDURL_EXCEPTION(HttpStatus.UNPROCESSABLE_ENTITY, "presignedUrl ๋ฐœ๊ธ‰ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."),
UNPROCESSABLE_KAKAO_SERVER_EXCEPTION(HttpStatus.UNPROCESSABLE_ENTITY, "์นด์นด์˜ค์„œ๋ฒ„์™€ ํ†ต์‹  ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."),


/**
Expand All @@ -65,7 +66,7 @@ public enum Error {
INVALID_ENCRYPT_COMMUNICATION(HttpStatus.INTERNAL_SERVER_ERROR, "ios ํ†ต์‹  ์ฆ๋ช… ๊ณผ์ • ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."),
CREATE_PUBLIC_KEY_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "publickey ์ƒ์„ฑ ๊ณผ์ • ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."),
FAIL_TO_SEND_PUSH_ALARM(HttpStatus.INTERNAL_SERVER_ERROR, "๋‹ค์ˆ˜๊ธฐ๊ธฐ ํ‘ธ์‹œ๋ฉ”์‹œ์ง€ ์ „์†ก ์‹คํŒจ"),

FAIL_TO_SEND_SQS(HttpStatus.INTERNAL_SERVER_ERROR, "sqs ์ „์†ก ์‹คํŒจ"),

CREATE_TOAST_PROCCESS_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "ํ† ์ŠคํŠธ ์ €์žฅ ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ์นดํ…Œ๊ณ ๋ฆฌ ๋˜๋Š” s3 ๊ด€๋ จ ๋ฌธ์ œ๋กœ ์˜ˆ์ƒ๋ฉ๋‹ˆ๋‹ค.")
;
Expand Down
2 changes: 2 additions & 0 deletions linkmind/src/main/java/com/app/toaster/exception/Success.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public enum Success {
UPDATE_TIMER_DATETIME_SUCCESS(HttpStatus.OK, "ํƒ€์ด๋จธ ์‹œ๊ฐ„/๋‚ ์งœ ์ˆ˜์ • ์™„๋ฃŒ"),
UPDATE_TIMER_COMMENT_SUCCESS(HttpStatus.OK, "ํƒ€์ด๋จธ ์ฝ”๋ฉ˜ํŠธ ์ˆ˜์ • ์™„๋ฃŒ"),
CHANGE_TIMER_ALARM_SUCCESS(HttpStatus.OK, "ํƒ€์ด๋จธ ์•Œ๋žŒ์—ฌ๋ถ€ ์ˆ˜์ • ์™„๋ฃŒ"),
PUSH_ALARM_PERIODIC_SUCCESS(HttpStatus.OK, "ํ‘ธ์‹œ์•Œ๋ฆผ ํ™œ์„ฑ์— ์„ฑ๊ณตํ–ˆ์Šต๋‹ˆ๋‹ค."),
PUSH_ALARM_SUCCESS(HttpStatus.OK, "ํ‘ธ์‹œ์•Œ๋ฆผ ์ „์†ก์— ์„ฑ๊ณตํ–ˆ์Šต๋‹ˆ๋‹ค."),


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.app.toaster.external.client.fcm;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.*;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Slf4j
@Configuration
public class FCMConfig {

@Value("${fcm.key.path}")
private String SERVICE_ACCOUNT_JSON;

@PostConstruct
public void init() {
try {
ClassPathResource resource = new ClassPathResource(SERVICE_ACCOUNT_JSON);
InputStream serviceAccount = resource.getInputStream();

FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.build();

FirebaseApp.initializeApp(options);
log.info("ํŒŒ์ด์–ด๋ฒ ์ด์Šค ์„œ๋ฒ„์™€์˜ ์—ฐ๊ฒฐ์— ์„ฑ๊ณตํ–ˆ์Šต๋‹ˆ๋‹ค.");
} catch (IOException e) {
log.error("ํŒŒ์ด์–ด๋ฒ ์ด์Šค ์„œ๋ฒ„์™€์˜ ์—ฐ๊ฒฐ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.");
}
}

// ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํŒŒ์ด์–ด๋ฒ ์ด์Šค ์•ฑ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ
@Bean
FirebaseMessaging firebaseMessaging() throws IOException {

ClassPathResource resource = new ClassPathResource(SERVICE_ACCOUNT_JSON);
InputStream refreshToken = resource.getInputStream();

FirebaseApp firebaseApp = null;
List<FirebaseApp> firebaseAppList = FirebaseApp.getApps();

if (!firebaseAppList.isEmpty() && firebaseAppList != null) {
for (FirebaseApp app : firebaseAppList) {
if (app.getName().equals(FirebaseApp.DEFAULT_APP_NAME)) {
firebaseApp = app;
}
}
} else {
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(refreshToken))
.build();

firebaseApp = FirebaseApp.initializeApp(options);
}

return FirebaseMessaging.getInstance(firebaseApp);


}

// TODO ํ”Œ๋žซํผ๋งˆ๋‹ค ๋ณ„๋„์˜ ์„ค์ •์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉ

// Android
public AndroidConfig TokenAndroidConfig(FCMPushRequestDto request) {
return AndroidConfig.builder()
// .setCollapseKey(request.getCollapseKey())
.setNotification(AndroidNotification.builder()
.setTitle(request.getTitle())
.setBody(request.getBody())
.build())
.build();
}

// Apple
public ApnsConfig TokenApnsConfig(FCMPushRequestDto request) {
return ApnsConfig.builder()
.setAps(Aps.builder()
.setAlert(
ApsAlert.builder()
.setTitle(request.getTitle())
.setBody(request.getBody())
// .setLaunchImage(request.getImgUrl())
.build()
)
// .setCategory(request.getCollapseKey())
.setSound("default")
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.app.toaster.external.client.fcm;

import com.app.toaster.common.dto.ApiResponse;
import com.app.toaster.external.client.sqs.SqsProducer;
import com.app.toaster.external.client.fcm.FCMPushRequestDto;
import com.app.toaster.exception.Success;
import com.app.toaster.external.client.fcm.FCMService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/alarm")
@RequiredArgsConstructor
public class FCMController {

private final FCMService fcmService;
// private final FCMScheduler fcmScheduler;
private final SqsProducer sqsProducer;

/**
* ํ—ค๋”์™€ ๋ฐ”๋””๋ฅผ ์ง์ ‘ ๋งŒ๋“ค์–ด ์•Œ๋ฆผ์„ ์ „์†กํ•˜๋Š” ํ…Œ์ŠคํŠธ์šฉ API
*/
@PostMapping
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<String> sendNotificationByToken(
@RequestBody FCMPushRequestDto request) throws IOException {

fcmService.pushAlarm(request);
return ResponseEntity.ok().body("ํ‘ธ์‹œ์•Œ๋ฆผ ์ „์†ก์— ์„ฑ๊ณตํ–ˆ์Šต๋‹ˆ๋‹ค!");
}

/**
* ์ƒˆ๋กœ์šด ์งˆ๋ฌธ์ด ๋„์ฐฉํ–ˆ์Œ์„ ์•Œ๋ฆฌ๋Š” ํ‘ธ์‹œ ์•Œ๋ฆผ ํ™œ์„ฑํ™” API
*/
@PostMapping("/qna")
@ResponseStatus(HttpStatus.OK)
public ApiResponse sendTopicScheduledTest(@RequestBody FCMPushRequestDto request) {
sqsProducer.sendMessage(request);
return ApiResponse.success(Success.PUSH_ALARM_PERIODIC_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.app.toaster.domain;
package com.app.toaster.external.client.fcm;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.app.toaster.controller.request.fcm;
package com.app.toaster.external.client.fcm;

import com.app.toaster.domain.Reminder;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

import java.awt.*;
import java.time.LocalDateTime;
import java.time.format.TextStyle;
import java.util.Locale;
import java.util.Random;

@Slf4j
@Getter
Expand All @@ -13,6 +17,7 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class FCMPushRequestDto {


private String targetToken;

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand All @@ -23,12 +28,14 @@ public class FCMPushRequestDto {

private String image;

public static FCMPushRequestDto sendTestPush(String targetToken) {
public static FCMPushRequestDto sendTestPush(String targetToken, String comment) {

return FCMPushRequestDto.builder()
.targetToken(targetToken)
.title("๐Ÿž" + PushMessage.TODAY_QNA.getTitle())
.body(PushMessage.TODAY_QNA.getBody())
.title("๐Ÿž ํ† ์ŠคํŠธ ")
.body(comment)
.build();

}

}
Loading

0 comments on commit e20f294

Please sign in to comment.