Skip to content

Commit b72f947

Browse files
authored
Merge pull request #140 from DogCatSquare/feat/gabi/notification
Feat/gabi/notification
2 parents 599950b + 94e7771 commit b72f947

30 files changed

+374
-521
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ out/
3535

3636
### VS Code ###
3737
.vscode/
38+
39+
# Firebase 서비스 계정 키 파일 무시
40+
src/main/resources/firebase-service-account.json
41+
42+
# Git 폴더들 무시
43+
*.git/
44+
BE.git/

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ configurations {
2121

2222
repositories {
2323
mavenCentral()
24+
google()
2425
}
2526

2627
dependencies {
@@ -64,8 +65,10 @@ dependencies {
6465

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

67-
//SSE
6868
implementation 'org.springframework.boot:spring-boot-starter-web-services'
69+
70+
implementation platform('com.google.firebase:firebase-bom:32.2.0')
71+
implementation 'com.google.firebase:firebase-admin:9.2.0'
6972
}
7073

7174

google-services.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"project_info": {
3+
"project_number": "817580878762",
4+
"project_id": "dogcatsquare-6936f",
5+
"storage_bucket": "dogcatsquare-6936f.firebasestorage.app"
6+
},
7+
"client": [
8+
{
9+
"client_info": {
10+
"mobilesdk_app_id": "1:817580878762:android:256ce2a4f241a50c65d9d3",
11+
"android_client_info": {
12+
"package_name": "com.company.DogCatSquare"
13+
}
14+
},
15+
"oauth_client": [],
16+
"api_key": [
17+
{
18+
"current_key": "AIzaSyB7pBiTspjSF1F5FBd9cZ3ha-fyVcdpF5c"
19+
}
20+
],
21+
"services": {
22+
"appinvite_service": {
23+
"other_platform_oauth_client": []
24+
}
25+
}
26+
}
27+
],
28+
"configuration_version": "1"
29+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package DC_square.spring.config;
2+
3+
import com.google.auth.oauth2.GoogleCredentials;
4+
import com.google.firebase.FirebaseApp;
5+
import com.google.firebase.FirebaseOptions;
6+
import org.springframework.stereotype.Service;
7+
8+
import javax.annotation.PostConstruct;
9+
import java.io.ByteArrayInputStream;
10+
import java.nio.charset.StandardCharsets;
11+
12+
@Service
13+
public class FirebaseInitialization {
14+
@PostConstruct
15+
public void initialize() {
16+
try {
17+
String firebaseConfig = System.getenv("FIREBASE_CONFIG");
18+
19+
if (firebaseConfig == null || firebaseConfig.isEmpty()) {
20+
throw new RuntimeException("환경변수 FIREBASE_CONFIG가 설정되어 있지 않습니다.");
21+
}
22+
23+
GoogleCredentials credentials = GoogleCredentials.fromStream(
24+
new ByteArrayInputStream(firebaseConfig.getBytes(StandardCharsets.UTF_8))
25+
);
26+
27+
FirebaseOptions options = new FirebaseOptions.Builder()
28+
.setCredentials(credentials)
29+
.build();
30+
31+
if (FirebaseApp.getApps().isEmpty()) {
32+
FirebaseApp.initializeApp(options);
33+
System.out.println("FirebaseApp 초기화 완료");
34+
} else {
35+
System.out.println("FirebaseApp 이미 초기화되어 있음");
36+
}
37+
38+
} catch (Exception e) {
39+
e.printStackTrace();
40+
throw new RuntimeException("Firebase 초기화 중 오류 발생: " + e.getMessage());
41+
}
42+
}
43+
}

src/main/java/DC_square/spring/domain/entity/Dday.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Dday {
3838

3939
@Builder.Default
4040
@Column(nullable = false)
41-
private Boolean isAlarm = false;
41+
private Boolean isAlarm = true;
4242

4343
public void setDefaultImageUrl() {
4444
switch(this.type) {

src/main/java/DC_square/spring/domain/entity/User.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ public Long getId() {
6464
@Column(name = "profile_image_url")
6565
private String profileImageUrl;
6666

67+
private String fcmToken;
6768
}
Lines changed: 11 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,39 @@
11
package DC_square.spring.domain.entity.notification;
22

3-
import DC_square.spring.domain.entity.Dday;
43
import DC_square.spring.domain.entity.User;
54
import DC_square.spring.domain.enums.NotificationType;
65
import jakarta.persistence.*;
76
import lombok.*;
8-
import org.hibernate.annotations.OnDelete;
9-
import org.hibernate.annotations.OnDeleteAction;
107

11-
import java.time.LocalDate;
128
import java.time.LocalDateTime;
139

14-
@Builder
10+
@Entity
1511
@Getter
1612
@Setter
17-
@Entity
1813
@NoArgsConstructor
1914
@AllArgsConstructor
20-
@Table(name = "notification")
15+
@Builder
2116
public class Notification {
17+
2218
@Id
2319
@GeneratedValue(strategy = GenerationType.IDENTITY)
2420
private Long id;
2521

26-
@Column(nullable = true)
27-
private String boardName;
28-
29-
@Column(nullable = true)
30-
private String postTitle;
31-
32-
@Column
33-
private String commenterName;
34-
35-
@Column
36-
private String commentContent;
37-
38-
@Column(nullable = false)
39-
private String ddayName;
40-
41-
@Column(nullable = false)
42-
private Integer daysRemaining;
43-
44-
@Embedded
45-
private NotificationContent content;
46-
47-
@Embedded
48-
private RelatedUrl url;
49-
50-
@Builder.Default
51-
@Column(name = "is_read", nullable = false)
52-
private Boolean read = false;
22+
@ManyToOne
23+
@JoinColumn(name = "user_id", nullable = false)
24+
private User user;
5325

5426
@Enumerated(EnumType.STRING)
55-
@Column(nullable = false)
5627
private NotificationType notificationType;
5728

58-
@OnDelete(action = OnDeleteAction.CASCADE)
59-
@ManyToOne(fetch = FetchType.LAZY)
60-
@JoinColumn(name = "user_id")
61-
private User user;
62-
63-
@Column(name = "created_at")
64-
private LocalDateTime createdAt;
29+
private String title;
6530

66-
private LocalDateTime updatedAt;
31+
private String content;
6732

68-
@Builder
69-
public Notification(User user, NotificationType notificationType, String content, String url,
70-
String boardName, String postTitle, String commenterName, String commentContent,
71-
String ddayName, Integer daysRemaining) {
72-
this.user = user;
73-
this.notificationType = notificationType;
74-
this.content = new NotificationContent(content);
75-
this.url = new RelatedUrl(url);
76-
this.read = false;
77-
this.boardName = boardName;
78-
this.postTitle = postTitle;
79-
this.commenterName = commenterName;
80-
this.commentContent = commentContent;
81-
this.ddayName = ddayName;
82-
this.daysRemaining = daysRemaining;
83-
this.createdAt = LocalDateTime.now();
84-
this.updatedAt = LocalDateTime.now();
85-
}
86-
87-
// 댓글 관련 알림
88-
public static Notification createCommentNotification(User user, String content, String url,
89-
String boardName, String postTitle,
90-
String commenterName, String commentContent) {
91-
return Notification.builder()
92-
.user(user)
93-
.notificationType(NotificationType.COMMENT)
94-
.content(new NotificationContent(content))
95-
.url(new RelatedUrl(url))
96-
.boardName(boardName)
97-
.postTitle(postTitle)
98-
.commenterName(commenterName)
99-
.commentContent(commentContent)
100-
.build();
101-
}
102-
103-
// 디데이 관련 알림
104-
public static Notification createDdayNotification(User user, String content, String url,
105-
String ddayName, Integer daysRemaining) {
106-
return Notification.builder()
107-
.user(user)
108-
.notificationType(NotificationType.DDAY)
109-
.content(new NotificationContent(content))
110-
.url(new RelatedUrl(url))
111-
.ddayName(ddayName)
112-
.daysRemaining(daysRemaining)
113-
.build();
114-
}
115-
116-
public static int calculateDaysRemaining(Dday dday) {
117-
if (dday == null || dday.getDay() == null) {
118-
return 0;
119-
}
120-
return (int) LocalDate.now().until(dday.getDay()).getDays();
121-
}
122-
123-
public String getContent() {
124-
return content.getContent();
125-
}
126-
127-
public String getUrl() {
128-
return url.getUrl();
129-
}
130-
131-
public void read(){
132-
read = true;
133-
}
134-
135-
public void setCreatedAt(LocalDateTime createdAt) {
136-
this.createdAt = createdAt;
137-
}
33+
private LocalDateTime createdAt;
13834

13935
@PrePersist
14036
public void prePersist() {
141-
this.createdAt = LocalDateTime.now();
142-
this.updatedAt = LocalDateTime.now();
143-
}
144-
145-
@PreUpdate
146-
public void preUpdate() {
147-
this.updatedAt = LocalDateTime.now();
37+
createdAt = LocalDateTime.now();
14838
}
149-
}
39+
}

src/main/java/DC_square/spring/domain/entity/notification/NotificationContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ public class NotificationContent {
1515
public NotificationContent(String content){
1616
this.content = content;
1717
}
18-
}
18+
}

src/main/java/DC_square/spring/domain/entity/place/PlaceImage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class PlaceImage {
1616
@GeneratedValue(strategy = GenerationType.IDENTITY)
1717
private Long id;
1818

19-
@Column(name = "photo_reference", nullable = false)
19+
@Column(name = "photo_reference", nullable = false, length = 2000)
2020
private String photoReference;
2121

2222
@Column(name = "width")
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package DC_square.spring.domain.enums;
22

33
public enum NotificationType {
4-
COMMENT,
5-
DDAY
4+
COMMENT, DDAY
65
}

0 commit comments

Comments
 (0)