Skip to content

Commit

Permalink
feat: push alarm 테스트 api 추가
Browse files Browse the repository at this point in the history
Related-to : #17
  • Loading branch information
ji-woong-song committed Apr 2, 2024
1 parent 32163da commit 5e3d35c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/main/java/com/umc5th/muffler/global/TestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.umc5th.muffler.global;

import com.umc5th.muffler.domain.goal.dto.FinishedGoal;
import com.umc5th.muffler.domain.member.repository.MemberRepository;
import com.umc5th.muffler.entity.Member;
import com.umc5th.muffler.global.response.code.ErrorCode;
import com.umc5th.muffler.global.response.exception.MemberException;
import com.umc5th.muffler.message.service.AlarmService;
import java.security.Principal;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// push alarm test용 테스트 완료 후 제거 예정
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/test")
public class TestController {
private final AlarmService alarmService;
private final MemberRepository memberRepository;
@GetMapping("/alarm")
public ResponseEntity<String> testAlarm(Principal principal) {
Member member = memberRepository.findById(principal.getName())
.orElseThrow(() -> new MemberException(ErrorCode.MEMBER_NOT_FOUND));
String token = member.getMemberAlarm().getToken();
if (token == null || token.isEmpty()) {
throw new MemberException(ErrorCode.BAD_REQUEST);
}
alarmService.sendEndGoals(List.of(new FinishedGoal("goal title", "goal icon", token)));
return ResponseEntity.ok("success");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.umc5th.muffler.global.util.DefaultDateTimeProvider;
import com.umc5th.muffler.message.service.sender.Sender;
import com.umc5th.muffler.message.service.sender.impl.ConsoleMessageSender;
import com.umc5th.muffler.message.service.sender.impl.FirebaseMessageSender;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
Expand All @@ -17,5 +18,5 @@ public DateTimeProvider dateTimeProvider() {
}

@Bean
public Sender Sender() { return new ConsoleMessageSender(); }
public Sender Sender() { return new FirebaseMessageSender(); }
}

0 comments on commit 5e3d35c

Please sign in to comment.