diff --git a/src/main/java/com/kboticketing/kboticketing/controller/ScheduleController.java b/src/main/java/com/kboticketing/kboticketing/controller/ScheduleController.java new file mode 100644 index 0000000..e4092d3 --- /dev/null +++ b/src/main/java/com/kboticketing/kboticketing/controller/ScheduleController.java @@ -0,0 +1,29 @@ +package com.kboticketing.kboticketing.controller; + + +import com.kboticketing.kboticketing.domain.ScheduleTeam; +import com.kboticketing.kboticketing.dto.ScheduleQueryParamDto; +import com.kboticketing.kboticketing.service.ScheduleService; +import com.kboticketing.kboticketing.utils.response.CommonResponse; +import java.util.ArrayList; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author hazel + */ +@RestController +@RequiredArgsConstructor +public class ScheduleController { + + private final ScheduleService scheduleService; + + @GetMapping("schedules") + public ResponseEntity getSchedules( + ScheduleQueryParamDto scheduleQueryParamDto) { + ArrayList schedules = scheduleService.getSchedules(scheduleQueryParamDto); + return ResponseEntity.ok(CommonResponse.ok(schedules)); + } +} diff --git a/src/main/java/com/kboticketing/kboticketing/dao/ScheduleMapper.java b/src/main/java/com/kboticketing/kboticketing/dao/ScheduleMapper.java new file mode 100644 index 0000000..392f359 --- /dev/null +++ b/src/main/java/com/kboticketing/kboticketing/dao/ScheduleMapper.java @@ -0,0 +1,15 @@ +package com.kboticketing.kboticketing.dao; + +import com.kboticketing.kboticketing.domain.ScheduleTeam; +import com.kboticketing.kboticketing.dto.ScheduleQueryParamDto; +import java.util.ArrayList; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author hazel + */ +@Mapper +public interface ScheduleMapper { + + ArrayList selectSchedules(ScheduleQueryParamDto scheduleQueryParamDto); +} diff --git a/src/main/java/com/kboticketing/kboticketing/domain/ScheduleTeam.java b/src/main/java/com/kboticketing/kboticketing/domain/ScheduleTeam.java new file mode 100644 index 0000000..679501a --- /dev/null +++ b/src/main/java/com/kboticketing/kboticketing/domain/ScheduleTeam.java @@ -0,0 +1,17 @@ +package com.kboticketing.kboticketing.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * @author hazel + */ +@RequiredArgsConstructor +@Getter +public class ScheduleTeam { + + private final Integer scheduleId; + private final String scheduleName; + private final String stadiumName; + private final String date; +} diff --git a/src/main/java/com/kboticketing/kboticketing/dto/ScheduleQueryParamDto.java b/src/main/java/com/kboticketing/kboticketing/dto/ScheduleQueryParamDto.java new file mode 100644 index 0000000..b069b8b --- /dev/null +++ b/src/main/java/com/kboticketing/kboticketing/dto/ScheduleQueryParamDto.java @@ -0,0 +1,25 @@ +package com.kboticketing.kboticketing.dto; + +import java.time.LocalDateTime; +import lombok.Getter; + +/** + * @author hazel + */ +@Getter +public class ScheduleQueryParamDto { + + private final Integer teamId; + private final Integer month; + private final Integer day; + private final Integer stadiumId; + + public ScheduleQueryParamDto(Integer teamId, Integer month, Integer day, Integer stadiumId) { + this.teamId = teamId; + // month 필드가 null이라면 현재 월 설정 + this.month = month == null ? LocalDateTime.now() + .getMonthValue() : month; + this.day = day; + this.stadiumId = stadiumId; + } +} diff --git a/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java b/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java new file mode 100644 index 0000000..d636cb9 --- /dev/null +++ b/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java @@ -0,0 +1,22 @@ +package com.kboticketing.kboticketing.service; + +import com.kboticketing.kboticketing.dao.ScheduleMapper; +import com.kboticketing.kboticketing.domain.ScheduleTeam; +import com.kboticketing.kboticketing.dto.ScheduleQueryParamDto; +import java.util.ArrayList; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * @author hazel + */ +@Service +@RequiredArgsConstructor +public class ScheduleService { + + private final ScheduleMapper scheduleMapper; + + public ArrayList getSchedules(ScheduleQueryParamDto scheduleQueryParamDto) { + return scheduleMapper.selectSchedules(scheduleQueryParamDto); + } +} diff --git a/src/main/resources/mapper/ScheduleMapper.xml b/src/main/resources/mapper/ScheduleMapper.xml new file mode 100644 index 0000000..3225db8 --- /dev/null +++ b/src/main/resources/mapper/ScheduleMapper.xml @@ -0,0 +1,30 @@ + + + + + + \ No newline at end of file diff --git a/src/test/java/com/kboticketing/kboticketing/controller/ScheduleControllerTest.java b/src/test/java/com/kboticketing/kboticketing/controller/ScheduleControllerTest.java new file mode 100644 index 0000000..63159b0 --- /dev/null +++ b/src/test/java/com/kboticketing/kboticketing/controller/ScheduleControllerTest.java @@ -0,0 +1,49 @@ +package com.kboticketing.kboticketing.controller; + +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.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.kboticketing.kboticketing.domain.ScheduleTeam; +import com.kboticketing.kboticketing.service.ScheduleService; +import java.util.ArrayList; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; + +/** + * @author hazel + */ +@WebMvcTest(ScheduleController.class) +@ExtendWith(MockitoExtension.class) +class ScheduleControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + ScheduleService scheduleService; + + @Test + @DisplayName("[SUCCESS] 일정 목록 조회 테스트") + public void getSchedulesTest() throws Exception { + + //given + ArrayList scheduleTeams = new ArrayList<>(); + scheduleTeams.add(new ScheduleTeam(1, "LG vs SSG", "잠실종합운동장", "2024-04-01 18:30:00")); + given(scheduleService.getSchedules(any())).willReturn(scheduleTeams); + + //when, then + mockMvc.perform(get("/schedules")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.data[0].scheduleId").value(scheduleTeams.get(0) + .getScheduleId())); + } +} \ No newline at end of file diff --git a/src/test/java/com/kboticketing/kboticketing/service/ScheduleServiceTest.java b/src/test/java/com/kboticketing/kboticketing/service/ScheduleServiceTest.java new file mode 100644 index 0000000..cd189ad --- /dev/null +++ b/src/test/java/com/kboticketing/kboticketing/service/ScheduleServiceTest.java @@ -0,0 +1,42 @@ +package com.kboticketing.kboticketing.service; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.mockito.ArgumentMatchers.any; + +import com.kboticketing.kboticketing.dao.ScheduleMapper; +import com.kboticketing.kboticketing.domain.ScheduleTeam; +import java.util.ArrayList; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.mockito.BDDMockito.given; + +/** + * @author hazel + */ +@ExtendWith(MockitoExtension.class) +class ScheduleServiceTest { + + @Mock + private ScheduleMapper scheduleMapper; + + @InjectMocks + private ScheduleService scheduleService; + + @Test + @DisplayName("[SUCCESS] 경기 목록 조회 테스트") + public void getSchedulesTest() { + + //given + ArrayList scheduleTeams = new ArrayList<>(); + scheduleTeams.add(new ScheduleTeam(1, "LG vs SSG", "잠실종합운동장", "2024-04-01 18:30:00")); + given(scheduleMapper.selectSchedules(any())).willReturn(scheduleTeams); + + //when, then + assertThat(scheduleService.getSchedules(any())).isEqualTo(scheduleTeams); + } +} \ No newline at end of file