Skip to content

Commit

Permalink
Merge pull request #165 from Genti2024/hotfix/push-type
Browse files Browse the repository at this point in the history
Fix: #163 swagger 문서화 추가
  • Loading branch information
BYEONGRYEOL authored Sep 15, 2024
2 parents 819b7e3 + 15f4345 commit 49490f0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.gt.genti.admin.api;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

import com.gt.genti.admin.dto.request.SendPushRequestDto;
import com.gt.genti.error.ResponseCode;
import com.gt.genti.response.GentiResponse;
import com.gt.genti.swagger.EnumResponse;
import com.gt.genti.swagger.EnumResponses;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "[PushNotificationController] 푸시알림 컨트롤러", description = "백엔드용 푸시알림 보내기")
public interface PushNotificationApi {

@Operation(summary = "업데이트 푸시알림 보내기", description = "OB, YB 유저 식별하여 전체 푸시알림")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
})
ResponseEntity<GentiResponse.ApiResult<Boolean>> sendUpdatePush(
@RequestHeader(value = "Admin-Secret-Key") String adminSecretKey,
@RequestBody SendPushRequestDto sendPushRequestDto
);

@Operation(summary = "푸시알림 테스트", description = "이메일 입력하여 해당 사용자에게 테스트")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
})
ResponseEntity<GentiResponse.ApiResult<Boolean>> test(
@RequestHeader(value = "Admin-Secret-Key") String adminSecretKey,
@RequestBody SendPushRequestDto sendPushRequestDto,
@RequestParam(name = "email") String email
);
}


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gt.genti.admin;
package com.gt.genti.admin.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
Expand All @@ -7,7 +7,9 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.gt.genti.admin.api.PushNotificationApi;
import com.gt.genti.admin.dto.request.SendPushRequestDto;
import com.gt.genti.admin.service.PushNotificationService;
import com.gt.genti.error.ExpectedException;
Expand All @@ -21,15 +23,16 @@
@Controller
@RequiredArgsConstructor
@RequestMapping("/api/v1/push")
public class PushNotificationController {
public class PushNotificationController implements PushNotificationApi {

private final PushNotificationService pushNotificationService;

@Value("${openchat.admin-secret-key}")
private String ADMIN_SECRET_KEY;

@Override()
@PostMapping("/update")
public ResponseEntity<GentiResponse.ApiResult<Boolean>> modifyOpenChatInfo(
public ResponseEntity<GentiResponse.ApiResult<Boolean>> sendUpdatePush(
@RequestHeader(value = "Admin-Secret-Key") String adminSecretKey,
@RequestBody SendPushRequestDto sendPushRequestDto
) {
Expand All @@ -41,15 +44,17 @@ public ResponseEntity<GentiResponse.ApiResult<Boolean>> modifyOpenChatInfo(
}
}

@Override
@PostMapping("/test")
public ResponseEntity<GentiResponse.ApiResult<Boolean>> test(
@RequestHeader(value = "Admin-Secret-Key") String adminSecretKey,
@RequestBody SendPushRequestDto sendPushRequestDto
@RequestBody SendPushRequestDto sendPushRequestDto,
@RequestParam(name = "email") String email
) {
if (!ADMIN_SECRET_KEY.equals(adminSecretKey)) {
throw ExpectedException.withLogging(ResponseCode.InvalidOpenChatSecretKey);
} else {
pushNotificationService.test(sendPushRequestDto);
pushNotificationService.test(sendPushRequestDto, email);
return GentiResponse.success(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public void sendUpdatePush(SendPushRequestDto sendPushRequestDto) {
sendPushRequestDto.getBody()));
}

public void test(SendPushRequestDto sendPushRequestDto) {
userRepository.findByEmail("[email protected]").ifPresent(
public void test(SendPushRequestDto sendPushRequestDto, String email) {
userRepository.findByEmail(email).ifPresent(
u -> customEventPublisher.publishCustomEvent(u.getId(), sendPushRequestDto.getTitle(),
sendPushRequestDto.getBody())
);
Expand Down

0 comments on commit 49490f0

Please sign in to comment.