-
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.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
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); | ||
} | ||
} |