-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from f-lab-edu/feat/23
[#23] PUSH 메시지 전송 기능 개발
- Loading branch information
Showing
34 changed files
with
987 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/flab/just_10_minutes/notification/controller/NotificationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/flab/just_10_minutes/notification/domain/Campaign.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/flab/just_10_minutes/notification/domain/FcmNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/flab/just_10_minutes/notification/domain/FcmNotificationEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/flab/just_10_minutes/notification/domain/FcmToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/flab/just_10_minutes/notification/dto/CampaignRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/flab/just_10_minutes/notification/dto/FcmNotificationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/flab/just_10_minutes/notification/dto/FcmTokenRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
34 changes: 34 additions & 0 deletions
34
...main/java/com/flab/just_10_minutes/notification/infrastructure/entity/CampaignEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...va/com/flab/just_10_minutes/notification/infrastructure/entity/FcmNotificationEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...main/java/com/flab/just_10_minutes/notification/infrastructure/entity/FcmTokenEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.