Skip to content

Commit

Permalink
[HOTFIX] plan api
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Jan 13, 2024
1 parent 79a9d63 commit daa2096
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 23 deletions.
3 changes: 3 additions & 0 deletions backend/src/docs/plan.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ operation::post update plan[snippets='http-request,http-response']

=== 계획 날짜 수정
operation::post update plan day[snippets='http-request,http-response']

=== 그룹 내부의 계획 전체 조회
operation::get all plans by group[snippets='http-request,http-response']
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.google.firebase.messaging.FirebaseMessagingException;
import com.twtw.backend.domain.notification.dto.NotificationRequest;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class FcmConsumer {
private final FirebaseMessaging firebaseMessaging;
Expand All @@ -16,8 +18,11 @@ public FcmConsumer(FirebaseMessaging firebaseMessaging) {
}

@RabbitListener(queues = "notification.queue")
public void sendNotification(final NotificationRequest request)
throws FirebaseMessagingException {
firebaseMessaging.send(request.toMessage());
public void sendNotification(final NotificationRequest request) {
try {
firebaseMessaging.send(request.toMessage());
} catch (FirebaseMessagingException e) {
log.error(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public ResponseEntity<List<PlanInfoResponse>> getPlans() {
return ResponseEntity.ok(planService.getPlans());
}

@GetMapping("group/{groupId}")
public ResponseEntity<List<PlanInfoResponse>> getPlansByGroupId(@PathVariable final UUID groupId) {
return ResponseEntity.ok(planService.getPlansByGroupId(groupId));
}

@PostMapping("update")
public ResponseEntity<Void> updatePlan(@RequestBody final UpdatePlanRequest updatePlanRequest) {
planService.updatePlan(updatePlanRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,10 @@ public void deleteInvite(final PlanMemberRequest request) {
Plan plan = getPlanEntity(request.getPlanId());
plan.deleteInvite(member);
}

public List<PlanInfoResponse> getPlansByGroupId(final UUID groupId) {
final Group group = groupService.getGroupEntity(groupId);
final List<Plan> plans = group.getGroupPlans();
return plans.stream().map(this::getPlanInfoResponse).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package com.twtw.backend.domain.place.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;

import com.twtw.backend.domain.place.dto.client.SurroundPlaceRequest;
import com.twtw.backend.domain.place.dto.client.SurroundPlaceResponse;
import com.twtw.backend.domain.place.entity.Place;
import com.twtw.backend.domain.plan.dto.client.MetaDetails;
import com.twtw.backend.domain.plan.dto.client.PlaceClientDetails;
import com.twtw.backend.domain.plan.dto.response.PlaceDetails;
import com.twtw.backend.fixture.place.PlaceDetailsFixture;
import com.twtw.backend.fixture.place.PlaceEntityFixture;
import com.twtw.backend.global.client.KakaoMapClient;
import com.twtw.backend.support.service.LoginTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;

@DisplayName("PlaceService의")
class PlaceServiceTest extends LoginTest {

Expand Down Expand Up @@ -56,7 +54,7 @@ void getPlaceDetails() {
final Place place = PlaceEntityFixture.FIRST_PLACE.toEntity();

// when
final PlaceClientDetails placeDetails = placeService.getPlaceDetails(place);
final PlaceDetails placeDetails = placeService.getPlaceDetails(place);

// then
assertThat(placeDetails.getPlaceName()).isEqualTo(place.getPlaceName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package com.twtw.backend.domain.plan.controller;

import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentRequest;
import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentResponse;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willDoNothing;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.twtw.backend.domain.group.dto.response.GroupInfoResponse;
import com.twtw.backend.domain.member.dto.response.MemberResponse;
import com.twtw.backend.domain.place.entity.CategoryGroupCode;
Expand All @@ -25,7 +13,6 @@
import com.twtw.backend.domain.plan.dto.response.PlanResponse;
import com.twtw.backend.domain.plan.service.PlanService;
import com.twtw.backend.support.docs.RestDocsTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -38,6 +25,17 @@
import java.util.List;
import java.util.UUID;

import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentRequest;
import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentResponse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willDoNothing;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@DisplayName("PlanController의")
@WebMvcTest(PlanController.class)
class PlanControllerTest extends RestDocsTest {
Expand Down Expand Up @@ -465,4 +463,99 @@ void updatePlan() throws Exception {
perform.andDo(print())
.andDo(document("post update plan", getDocumentRequest(), getDocumentResponse()));
}

@Test
@DisplayName("계획 전체 조회 API가 수행되는가")
void getPlansByGroupId() throws Exception {
// given
final List<PlanInfoResponse> expected =
List.of(
PlanInfoResponse.builder()
.planId(UUID.randomUUID())
.planMakerId(UUID.randomUUID())
.placeId(UUID.randomUUID())
.name("약속1")
.planDay("2023-12-25 15:30")
.placeDetails(
new PlaceDetails(
"카페 온마이마인드",
"https://place.map.kakao.com/1625295668",
"경기 안성시 죽산면 죽산초교길 36-4",
127.420430538256,
37.0766874564297))
.groupInfo(
new GroupInfoResponse(
UUID.randomUUID(),
UUID.randomUUID(),
"홍담진",
"http://someUrlToS3",
List.of(
new MemberResponse(
UUID.randomUUID(),
"카즈하",
"http://HJ39GOAT"),
new MemberResponse(
UUID.randomUUID(),
"사쿠라",
"http://HJ39"))))
.members(
List.of(
new MemberResponse(
UUID.randomUUID(),
"진호정",
"http://HoJin39")))
.build(),
PlanInfoResponse.builder()
.planId(UUID.randomUUID())
.planMakerId(UUID.randomUUID())
.placeId(UUID.randomUUID())
.name("약속2")
.planDay("2023-12-25 15:30")
.placeDetails(
new PlaceDetails(
"카페 온마이마인드",
"https://place.map.kakao.com/1625295668",
"경기 안성시 죽산면 죽산초교길 36-4",
127.420430538256,
37.0766874564297))
.groupInfo(
new GroupInfoResponse(
UUID.randomUUID(),
UUID.randomUUID(),
"HongDamJin",
"http://someUrlToS3",
List.of(
new MemberResponse(
UUID.randomUUID(),
"카즈하",
"http://HJ39"),
new MemberResponse(
UUID.randomUUID(),
"사쿠라",
"http://HJ39"))))
.members(
List.of(
new MemberResponse(
UUID.randomUUID(),
"JinHoJeong",
"http://HJ39")))
.build());

given(planService.getPlansByGroupId(any())).willReturn(expected);

// when
final ResultActions perform =
mockMvc.perform(
get("/plans/group/" + UUID.randomUUID())
.contentType(MediaType.APPLICATION_JSON)
.header(
"Authorization",
"Bearer wefa3fsdczf32.gaoiuergf92.gb5hsa2jgh"));
// then
perform.andExpect(status().isOk());

// docs
perform.andDo(print())
.andDo(document("get all plans by group", getDocumentRequest(), getDocumentResponse()));
}
}

0 comments on commit daa2096

Please sign in to comment.