<aside> 📌 Meezle 의 이벤트를 톡캘린더와 연동시키기
</aside>
톡캘린더는 카카오톡 채팅방에서 일정을 만들고, 모아볼 수 있는 서비스입니다. 톡캘린더 API는 사용자의 톡캘린더에 일정을 추가하고 관리하는 기능을 제공합니다.
톡 캘린더는 카카오톡에서 제공하는 캘린더 서비스로, 등록된 이벤트가 시작되기 전, 카톡으로 알림을 보내준다. 우리가 주목한 것은 카톡으로 알림을 보내는 것
이었다. Meezle 의 경우, 모임의 일정을 확정하는 것까진 가능하지만, 이용자에게 그것을 알려주는 기능이 구현되어 있지 않았다. 이를 별도로 구현하는 것도 좋지만, 카카오톡 소셜 로그인을 지원하는 참에 쓸만한 API 를 찾았고, 우리의 요구와 딱 맞는 것을 찾을 수 있었다.
<aside> 🔥 모르는 API 를 살필 때, Postman 을 꼭 사용하자!!!!
</aside>
로그인을 제외하고 외부 API 를 적극적으로 사용하려 한적은 이번이 처음이었다. 그래서 어떻게 API 를 검토할 수 있을까 고민하다, 무작정 문서를 읽고, Spring 으로 구현하려고 시도했다. 하지만 어떤 형식으로 반환값이 도착하는지, RRULE 의 형식은 무엇인지 모호한 상태로 구현하다보니 많은 시간이 소비 되었다. 그래서 다른 방법은 없을까 고민하다 문득 예전에 Postman
으로 직접 만든 API 를 테스트한 경험이 떠올라서 바로 사용해봤다.
<aside> 💡 짱짱
</aside>
최고다..!!
API 가 어떤 형식으로 요청되고 반환 되는지 손쉽게 알 수 있었다. 기존의 방법으로는 한 API 를 테스트하기 위해서는
이라는 여러 단계를 거쳐야 했지만, Postman 을 사용함으로써 어떤 형식이 필요한지 몇 초 만에 바로 알 수 있었다. 예를 들어, 톡캘린더를 생성하는 API 를 검토할 때,
Spring 구현
@PostMapping("/calendar")
public @Valid ApiCallResponse<CalendarPostResponse> createCalendar(
@Valid @NotNull @RequestParam(value = "platform") PlatformType platform,
@Valid @RequestBody CalendarPostRequest body
) {
final var currentUser = authService.getCurrentUserInfo();
final var oAuth2TokenInfo = oauth2Service.getToken(currentUser.userId());
CalendarPostResponse calendar = null;
switch (platform) {
case KAKAO -> {
final var kakaoCalendar = kakaoService.createKakaoCalendar(oAuth2TokenInfo.getAccessToken(), body);
calendar = CalendarPostResponse.of(kakaoCalendar);
}
default -> {
throw new InvalidValueException(String.format("Undefined platform : %s", platform.name()), "유효하지 않은 플랫폼입니다.");
}
}
return ApiCallResponse.ofSuccess(calendar);
}
public KakaoCalendarPostResponse createKakaoCalendar(String accessToken, CalendarPostRequest request) {
return kakaoApiClient
.createCalendar(HttpUtils.withBearerToken(accessToken), request.name(), request.color(), request.reminder(), request.reminderAllDay());
}
@Retryable(backoff = @Backoff(delay = 50, multiplier = 2, maxDelay = 1000), value = BadGatewayException.class)
@PostMapping("/v2/api/calendar/create/calendar")
KakaoCalendarPostResponse createCalendar(
@RequestHeader("Authorization") String accessToken,
@RequestParam(name = "name") String name,
@RequestParam(name = "color", required = false) KakaoCalendarColor color,
@RequestParam(name = "reminder", required = false) Integer reminder,
@RequestParam(name = "reminder_all_day", required = false) Integer reminderAllDay);
public record KakaoCalendar(
@JsonProperty(value = "id", defaultValue = "primary", required = true)
String id,
@JsonProperty(value = "name")
String name,
@JsonProperty(value = "color")
KakaoCalendarColor color,
@JsonProperty(value = "reminder")
Integer reminder,
@JsonProperty(value = "reminder_all_day")
Integer reminderAllDay
) {
}
등 수많은 작업을 거쳐야 했다. 물론 실제 연동을 할 때, 위 모듈을 이용하긴 하지만, 구현이 아닌 검토 과정에서 이러한 과정을 거치는 것은 너무 많은 시간 낭비를 초래했다.
Postman
위 과정을 Postman 으로 검토하면 매우 간단한데,
테스트 API Limit 은 너무 짜다. ㅜㅜㅜ
문서에 나온 내용을 그대로 붙여 넣기만 한다면, 바로 결과가 나온다.
우리 서비스에서 필요한 API 는 서브캘린더
와 일반 일정
이었다. 그 이유는