Skip to content

Commit

Permalink
Merge pull request #24 from f-lab-edu/feat/23
Browse files Browse the repository at this point in the history
[#23] PUSH 메시지 전송 기능 개발
  • Loading branch information
corea1836 authored Nov 27, 2024
2 parents c47edf9 + b77651a commit 44c45ff
Show file tree
Hide file tree
Showing 34 changed files with 987 additions and 33 deletions.
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ dependencies {
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-aop:3.3.3'

implementation 'org.springframework.retry:spring-retry:2.0.10'


implementation 'com.google.code.gson:gson:2.10.1'

Expand All @@ -50,13 +54,15 @@ dependencies {
//wiremock
testImplementation 'com.squareup.okhttp3:mockwebserver'

//monotoring
//monitoring
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.micrometer:micrometer-registry-prometheus")

// https://mvnrepository.com/artifact/com.slack.api/slack-api-client
//slack
implementation 'com.slack.api:slack-api-client:1.43.1'

//fcm
implementation 'com.google.firebase:firebase-admin:8.1.0'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.flab.just_10_minutes.notification.controller;

import com.flab.just_10_minutes.notification.dto.CampaignRequest;
import com.flab.just_10_minutes.notification.dto.FcmNotificationRequest;
import com.flab.just_10_minutes.notification.dto.FcmTokenRequest;
import com.flab.just_10_minutes.notification.service.NotificationService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/notifications")
public class NotificationController {

private final NotificationService notificationService;

@PostMapping("/fcm-tokens")
public ResponseEntity<HttpStatus> saveToken(@RequestBody FcmTokenRequest fcmTokenRequest) {
notificationService.saveToken(fcmTokenRequest);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@PostMapping("/campaigns")
public ResponseEntity<HttpStatus> saveCampaign(@RequestBody CampaignRequest campaignRequest) {
notificationService.saveCampaign(campaignRequest);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@PostMapping("/fcm-publish")
public void publishMessage(@RequestBody FcmNotificationRequest fcmNotificationRequest) {
notificationService.publishFcmNotificationEvent(fcmNotificationRequest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.flab.just_10_minutes.notification.domain;

import com.flab.just_10_minutes.notification.dto.CampaignRequest;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
public class Campaign {

private Long id;
private String title;
private String body;
private String imgUrl;

public static Campaign from(CampaignRequest campaignRequest) {
return Campaign.builder()
.title(campaignRequest.getTitle())
.body(campaignRequest.getBody())
.imgUrl(campaignRequest.getImgUrl())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.flab.just_10_minutes.notification.domain;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;
import lombok.Builder;
import lombok.With;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
@With
public class FcmNotification {

private String notificationId;
private String receiverId;
private String destination;
private Long campaignId;
private Boolean isSend;

public static FcmNotification from(FcmNotificationEvent event, FcmToken fcmToken) {
return FcmNotification.builder()
.notificationId(event.getEventId())
.receiverId(event.getReceiverId())
.destination(fcmToken.getToken())
.campaignId(event.getCampaignId())
.build();
}

public FcmNotification update(final Boolean isSend) {
return this.withIsSend(isSend);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.flab.just_10_minutes.notification.domain;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;
import lombok.Builder;
import lombok.With;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
@With
public class FcmNotificationEvent {

private String eventId;
private String receiverId;
private Long campaignId;

public static FcmNotificationEvent from(final String eventId, final String receiverId, final Long campaignId) {
return FcmNotificationEvent.builder()
.eventId(eventId)
.receiverId(receiverId)
.campaignId(campaignId)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.flab.just_10_minutes.notification.domain;

import com.flab.just_10_minutes.notification.dto.FcmTokenRequest;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import java.time.LocalDate;

@Getter
@Builder
@AllArgsConstructor
public class FcmToken {

private String loginId;
private String token;
private LocalDate createdAt;
private LocalDate updatedAt;

public static FcmToken from(FcmTokenRequest fcmTokenRequest) {
return FcmToken.builder()
.loginId(fcmTokenRequest.getLoginId())
.token(fcmTokenRequest.getToken())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.flab.just_10_minutes.notification.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CampaignRequest {

private String title;
private String body;
private String imgUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.flab.just_10_minutes.notification.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FcmNotificationRequest {

private String loginId;
private Long campaignId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.flab.just_10_minutes.notification.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FcmTokenRequest {

private String loginId;
private String token;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.flab.just_10_minutes.notification.infrastructure.entity;

import com.flab.just_10_minutes.notification.domain.Campaign;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class CampaignEntity {

private Long id;
private String title;
private String body;
private String imgUrl;

public static CampaignEntity from(Campaign fcmCampaign) {
return CampaignEntity.builder()
.title(fcmCampaign.getTitle())
.body(fcmCampaign.getBody())
.imgUrl(fcmCampaign.getImgUrl())
.build();
}

public static Campaign toDomain(CampaignEntity fcmCampaignEntity) {
return Campaign.builder()
.id(fcmCampaignEntity.getId())
.title(fcmCampaignEntity.getTitle())
.body(fcmCampaignEntity.getBody())
.imgUrl(fcmCampaignEntity.getImgUrl())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.flab.just_10_minutes.notification.infrastructure.entity;

import com.flab.just_10_minutes.notification.domain.FcmNotification;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.With;
import lombok.Builder;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
@With
public class FcmNotificationEntity {

private Long id;
private String NotificationId;
private Long campaignId;
private String destination;
private Boolean isSend;

public static FcmNotificationEntity from(FcmNotification fcmNotification) {
return FcmNotificationEntity.builder()
.NotificationId(fcmNotification.getNotificationId())
.campaignId(fcmNotification.getCampaignId())
.destination(fcmNotification.getDestination())
.isSend(fcmNotification.getIsSend())
.build();
}

public static FcmNotification toDomain(FcmNotificationEntity notificationEntity) {
return FcmNotification.builder()
.notificationId(notificationEntity.getNotificationId())
.campaignId(notificationEntity.getCampaignId())
.destination(notificationEntity.getDestination())
.isSend(notificationEntity.getIsSend())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.flab.just_10_minutes.notification.infrastructure.entity;

import com.flab.just_10_minutes.notification.domain.FcmToken;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class FcmTokenEntity {

private Long id;
private String loginId;
private String token;

public static FcmTokenEntity from(FcmToken fcmToken) {
return FcmTokenEntity.builder()
.loginId(fcmToken.getLoginId())
.token(fcmToken.getToken())
.build();
}

public static FcmToken toDomain(FcmTokenEntity fcmTokenEntity) {
return FcmToken.builder()
.loginId(fcmTokenEntity.getLoginId())
.token(fcmTokenEntity.getToken())
.build();
}
}
Loading

0 comments on commit 44c45ff

Please sign in to comment.