-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 스포츠 전체 조회 기능 구현 #105
Changes from 9 commits
7d863d1
411aa4f
dc3ba5a
129d737
d4d3457
36edd8d
9e85df8
96aad43
135c2a9
efc19c1
f2c8a4f
c5fc90f
ae2e239
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sports.server.query.application; | ||
|
||
import com.sports.server.query.dto.response.SportResponse; | ||
import com.sports.server.query.repository.SportQueryRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class SportQueryService { | ||
|
||
private final SportQueryRepository sportQueryRepository; | ||
|
||
public List<SportResponse> findAll() { | ||
return sportQueryRepository.findAll().stream().map(SportResponse::new).toList(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.sports.server.query.dto.response; | ||
|
||
import com.sports.server.command.sport.domain.Sport; | ||
|
||
public record SportResponse( | ||
Long id, | ||
String name | ||
|
||
) { | ||
public SportResponse(Sport sport) { | ||
this( | ||
sport.getId(), | ||
sport.getName() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.sports.server.query.presentation; | ||
|
||
import com.sports.server.query.application.SportQueryService; | ||
import com.sports.server.query.dto.response.SportResponse; | ||
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.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/sports" ) | ||
public class SportQueryController { | ||
|
||
private final SportQueryService sportQueryService; | ||
|
||
@GetMapping | ||
public ResponseEntity<List<SportResponse>> findAll() { | ||
return ResponseEntity.ok(sportQueryService.findAll()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.sports.server.query.repository; | ||
|
||
import com.sports.server.command.sport.domain.Sport; | ||
import java.util.List; | ||
import org.springframework.data.repository.Repository; | ||
|
||
public interface SportQueryRepository extends Repository<Sport, Long> { | ||
List<Sport> findAll(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.sports.server.query.acceptance; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import com.sports.server.query.dto.response.SportResponse; | ||
import com.sports.server.support.AcceptanceTest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
@Sql("/game-fixture.sql") | ||
public class SportQueryAcceptanceTest extends AcceptanceTest { | ||
|
||
@Test | ||
void 모든_종목을_조회한다() { | ||
|
||
// when | ||
ExtractableResponse<Response> response = RestAssured.given().log().all() | ||
.when() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.get("/sports") | ||
.then().log().all() | ||
.extract(); | ||
|
||
// then | ||
List<SportResponse> actual = toResponses(response, SportResponse.class); | ||
assertAll( | ||
() -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()), | ||
() -> assertThat(actual) | ||
.map(SportResponse::id) | ||
.containsExactly(1L, 2L), | ||
() -> assertThat(actual) | ||
.map(SportResponse::name) | ||
.containsExactly("농구", "루미큐브")); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.sports.server.query.presentation; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.sports.server.query.dto.response.SportResponse; | ||
import com.sports.server.support.DocumentationTest; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.restdocs.payload.JsonFieldType; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
public class SportQueryControllerTest extends DocumentationTest { | ||
|
||
@Test | ||
void 종목을_전체_조회한다() throws Exception { | ||
|
||
// given | ||
List<SportResponse> responses = List.of( | ||
new SportResponse(1L, "농구"), | ||
new SportResponse(2L, "루미큐브") | ||
); | ||
|
||
given(sportQueryService.findAll()) | ||
.willReturn(responses); | ||
|
||
// when | ||
ResultActions result = mockMvc.perform(get("/sports") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
); | ||
|
||
// then | ||
result.andExpect((status().isOk())) | ||
.andDo(restDocsHandler.document( | ||
responseFields( | ||
fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("종목의 ID"), | ||
fieldWithPath("[].name").type(JsonFieldType.STRING).description("종목의 이름") | ||
) | ||
)); | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.sports.server.support; | ||
|
||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; | ||
import org.springframework.restdocs.operation.preprocess.OperationRequestPreprocessor; | ||
|
||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; | ||
|
||
@TestConfiguration | ||
public class RestDocsConfig { | ||
|
||
private static final OperationRequestPreprocessor HOST_INFO = preprocessRequest(modifyUris() | ||
.scheme("https" ) | ||
.host("www.api.hufstreaming.site" ) | ||
.removePort(), prettyPrint() | ||
); | ||
|
||
@Bean | ||
public RestDocumentationResultHandler restDocsMockMvcConfigurationCustomizer() { | ||
return MockMvcRestDocumentation.document( | ||
"{class-name}/{method-name}", | ||
HOST_INFO, | ||
preprocessResponse(prettyPrint()) | ||
); | ||
} | ||
} | ||
Comment on lines
+11
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위처럼 RestDocumentationResultHandler를 빈으로 등록하고 사용할 곳에서 주입 받아서 사용하면 문서들이 생겨나네요. 저도 정확한 오류 원인은 잘 모르겠지만 빈으로 등록해야 완전하게 동작하나봅니다 @Autowired
protected RestDocumentationResultHandler restDocsHandler; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그때는 되고 지금은 안된다니 . . 당혹스럽네요 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스포츠, 종목에 대한 코멘트는 여기다가 남길게요. 확실히 영어이름은 Sport인데 한글로는 스포츠 또는 종목으로 혼용하고 있네요. 축구, 농구 등을 생각했을 땐 스포츠가 적절해보이지만 루미큐브 같은 경우는 스포츠라 볼 수 있는지 애매하긴 하네요.
종목이 더 포괄적인 의미를 담고 있는 것 같긴한데 용어 통일을 해야한다면 현재로서는 스포츠가 더 적절한것 같긴해요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 확인했습니당
스포츠로 용어 통일하도록 할게요!