From 6cdc0db774ad4a3a85e5a8dea52c1489d56d7f81 Mon Sep 17 00:00:00 2001 From: kunsanglee Date: Mon, 22 Jul 2024 16:44:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=96=89=EC=82=AC=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 3juhwan <13selfesteem91@naver.com> --- .../haengdong/application/EventService.java | 9 ++++++- .../response/EventDetailAppResponse.java | 10 ++++++++ .../presentation/EventController.java | 10 ++++++++ .../response/EventDetailResponse.java | 10 ++++++++ .../application/EventServiceTest.java | 24 +++++++++++++++++++ .../presentation/EventControllerTest.java | 16 +++++++++++++ 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/server/haengdong/application/response/EventDetailAppResponse.java create mode 100644 server/src/main/java/server/haengdong/presentation/response/EventDetailResponse.java diff --git a/server/src/main/java/server/haengdong/application/EventService.java b/server/src/main/java/server/haengdong/application/EventService.java index 5fc9cd01c..ea4384148 100644 --- a/server/src/main/java/server/haengdong/application/EventService.java +++ b/server/src/main/java/server/haengdong/application/EventService.java @@ -4,9 +4,10 @@ import org.springframework.stereotype.Service; import server.haengdong.application.request.EventAppRequest; import server.haengdong.application.response.EventAppResponse; +import server.haengdong.application.response.EventDetailAppResponse; import server.haengdong.domain.event.Event; -import server.haengdong.domain.event.EventTokenProvider; import server.haengdong.domain.event.EventRepository; +import server.haengdong.domain.event.EventTokenProvider; @RequiredArgsConstructor @Service @@ -22,4 +23,10 @@ public EventAppResponse saveEvent(EventAppRequest request) { return EventAppResponse.of(event); } + + public EventDetailAppResponse findEvent(String token) { + Event event = eventRepository.findByToken(token).orElseThrow(() -> new IllegalArgumentException("")); + + return EventDetailAppResponse.of(event); + } } diff --git a/server/src/main/java/server/haengdong/application/response/EventDetailAppResponse.java b/server/src/main/java/server/haengdong/application/response/EventDetailAppResponse.java new file mode 100644 index 000000000..6e38826d4 --- /dev/null +++ b/server/src/main/java/server/haengdong/application/response/EventDetailAppResponse.java @@ -0,0 +1,10 @@ +package server.haengdong.application.response; + +import server.haengdong.domain.event.Event; + +public record EventDetailAppResponse(String eventName) { + + public static EventDetailAppResponse of(Event event) { + return new EventDetailAppResponse(event.getName()); + } +} diff --git a/server/src/main/java/server/haengdong/presentation/EventController.java b/server/src/main/java/server/haengdong/presentation/EventController.java index 5254a78ae..1cc7dc77a 100644 --- a/server/src/main/java/server/haengdong/presentation/EventController.java +++ b/server/src/main/java/server/haengdong/presentation/EventController.java @@ -3,11 +3,14 @@ import java.net.URI; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import server.haengdong.application.EventService; import server.haengdong.application.response.EventAppResponse; import server.haengdong.presentation.request.EventSaveRequest; +import server.haengdong.presentation.response.EventDetailResponse; @RequiredArgsConstructor @RestController @@ -23,4 +26,11 @@ public ResponseEntity saveEvent(EventSaveRequest request) { .location(URI.create("events/" + eventAppResponse.token())) .build(); } + + @GetMapping("/api/events/{token}") + public ResponseEntity findEvent(@PathVariable("token") String token) { + EventDetailResponse eventDetailResponse = EventDetailResponse.of(eventService.findEvent(token)); + + return ResponseEntity.ok(eventDetailResponse); + } } diff --git a/server/src/main/java/server/haengdong/presentation/response/EventDetailResponse.java b/server/src/main/java/server/haengdong/presentation/response/EventDetailResponse.java new file mode 100644 index 000000000..c18694393 --- /dev/null +++ b/server/src/main/java/server/haengdong/presentation/response/EventDetailResponse.java @@ -0,0 +1,10 @@ +package server.haengdong.presentation.response; + +import server.haengdong.application.response.EventDetailAppResponse; + +public record EventDetailResponse(String eventName) { + + public static EventDetailResponse of(EventDetailAppResponse response) { + return new EventDetailResponse(response.eventName()); + } +} diff --git a/server/src/test/java/server/haengdong/application/EventServiceTest.java b/server/src/test/java/server/haengdong/application/EventServiceTest.java index 12a5a08a5..31b1c650e 100644 --- a/server/src/test/java/server/haengdong/application/EventServiceTest.java +++ b/server/src/test/java/server/haengdong/application/EventServiceTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -11,6 +12,9 @@ import org.springframework.boot.test.mock.mockito.MockBean; import server.haengdong.application.request.EventAppRequest; import server.haengdong.application.response.EventAppResponse; +import server.haengdong.application.response.EventDetailAppResponse; +import server.haengdong.domain.event.Event; +import server.haengdong.domain.event.EventRepository; import server.haengdong.domain.event.EventTokenProvider; @SpringBootTest @@ -22,6 +26,14 @@ class EventServiceTest { @MockBean private EventTokenProvider eventTokenProvider; + @Autowired + private EventRepository eventRepository; + + @AfterEach + void tearDown() { + eventRepository.deleteAllInBatch(); + } + @DisplayName("행사를 생성한다") @Test void saveEventTest() { @@ -32,4 +44,16 @@ void saveEventTest() { assertThat(response.token()).isEqualTo("TOKEN"); } + + @DisplayName("토큰으로 행사를 조회한다.") + @Test + void findEventTest() { + String token = "TOKEN"; + Event event = new Event("행동대장 회식", token); + eventRepository.save(event); + + EventDetailAppResponse eventDetailAppResponse = eventService.findEvent(token); + + assertThat(eventDetailAppResponse.eventName()).isEqualTo("행동대장 회식"); + } } diff --git a/server/src/test/java/server/haengdong/presentation/EventControllerTest.java b/server/src/test/java/server/haengdong/presentation/EventControllerTest.java index a1d67f0a1..c50431696 100644 --- a/server/src/test/java/server/haengdong/presentation/EventControllerTest.java +++ b/server/src/test/java/server/haengdong/presentation/EventControllerTest.java @@ -2,8 +2,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; 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.fasterxml.jackson.databind.ObjectMapper; @@ -18,6 +20,7 @@ import server.haengdong.application.EventService; import server.haengdong.application.request.EventAppRequest; import server.haengdong.application.response.EventAppResponse; +import server.haengdong.application.response.EventDetailAppResponse; import server.haengdong.presentation.request.EventSaveRequest; @WebMvcTest(EventController.class) @@ -48,4 +51,17 @@ void saveEvent() throws Exception { .andExpect(status().isOk()) .andExpect(MockMvcResultMatchers.redirectedUrl("events/" + token)); } + + @DisplayName("토큰으로 행사를 조회한다.") + @Test + void findEventTest() throws Exception { + String token = "TOKEN"; + EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식"); + given(eventService.findEvent(token)).willReturn(eventDetailAppResponse); + + mockMvc.perform(get("/api/events/" + token)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.eventName").value("행동대장 회식")); + } }