-
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 #16 from f-lab-edu/feature/14-teams
[#14] 팀 목록 조회 API 구현
- Loading branch information
Showing
8 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/kboticketing/kboticketing/controller/TeamController.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,26 @@ | ||
package com.kboticketing.kboticketing.controller; | ||
|
||
import com.kboticketing.kboticketing.domain.Team; | ||
import com.kboticketing.kboticketing.service.TeamService; | ||
import com.kboticketing.kboticketing.utils.response.CommonResponse; | ||
import java.util.List; | ||
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 TeamController { | ||
|
||
private final TeamService teamService; | ||
|
||
@GetMapping("teams") | ||
public ResponseEntity<CommonResponse> getTeams() { | ||
List<Team> teams = teamService.getTeams(); | ||
return ResponseEntity.ok(CommonResponse.ok(teams)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/kboticketing/kboticketing/dao/TeamMapper.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.Team; | ||
import java.util.List; | ||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
/** | ||
* @author hazel | ||
*/ | ||
@Mapper | ||
public interface TeamMapper { | ||
|
||
List<Team> selectTeams(); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/kboticketing/kboticketing/domain/Team.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.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* @author hazel | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
public class Team { | ||
|
||
private final Integer teamId; | ||
private final String name; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/kboticketing/kboticketing/service/TeamService.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,21 @@ | ||
package com.kboticketing.kboticketing.service; | ||
|
||
import com.kboticketing.kboticketing.dao.TeamMapper; | ||
import com.kboticketing.kboticketing.domain.Team; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author hazel | ||
*/ | ||
@Service | ||
@RequiredArgsConstructor | ||
public class TeamService { | ||
|
||
private final TeamMapper teamMapper; | ||
|
||
public List<Team> getTeams() { | ||
return teamMapper.selectTeams(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/kboticketing/kboticketing/utils/response/CommonResponse.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,21 @@ | ||
package com.kboticketing.kboticketing.utils.response; | ||
|
||
import com.kboticketing.kboticketing.utils.DateTimeUtils; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* @author hazel | ||
*/ | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public class CommonResponse { | ||
|
||
private final Object data; | ||
private final String timestamp; | ||
|
||
public static CommonResponse ok(Object data) { | ||
return new CommonResponse(data, DateTimeUtils.getCurrentTime()); | ||
} | ||
} |
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,11 @@ | ||
<?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.TeamMapper"> | ||
<select id="selectTeams" resultType="com.kboticketing.kboticketing.domain.Team"> | ||
SELECT team_id, name | ||
FROM teams | ||
</select> | ||
|
||
</mapper> |
54 changes: 54 additions & 0 deletions
54
src/test/java/com/kboticketing/kboticketing/controller/TeamControllerTest.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,54 @@ | ||
package com.kboticketing.kboticketing.controller; | ||
|
||
import static org.mockito.BDDMockito.*; | ||
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.Team; | ||
import com.kboticketing.kboticketing.service.TeamService; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
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(TeamController.class) | ||
@ExtendWith(MockitoExtension.class) | ||
class TeamControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private TeamService teamService; | ||
|
||
@Test | ||
@DisplayName("[SUCCESS] 팀 리스트 테스트") | ||
public void getTeamsTest() throws Exception { | ||
|
||
//given | ||
List<Team> fakeTeams = Arrays.asList( | ||
new Team(1, "Team 1"), | ||
new Team(2, "Team 2"), | ||
new Team(3, "Team 3") | ||
); | ||
given(teamService.getTeams()).willReturn(fakeTeams); | ||
|
||
//when, then | ||
mockMvc.perform(get("/teams")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.data[0].name").value("Team 1")) | ||
.andExpect(jsonPath("$.data[1].name").value("Team 2")) | ||
.andExpect(jsonPath("$.data[2].name").value("Team 3")); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/com/kboticketing/kboticketing/service/TeamServiceTest.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,45 @@ | ||
package com.kboticketing.kboticketing.service; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
import com.kboticketing.kboticketing.dao.TeamMapper; | ||
import com.kboticketing.kboticketing.domain.Team; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
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; | ||
|
||
/** | ||
* @author hazel | ||
*/ | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class TeamServiceTest { | ||
|
||
@Mock | ||
private TeamMapper teamMapper; | ||
|
||
@InjectMocks | ||
private TeamService teamService; | ||
|
||
@Test | ||
@DisplayName("[SUCCESS] 팀 리스트 테스트") | ||
public void getTeamsTest() { | ||
|
||
//given | ||
List<Team> fakeTeams = Arrays.asList( | ||
new Team(1, "Team 1"), | ||
new Team(2, "Team 2"), | ||
new Team(3, "Team 3") | ||
); | ||
given(teamMapper.selectTeams()).willReturn(fakeTeams); | ||
|
||
//when, then | ||
assertThat(teamService.getTeams()).isEqualTo(fakeTeams); | ||
} | ||
} |