-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from f-lab-edu/feature/15-schedules
[#15] 경기 목록 조회 API 구현
- Loading branch information
Showing
8 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/com/kboticketing/kboticketing/controller/ScheduleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CommonResponse> getSchedules( | ||
ScheduleQueryParamDto scheduleQueryParamDto) { | ||
ArrayList<ScheduleTeam> schedules = scheduleService.getSchedules(scheduleQueryParamDto); | ||
return ResponseEntity.ok(CommonResponse.ok(schedules)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/kboticketing/kboticketing/dao/ScheduleMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ScheduleTeam> selectSchedules(ScheduleQueryParamDto scheduleQueryParamDto); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/kboticketing/kboticketing/domain/ScheduleTeam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/kboticketing/kboticketing/dto/ScheduleQueryParamDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ScheduleTeam> getSchedules(ScheduleQueryParamDto scheduleQueryParamDto) { | ||
return scheduleMapper.selectSchedules(scheduleQueryParamDto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
|
||
<mapper namespace="com.kboticketing.kboticketing.dao.ScheduleMapper"> | ||
<select id="selectSchedules" resultType="com.kboticketing.kboticketing.domain.ScheduleTeam"> | ||
SELECT | ||
schedules.schedule_id, | ||
schedules.name AS scheduleName, | ||
stadium.name AS stadiumName, | ||
schedules.date AS date | ||
FROM schedules schedules | ||
LEFT JOIN | ||
stadium ON stadium.stadium_id = schedules.stadium_id | ||
<where> | ||
<if test="teamId != null"> | ||
AND home_team_id = #{teamId} | ||
</if> | ||
<if test="month != null"> | ||
AND month(date)= #{month} | ||
</if> | ||
<if test="day != null"> | ||
AND day(date)= #{day} | ||
</if> | ||
<if test="stadiumId != null"> | ||
AND schedules.stadium_id = #{stadiumId} | ||
</if> | ||
</where> | ||
</select> | ||
</mapper> |
49 changes: 49 additions & 0 deletions
49
src/test/java/com/kboticketing/kboticketing/controller/ScheduleControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ScheduleTeam> 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())); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/com/kboticketing/kboticketing/service/ScheduleServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ScheduleTeam> 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); | ||
} | ||
} |