Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mission #20

Merged
merged 4 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ out/
### application.yml ###
application-dev.yml
application-prod.yml
application-local.yml
application-oauth.properties

### firebase sdk json ###
togetup-26b96-firebase-adminsdk-3l3ah-3164ed8f18.json
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ dependencies {
implementation 'javax.xml.bind:jaxb-api'
implementation 'com.google.code.gson:gson:2.8.0'


// OpenCV
implementation 'org.openpnp:opencv:4.6.0-0'
implementation group: 'com.microsoft.onnxruntime', name: 'onnxruntime', version: '1.12.1'
implementation 'com.google.firebase:firebase-admin:8.0.0'
}

ext {
Expand Down
Binary file added logs/app.2023-06-13.0.gz
Binary file not shown.
Binary file added logs/app.2023-06-17.0.gz
Binary file not shown.
2,839 changes: 2,839 additions & 0 deletions logs/app.log

Large diffs are not rendered by default.

Binary file added logs/error-2023-06-13.0.gz
Binary file not shown.
2,720 changes: 2,720 additions & 0 deletions logs/error.log

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.wakeUpTogetUp.togetUp.alarms;
package com.wakeUpTogetUp.togetUp.alarm;

import com.wakeUpTogetUp.togetUp.alarms.dto.request.DeleteAlarmReq;
import com.wakeUpTogetUp.togetUp.alarms.dto.request.PatchAlarmReq;
import com.wakeUpTogetUp.togetUp.alarms.dto.response.AlarmRes;
import com.wakeUpTogetUp.togetUp.alarms.dto.response.AlarmsRes;
import com.wakeUpTogetUp.togetUp.alarms.dto.request.PostAlarmReq;
import com.wakeUpTogetUp.togetUp.alarm.dto.request.DeleteAlarmReq;
import com.wakeUpTogetUp.togetUp.alarm.dto.request.PatchAlarmReq;
import com.wakeUpTogetUp.togetUp.alarm.dto.response.AlarmRes;
import com.wakeUpTogetUp.togetUp.alarm.dto.response.AlarmsRes;
import com.wakeUpTogetUp.togetUp.alarm.dto.request.PostAlarmReq;
import com.wakeUpTogetUp.togetUp.common.dto.BaseResponse;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wakeUpTogetUp.togetUp.alarms;
package com.wakeUpTogetUp.togetUp.alarm;

import com.wakeUpTogetUp.togetUp.alarms.model.Alarm;
import com.wakeUpTogetUp.togetUp.alarms.dto.response.AlarmRes;
import com.wakeUpTogetUp.togetUp.alarms.dto.response.AlarmsRes;
import com.wakeUpTogetUp.togetUp.alarm.model.Alarm;
import com.wakeUpTogetUp.togetUp.alarm.dto.response.AlarmRes;
import com.wakeUpTogetUp.togetUp.alarm.dto.response.AlarmsRes;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.routine.RoutineProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wakeUpTogetUp.togetUp.alarms;
package com.wakeUpTogetUp.togetUp.alarm;

import com.wakeUpTogetUp.togetUp.alarms.model.Alarm;
import com.wakeUpTogetUp.togetUp.alarm.model.Alarm;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.wakeUpTogetUp.togetUp.alarms;
package com.wakeUpTogetUp.togetUp.alarm;

import com.wakeUpTogetUp.togetUp.alarms.dto.request.PatchAlarmReq;
import com.wakeUpTogetUp.togetUp.alarms.dto.response.AlarmRes;
import com.wakeUpTogetUp.togetUp.alarms.model.Alarm;
import com.wakeUpTogetUp.togetUp.alarms.dto.request.PostAlarmReq;
import com.wakeUpTogetUp.togetUp.alarm.dto.request.PatchAlarmReq;
import com.wakeUpTogetUp.togetUp.alarm.dto.response.AlarmRes;
import com.wakeUpTogetUp.togetUp.alarm.model.Alarm;
import com.wakeUpTogetUp.togetUp.alarm.dto.request.PostAlarmReq;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.mission.MissionRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wakeUpTogetUp.togetUp.alarms.dto.request;
package com.wakeUpTogetUp.togetUp.alarm.dto.request;

import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wakeUpTogetUp.togetUp.alarms.dto.request;
package com.wakeUpTogetUp.togetUp.alarm.dto.request;

import com.wakeUpTogetUp.togetUp.routine.dto.request.PostRoutineReq;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wakeUpTogetUp.togetUp.alarms.dto.request;
package com.wakeUpTogetUp.togetUp.alarm.dto.request;

import com.wakeUpTogetUp.togetUp.routine.dto.request.PostRoutineReq;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wakeUpTogetUp.togetUp.alarms.dto.response;
package com.wakeUpTogetUp.togetUp.alarm.dto.response;

import com.wakeUpTogetUp.togetUp.routine.dto.response.RoutineRes;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wakeUpTogetUp.togetUp.alarms.dto.response;
package com.wakeUpTogetUp.togetUp.alarm.dto.response;

import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wakeUpTogetUp.togetUp.alarms.model;
package com.wakeUpTogetUp.togetUp.alarm.model;

import com.wakeUpTogetUp.togetUp.mission.model.Mission;
import com.wakeUpTogetUp.togetUp.users.model.User;
Expand All @@ -19,6 +19,7 @@ public class Alarm {
@PrePersist
public void prePersist() {
this.isActivated = this.isActivated == null ? Boolean.TRUE : this.isActivated;
this.icon = this.icon == null ? "⏰" : this.icon;
}
@Builder
public Alarm(User user, Mission mission, String name, String icon, String sound, Boolean isVibrate, Boolean isRoutineOn, Integer snoozeInterval, Integer snoozeCnt, Time alarmTime, Boolean monday, Boolean tuesday, Boolean wednesday, Boolean thursday, Boolean friday, Boolean saturday, Boolean sunday) {
Expand Down Expand Up @@ -71,17 +72,27 @@ public void modifyProperties(Mission mission, String name, String icon, String s
private String name;
private String icon;
private String sound;
@Column(columnDefinition = "tinyint")
private Boolean isVibrate;
@Column(columnDefinition = "tinyint")
private Boolean isRoutineOn;
private Integer snoozeInterval;
private Integer snoozeCnt;
private Time alarmTime;
@Column(columnDefinition = "tinyint")
private Boolean monday;
@Column(columnDefinition = "tinyint")
private Boolean tuesday;
@Column(columnDefinition = "tinyint")
private Boolean wednesday;
@Column(columnDefinition = "tinyint")
private Boolean thursday;
@Column(columnDefinition = "tinyint")
private Boolean friday;
@Column(columnDefinition = "tinyint")
private Boolean saturday;
@Column(columnDefinition = "tinyint")
private Boolean sunday;
@Column(columnDefinition = "tinyint")
private Boolean isActivated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.wakeUpTogetUp.togetUp.chat.ChatRoomRepository;
import com.wakeUpTogetUp.togetUp.chat.ChatService;
import com.wakeUpTogetUp.togetUp.chat.JwtTokenProvider;
import com.wakeUpTogetUp.togetUp.fcmNotification.FcmService;
import com.wakeUpTogetUp.togetUp.fcmNotification.NotificationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.Header;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/wakeUpTogetUp/togetUp/common/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum Status {
* 500번대(서버 에러)
*/
// 공통
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "예상치 못한 서버 에러입니다. 제보 부탁드립니다.")
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "예상치 못한 서버 에러입니다. 제보 부탁드립니다."),

;

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/wakeUpTogetUp/togetUp/config/FirebaseConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.wakeUpTogetUp.togetUp.config;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.FirebaseMessaging;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
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.InputStream;

@Configuration
public class FirebaseConfig {
@Value("${my.file.firebase-configuration-file}")
private String resourceName;

@Bean
FirebaseMessaging firebaseMessaging(FirebaseApp firebaseApp) {
return FirebaseMessaging.getInstance(firebaseApp);
}
@Bean
FirebaseApp firebaseApp(GoogleCredentials credentials) {
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(credentials)
.build();

return FirebaseApp.initializeApp(options);
}
@Bean
GoogleCredentials googleCredentials() {
try (InputStream serviceAccount = new ClassPathResource(resourceName).getInputStream()) {
return GoogleCredentials.fromStream(serviceAccount);
} catch (Exception e) {
e.printStackTrace();
throw new BaseException(Status.INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class GlobalExceptionHandler {
// Catch Custom Exception(BaseException)
@ExceptionHandler({ BaseException.class })
protected BaseResponse handleCustomException(BaseException exception) {
logger.debug("BaseResponse exception occurred: {}",
exception.getMessage(),
exception);

return new BaseResponse<>(exception.getStatus());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.wakeUpTogetUp.togetUp.fcmNotification;

import com.google.firebase.messaging.*;
import com.wakeUpTogetUp.togetUp.fcmNotification.dto.request.PushNotificationReq;
import com.wakeUpTogetUp.togetUp.fcmNotification.dto.response.PushNotificationRes;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.ExecutionException;

@Service
@RequiredArgsConstructor
public class FcmService {
private final FirebaseMessaging firebaseMessaging;

@Transactional
public PushNotificationRes sendMessageToToken(PushNotificationReq request)
throws InterruptedException, ExecutionException {
// message 만들기
Message message = getPreconfiguredMessageToToken(request);
String response = sendAndGetResponse(message);

return PushNotificationRes.builder()
.message("Sent message to token.")
.category(request.getCategory())
.response(response)
.build();
}
@Transactional
public PushNotificationRes sendMessageToTokens(PushNotificationReq request)
throws ExecutionException, InterruptedException {
// message 만들기
MulticastMessage message = getPreconfiguredMessageToTokens(request);
Integer failureCnt = sendAndGetResponse(message);

return PushNotificationRes.builder()
.message("Sent message to tokens")
.category(request.getCategory())
.response(failureCnt.toString())
.build();
}

@Transactional
public PushNotificationRes sendMessageToTopic (PushNotificationReq request)
throws ExecutionException, InterruptedException {
// message 만들기
Message message = getPreconfiguredMessageToTopic(request);
String response = sendAndGetResponse(message);

return PushNotificationRes.builder()
.message("Sent message to tokens.")
.category(request.getCategory())
.topic(request.getTopic())
.response(response)
.build();
}

private String sendAndGetResponse(Message message) throws InterruptedException, ExecutionException {
return FirebaseMessaging.getInstance().sendAsync(message).get();
}

private int sendAndGetResponse(MulticastMessage message) throws ExecutionException, InterruptedException {
return FirebaseMessaging.getInstance().sendMulticastAsync(message).get().getFailureCount();
}

// topic
private Message getPreconfiguredMessageToTopic(PushNotificationReq request) {
return getPreconfiguredMessageBuilder(request).setTopic(request.getTopic())
.build();
}

// token
private Message getPreconfiguredMessageToToken(PushNotificationReq request) {
return getPreconfiguredMessageBuilder(request).setToken(request.getTokenList().get(0))
.build();
}

// token 여러 개
private MulticastMessage getPreconfiguredMessageToTokens(PushNotificationReq request) {
return getPreconfiguredMulticastMessageBuilder(request).addAllTokens(request.getTokenList())
.build();
}

private Message.Builder getPreconfiguredMessageBuilder(PushNotificationReq request) {
ApnsConfig apnsConfig = getApnsConfig(request.getCategory());
return Message.builder()
.setApnsConfig(apnsConfig)
.setNotification(Notification.builder()
.setTitle(request.getTitle())
.setBody(request.getMessage())
.build());
}

private MulticastMessage.Builder getPreconfiguredMulticastMessageBuilder(PushNotificationReq request) {
ApnsConfig apnsConfig = getApnsConfig(request.getCategory());
return MulticastMessage.builder()
.setApnsConfig(apnsConfig)
.setNotification(Notification.builder()
.setTitle(request.getTitle())
.setBody(request.getMessage())
.build());
}

private ApnsConfig getApnsConfig(String category) {
return ApnsConfig.builder()
.setAps(Aps.builder()
.setCategory(category)
.setBadge(1)
.setSound("default")
.build())
.build();
}

// 구독 요청
public void subscribe(List<String> memberTokenList, String topicName) {
firebaseMessaging.subscribeToTopicAsync(
memberTokenList,
topicName
);
}

// 구독 취소
public void unSubscribe(List<String> memberTokenList, String topicName) {
firebaseMessaging.unsubscribeFromTopicAsync(
memberTokenList,
topicName
);
}

// TODO : 토픽 삭제
public void deleteTopic(String topicName){

}
}
Loading