Skip to content

Commit

Permalink
feat: 행사 정보 조회 기능 구현
Browse files Browse the repository at this point in the history
Co-authored-by: 3juhwan <[email protected]>
  • Loading branch information
kunsanglee and 3Juhwan committed Jul 22, 2024
1 parent 22e4af8 commit 6cdc0db
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,4 +26,11 @@ public ResponseEntity<Void> saveEvent(EventSaveRequest request) {
.location(URI.create("events/" + eventAppResponse.token()))
.build();
}

@GetMapping("/api/events/{token}")
public ResponseEntity<EventDetailResponse> findEvent(@PathVariable("token") String token) {
EventDetailResponse eventDetailResponse = EventDetailResponse.of(eventService.findEvent(token));

return ResponseEntity.ok(eventDetailResponse);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
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;
import org.springframework.boot.test.context.SpringBootTest;
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
Expand All @@ -22,6 +26,14 @@ class EventServiceTest {
@MockBean
private EventTokenProvider eventTokenProvider;

@Autowired
private EventRepository eventRepository;

@AfterEach
void tearDown() {
eventRepository.deleteAllInBatch();
}

@DisplayName("행사를 생성한다")
@Test
void saveEventTest() {
Expand All @@ -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("행동대장 회식");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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("행동대장 회식"));
}
}

0 comments on commit 6cdc0db

Please sign in to comment.