Skip to content
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ out/

### VS Code ###
.vscode/

# Firebase 서비스 계정 키 파일 무시
src/main/resources/firebase-service-account.json

# Git 폴더들 무시
*.git/
BE.git/
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ configurations {

repositories {
mavenCentral()
google()
}

dependencies {
Expand Down Expand Up @@ -64,8 +65,10 @@ dependencies {

implementation 'org.springframework.boot:spring-boot-starter-webflux'

//SSE
implementation 'org.springframework.boot:spring-boot-starter-web-services'

implementation platform('com.google.firebase:firebase-bom:32.2.0')
implementation 'com.google.firebase:firebase-admin:9.2.0'
}


Expand Down
29 changes: 29 additions & 0 deletions google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "817580878762",
"project_id": "dogcatsquare-6936f",
"storage_bucket": "dogcatsquare-6936f.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:817580878762:android:256ce2a4f241a50c65d9d3",
"android_client_info": {
"package_name": "com.company.DogCatSquare"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyB7pBiTspjSF1F5FBd9cZ3ha-fyVcdpF5c"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
44 changes: 44 additions & 0 deletions src/main/java/DC_square/spring/config/FirebaseInitialization.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package DC_square.spring.config;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

@Service
public class FirebaseInitialization {

@PostConstruct
public void initialize() {
try {
String firebaseConfig = System.getenv("FIREBASE_CONFIG");

if (firebaseConfig == null || firebaseConfig.isEmpty()) {
throw new RuntimeException("환경변수 FIREBASE_CONFIG가 설정되어 있지 않습니다.");
}

GoogleCredentials credentials = GoogleCredentials.fromStream(
new ByteArrayInputStream(firebaseConfig.getBytes(StandardCharsets.UTF_8))
);

FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.build();

if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options);
System.out.println("FirebaseApp 초기화 완료");
} else {
System.out.println("FirebaseApp 이미 초기화되어 있음");
}

} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Firebase 초기화 중 오류 발생: " + e.getMessage());
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/DC_square/spring/domain/entity/Dday.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Dday {

@Builder.Default
@Column(nullable = false)
private Boolean isAlarm = false;
private Boolean isAlarm = true;

public void setDefaultImageUrl() {
switch(this.type) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/DC_square/spring/domain/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ public Long getId() {
@Column(name = "profile_image_url")
private String profileImageUrl;

private String fcmToken;
}
Original file line number Diff line number Diff line change
@@ -1,149 +1,39 @@
package DC_square.spring.domain.entity.notification;

import DC_square.spring.domain.entity.Dday;
import DC_square.spring.domain.entity.User;
import DC_square.spring.domain.enums.NotificationType;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Builder
@Entity
@Getter
@Setter
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "notification")
@Builder
public class Notification {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = true)
private String boardName;

@Column(nullable = true)
private String postTitle;

@Column
private String commenterName;

@Column
private String commentContent;

@Column(nullable = false)
private String ddayName;

@Column(nullable = false)
private Integer daysRemaining;

@Embedded
private NotificationContent content;

@Embedded
private RelatedUrl url;

@Builder.Default
@Column(name = "is_read", nullable = false)
private Boolean read = false;
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private NotificationType notificationType;

@OnDelete(action = OnDeleteAction.CASCADE)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Column(name = "created_at")
private LocalDateTime createdAt;
private String title;

private LocalDateTime updatedAt;
private String content;

@Builder
public Notification(User user, NotificationType notificationType, String content, String url,
String boardName, String postTitle, String commenterName, String commentContent,
String ddayName, Integer daysRemaining) {
this.user = user;
this.notificationType = notificationType;
this.content = new NotificationContent(content);
this.url = new RelatedUrl(url);
this.read = false;
this.boardName = boardName;
this.postTitle = postTitle;
this.commenterName = commenterName;
this.commentContent = commentContent;
this.ddayName = ddayName;
this.daysRemaining = daysRemaining;
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}

// 댓글 관련 알림
public static Notification createCommentNotification(User user, String content, String url,
String boardName, String postTitle,
String commenterName, String commentContent) {
return Notification.builder()
.user(user)
.notificationType(NotificationType.COMMENT)
.content(new NotificationContent(content))
.url(new RelatedUrl(url))
.boardName(boardName)
.postTitle(postTitle)
.commenterName(commenterName)
.commentContent(commentContent)
.build();
}

// 디데이 관련 알림
public static Notification createDdayNotification(User user, String content, String url,
String ddayName, Integer daysRemaining) {
return Notification.builder()
.user(user)
.notificationType(NotificationType.DDAY)
.content(new NotificationContent(content))
.url(new RelatedUrl(url))
.ddayName(ddayName)
.daysRemaining(daysRemaining)
.build();
}

public static int calculateDaysRemaining(Dday dday) {
if (dday == null || dday.getDay() == null) {
return 0;
}
return (int) LocalDate.now().until(dday.getDay()).getDays();
}

public String getContent() {
return content.getContent();
}

public String getUrl() {
return url.getUrl();
}

public void read(){
read = true;
}

public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}
private LocalDateTime createdAt;

@PrePersist
public void prePersist() {
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}

@PreUpdate
public void preUpdate() {
this.updatedAt = LocalDateTime.now();
createdAt = LocalDateTime.now();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public class NotificationContent {
public NotificationContent(String content){
this.content = content;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package DC_square.spring.domain.enums;

public enum NotificationType {
COMMENT,
DDAY
COMMENT, DDAY
}
25 changes: 0 additions & 25 deletions src/main/java/DC_square/spring/mapper/NotificationMapper.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package DC_square.spring.repository.NotificationRepository;
package DC_square.spring.repository;

import DC_square.spring.domain.entity.notification.Notification;
import DC_square.spring.domain.entity.User;
Expand All @@ -11,4 +11,4 @@
import java.util.List;
public interface NotificationRepository extends JpaRepository<Notification, Long> {
List<Notification> findAllByUser(User user);
}
}

This file was deleted.

Loading