Skip to content

Commit b5d0227

Browse files
authored
Merge pull request #174 from GoToBILL/fix
feat: ActivityAlert 도메인 모델과 AlertType enum을 추가했습니다
2 parents 16ab012 + 82c86c2 commit b5d0227

29 files changed

+1410
-163
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ dependencies {
4747
testImplementation 'org.springframework.security:spring-security-test'
4848
testImplementation 'io.projectreactor:reactor-test'
4949
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
50+
51+
// JOL (Java Object Layout) - 메모리 크기 측정용
52+
testImplementation 'org.openjdk.jol:jol-core:0.17'
5053
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.4.0'
5154
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
5255
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3'

src/main/java/com/example/cherrydan/activity/controller/ActivityController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public ApiResponse<PageListResponseDTO<ActivityAlertResponseDTO>> getBookmarkAct
5757
return ApiResponse.success("북마크 활동 알림 목록 조회 성공", response);
5858
}
5959

60+
@Operation(
61+
summary = "북마크 기반 활동 알림 개수 조회",
62+
description = "사용자의 북마크 기반 활동 알림 개수를 조회합니다."
63+
)
64+
@GetMapping("/bookmark-alerts/count")
65+
public ApiResponse<Long> getBookmarkActivityAlertsCount(
66+
@Parameter(hidden = true) @AuthenticationPrincipal UserDetailsImpl currentUser
67+
) {
68+
Long alertsCount = activityAlertService.getUserActivityAlertsCount(currentUser.getId());
69+
return ApiResponse.success("북마크 활동 알림 개수 조회 성공", alertsCount);
70+
}
71+
6072
@Operation(
6173
summary = "북마크 기반 활동 알림 삭제",
6274
description = "선택한 북마크 기반 활동 알림들을 삭제합니다. 본인의 알림이 아닌 경우 403 에러를 반환합니다."

src/main/java/com/example/cherrydan/activity/domain/ActivityAlert.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
indexes = {
1414
@Index(name = "idx_user_visible_alert_date", columnList = "user_id, is_visible_to_user, alert_date"),
1515
@Index(name = "idx_alert_stage_visible", columnList = "alert_stage, is_visible_to_user")
16+
},
17+
uniqueConstraints = {
18+
@UniqueConstraint(name = "uk_activity_alert", columnNames = {"user_id", "campaign_id", "alert_type", "alert_date"})
1619
})
1720
@Getter
1821
@NoArgsConstructor
@@ -34,6 +37,10 @@ public class ActivityAlert extends BaseTimeEntity {
3437

3538
@Column(name = "alert_date", nullable = false)
3639
private LocalDate alertDate;
40+
41+
@Enumerated(EnumType.STRING)
42+
@Column(name = "alert_type", nullable = false, length = 50)
43+
private ActivityAlertType alertType;
3744

3845
@Column(name = "alert_stage", nullable = false)
3946
@Builder.Default
@@ -51,11 +58,15 @@ public void markAsNotified() {
5158
this.alertStage = 1;
5259
}
5360

54-
public boolean isNotified() {
55-
return alertStage > 0;
56-
}
57-
5861
public void markAsRead() {
5962
this.isRead = true;
6063
}
64+
65+
public String getNotificationTitle() {
66+
return alertType.getTitle();
67+
}
68+
69+
public String getNotificationBody() {
70+
return alertType.getBodyTemplate(campaign.getTitle());
71+
}
6172
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.example.cherrydan.activity.domain;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum ActivityAlertType {
7+
// 북마크 기반 알림
8+
BOOKMARK_DEADLINE_D1("마감알림", "D-1", "모집이 내일 완료됩니다. 얼른 신청해보세요."),
9+
BOOKMARK_DEADLINE_DDAY("마감알림", "D-Day", "모집이 오늘 종료됩니다."),
10+
11+
// CampaignStatus 기반 알림
12+
APPLY_RESULT_DDAY("공고 결과 알림", "D-Day", "선정 결과를 확인해보세요!"),
13+
14+
// 선정자 방문 알림 (REGION 타입만)
15+
SELECTED_VISIT_D3("방문알림", "D-3", "방문 마감일이 3일 남았습니다."),
16+
SELECTED_VISIT_DDAY("방문알림", "D-Day", "오늘이 마지막 방문 기회예요!"),
17+
18+
// 리뷰 작성 알림
19+
REVIEWING_DEADLINE_D3("리뷰 작성 알림", "D-3", "리뷰 작성이 3일 남았습니다."),
20+
REVIEWING_DEADLINE_DDAY("리뷰 작성 알림", "D-Day", "리뷰 작성이 오늘 마감됩니다. 놓치지 말고 작성해주세요.");
21+
22+
private final String category;
23+
private final String dDayLabel;
24+
private final String messageTemplate;
25+
26+
ActivityAlertType(String category, String dDayLabel, String messageTemplate) {
27+
this.category = category;
28+
this.dDayLabel = dDayLabel;
29+
this.messageTemplate = messageTemplate;
30+
}
31+
32+
public String getTitle() {
33+
return category;
34+
}
35+
36+
public String getBodyTemplate(String campaignTitle) {
37+
return String.format("%s %s %s", dDayLabel, campaignTitle, messageTemplate);
38+
}
39+
}

src/main/java/com/example/cherrydan/activity/repository/ActivityAlertRepository.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.cherrydan.activity.repository;
22

33
import com.example.cherrydan.activity.domain.ActivityAlert;
4+
import com.example.cherrydan.activity.domain.ActivityAlertType;
45
import org.springframework.data.domain.Page;
56
import org.springframework.data.domain.Pageable;
67
import org.springframework.data.jpa.repository.JpaRepository;
@@ -10,6 +11,7 @@
1011

1112
import java.time.LocalDate;
1213
import java.util.List;
14+
import java.util.Set;
1315

1416
@Repository
1517
public interface ActivityAlertRepository extends JpaRepository<ActivityAlert, Long> {
@@ -20,6 +22,12 @@ public interface ActivityAlertRepository extends JpaRepository<ActivityAlert, Lo
2022
@Query("SELECT aa FROM ActivityAlert aa WHERE aa.user.id = :userId AND aa.isVisibleToUser = true ORDER BY aa.alertDate DESC")
2123
Page<ActivityAlert> findByUserIdAndIsVisibleToUserTrue(@Param("userId") Long userId, Pageable pageable);
2224

25+
/**
26+
* 사용자의 활동 알림 개수 조회
27+
*/
28+
@Query("SELECT COUNT(aa) FROM ActivityAlert aa WHERE aa.user.id = :userId AND aa.isVisibleToUser = true")
29+
Long countByUserIdAndIsVisibleToUserTrue(@Param("userId") Long userId);
30+
2331

2432
/**
2533
* 당일 생성된 알림 미발송 활동 알림들 조회 (Campaign과 User를 Fetch Join으로 함께 조회)
@@ -30,6 +38,15 @@ public interface ActivityAlertRepository extends JpaRepository<ActivityAlert, Lo
3038
"WHERE aa.alertStage = 0 AND aa.isVisibleToUser = true AND aa.alertDate = :alertDate")
3139
List<ActivityAlert> findTodayUnnotifiedAlerts(@Param("alertDate") LocalDate alertDate);
3240

41+
/**
42+
* 당일 생성된 알림 미발송 활동 알림들 페이징 조회 (Campaign과 User를 Fetch Join으로 함께 조회)
43+
*/
44+
@Query("SELECT aa FROM ActivityAlert aa " +
45+
"JOIN FETCH aa.campaign c " +
46+
"JOIN FETCH aa.user u " +
47+
"WHERE aa.alertStage = 0 AND aa.isVisibleToUser = true AND aa.alertDate = :alertDate")
48+
Page<ActivityAlert> findTodayUnnotifiedAlertsWithPaging(@Param("alertDate") LocalDate alertDate, Pageable pageable);
49+
3350
/**
3451
* 사용자와 캠페인으로 알림 존재 여부 확인
3552
*/

0 commit comments

Comments
 (0)