-
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 #34 from VOM-Project/feature/fcm
feat: Add Webpush API
- Loading branch information
Showing
13 changed files
with
263 additions
and
135 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
37 changes: 0 additions & 37 deletions
37
src/main/java/vom/spring/domain/webpush/FcmController.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
82 changes: 0 additions & 82 deletions
82
src/main/java/vom/spring/domain/webpush/FcmServiceImpl.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/main/java/vom/spring/domain/webpush/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,51 @@ | ||
package vom.spring.domain.webpush.controller; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
import vom.spring.domain.webpush.dto.ApiResponseWrapper; | ||
import vom.spring.domain.webpush.service.FcmService; | ||
import vom.spring.domain.webpush.domain.SuccessCode; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@Controller | ||
public class FcmController { | ||
private FcmService fcmService; | ||
@Autowired | ||
public FcmController(FcmService fcmService) { | ||
this.fcmService = fcmService; | ||
} | ||
|
||
@PostMapping(value = "/api/fcm/{member-id}") | ||
public ResponseEntity<HttpStatus> setFcmToken( | ||
@PathVariable("member-id") Long member_id, | ||
@RequestParam String fcmToken | ||
) { | ||
fcmService.setFcmToken(fcmToken, member_id); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
// 웹 푸시 서비스 테스트용 | ||
@PostMapping("/api/v2/fcm/send/{member_id}") | ||
public ResponseEntity<ApiResponseWrapper<Object>> pushMessage( | ||
@PathVariable("member_id") Long memberId | ||
) throws IOException { | ||
log.debug("[+] 푸시 메시지를 전송합니다. "); | ||
|
||
int result = fcmService.sendMessageTo(memberId); | ||
|
||
ApiResponseWrapper<Object> arw = ApiResponseWrapper | ||
.builder() | ||
.result(result) | ||
.resultCode(SuccessCode.SELECT_SUCCESS.getStatus()) | ||
.resultMsg(SuccessCode.SELECT_SUCCESS.getMessage()) | ||
.build(); | ||
|
||
return new ResponseEntity<>(arw, HttpStatus.OK); | ||
} | ||
} |
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,32 @@ | ||
package vom.spring.domain.webpush.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import vom.spring.domain.member.domain.Member; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
public class Fcm { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private LocalDateTime createdAt; | ||
|
||
@Column(nullable = false) | ||
private String fcmToken; | ||
|
||
@OneToOne | ||
@JoinColumn(referencedColumnName = "id", name = "member_id", nullable = false) | ||
private Member member; | ||
} |
2 changes: 1 addition & 1 deletion
2
...om/spring/domain/webpush/SuccessCode.java → ...ng/domain/webpush/domain/SuccessCode.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
2 changes: 1 addition & 1 deletion
2
...ng/domain/webpush/ApiResponseWrapper.java → ...omain/webpush/dto/ApiResponseWrapper.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,4 +1,4 @@ | ||
package vom.spring.domain.webpush; | ||
package vom.spring.domain.webpush.dto; | ||
|
||
import lombok.Getter; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../spring/domain/webpush/FcmMessageDto.java → ...ing/domain/webpush/dto/FcmMessageDto.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
2 changes: 1 addition & 1 deletion
2
...vom/spring/domain/webpush/FcmSendDto.java → ...spring/domain/webpush/dto/FcmSendDto.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,4 +1,4 @@ | ||
package vom.spring.domain.webpush; | ||
package vom.spring.domain.webpush.dto; | ||
|
||
import lombok.*; | ||
|
||
|
28 changes: 28 additions & 0 deletions
28
src/main/java/vom/spring/domain/webpush/repository/FcmRepository.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,28 @@ | ||
package vom.spring.domain.webpush.repository; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.NoResultException; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.springframework.stereotype.Repository; | ||
import vom.spring.domain.webpush.domain.Fcm; | ||
|
||
@Repository | ||
public class FcmRepository { | ||
|
||
@PersistenceContext | ||
private EntityManager em; | ||
|
||
public void save(Fcm fcm) { | ||
em.persist(fcm); | ||
} | ||
|
||
public Fcm findByMember_id(Long member_id) { | ||
try { | ||
return em.createQuery("SELECT f FROM Fcm f WHERE f.member.id = :member_id", Fcm.class) | ||
.setParameter("member_id", member_id) | ||
.getSingleResult(); | ||
} catch (NoResultException e) { | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.