-
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 #129 from Link-MIND/test
[Merge] ํ์ํํด, ํธ์์๋ฆผ ๋ถ์ด๊ธฐ
- Loading branch information
Showing
30 changed files
with
820 additions
and
390 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
40 changes: 0 additions & 40 deletions
40
linkmind/src/main/java/com/app/toaster/config/fcm/FCMConfig.java
This file was deleted.
Oops, something went wrong.
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
29 changes: 0 additions & 29 deletions
29
linkmind/src/main/java/com/app/toaster/controller/FCMController.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
linkmind/src/main/java/com/app/toaster/controller/request/fcm/PushMessage.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -74,4 +74,5 @@ public String getFcmToken() { | |
public void updateProfile(String profile){ | ||
this.profile = profile; | ||
} | ||
|
||
} |
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
100 changes: 100 additions & 0 deletions
100
linkmind/src/main/java/com/app/toaster/external/client/fcm/FCMConfig.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,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(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
linkmind/src/main/java/com/app/toaster/external/client/fcm/FCMController.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,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); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...va/com/app/toaster/domain/FCMMessage.java โ ...aster/external/client/fcm/FCMMessage.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
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
Oops, something went wrong.