-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
352 additions
and
415 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
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
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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/project/backend/domain/fcm/controller/FcmController.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,23 @@ | ||
package project.backend.domain.fcm.controller; | ||
|
||
import io.swagger.annotations.Api; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
import project.backend.domain.fcm.service.FcmService; | ||
|
||
@RestController | ||
@RequestMapping("/api/fcm") | ||
@RequiredArgsConstructor | ||
@Api(tags = "테스트용 FCM - 삭제 예정") | ||
public class FcmController { | ||
|
||
private final FcmService fcmService; | ||
|
||
@PostMapping("/send") | ||
public String sendNotification(@RequestParam String token, | ||
@RequestParam String title, | ||
@RequestParam String body){ | ||
fcmService.sendNotificationByToken(token, title, body); | ||
return "Notification sent successfully"; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/project/backend/domain/fcm/service/FcmService.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,51 @@ | ||
package project.backend.domain.fcm.service; | ||
|
||
import com.google.firebase.messaging.FirebaseMessaging; | ||
import com.google.firebase.messaging.Message; | ||
import com.google.firebase.messaging.Notification; | ||
import org.springframework.stereotype.Service; | ||
import project.backend.domain.member.entity.Member; | ||
|
||
@Service | ||
public class FcmService { | ||
public void sendNotification(Member member, String title, String body) { | ||
String fcmToken = member.getFcmToken(); | ||
|
||
if (fcmToken != null) { | ||
Notification notification = Notification.builder() | ||
.setTitle(title) | ||
.setBody(body) | ||
.build(); | ||
|
||
Message message = Message.builder() | ||
.setToken(fcmToken) | ||
.setNotification(notification) | ||
.build(); | ||
try { | ||
String response = FirebaseMessaging.getInstance().send(message); | ||
System.out.println("Successfully sent message: " + response); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public void sendNotificationByToken(String token, String title, String body) { | ||
Notification notification = Notification.builder() | ||
.setTitle(title) | ||
.setBody(body) | ||
.build(); | ||
|
||
Message message = Message.builder() | ||
.setToken(token) | ||
.setNotification(notification) | ||
.build(); | ||
|
||
try { | ||
String response = FirebaseMessaging.getInstance().send(message); | ||
System.out.println("Successfully sent message: " + response); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
14 changes: 11 additions & 3 deletions
14
src/main/java/project/backend/domain/like/CulturalEventLikeListener.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 |
---|---|---|
@@ -1,18 +1,26 @@ | ||
package project.backend.domain.like; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import project.backend.domain.like.entity.CulturalEventLike; | ||
import project.backend.domain.notification.service.NotificationService; | ||
|
||
import javax.persistence.PrePersist; | ||
import javax.persistence.PreRemove; | ||
|
||
|
||
|
||
@Component | ||
public class CulturalEventLikeListener { | ||
|
||
@PrePersist | ||
public void postPersist(CulturalEventLike culturalEventLike) { | ||
public void prePersist(CulturalEventLike culturalEventLike) { | ||
culturalEventLike.culturalEvent.increaseLikeCount(); | ||
} | ||
|
||
@PreRemove | ||
public void postRemove(CulturalEventLike culturalEventLike) { | ||
public void preRemove(CulturalEventLike culturalEventLike) { | ||
culturalEventLike.deleteCulturalEventLike(); | ||
culturalEventLike.culturalEvent.decreaseLikeCount(); | ||
} | ||
} | ||
} |
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
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
18 changes: 18 additions & 0 deletions
18
src/main/java/project/backend/domain/member/dto/MemberFcmTokenDto.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,18 @@ | ||
package project.backend.domain.member.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
import javax.validation.constraints.Size; | ||
|
||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class MemberFcmTokenDto { | ||
@NotNull(message = "fcmToken은 필수 값입니다.") | ||
public String fcmToken; | ||
} |
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
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
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
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
Oops, something went wrong.