-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
228 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/catspot/studyplace/StudyPlaceController.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,28 @@ | ||
package com.catspot.studyplace; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@AllArgsConstructor | ||
public class StudyPlaceController { | ||
private final StudyPlaceRepository studyPlaceRepository; | ||
|
||
@GetMapping("/study-seat") | ||
public StudyPlaceResponse getAllStudyPlaces() { | ||
List<StudyPlace> allStudyPlaces = studyPlaceRepository.findAll(); | ||
List<StudyPlaceDto> studyPlaceDtos = new ArrayList<>(); | ||
|
||
for (StudyPlace studyPlace : allStudyPlaces) { | ||
StudyPlaceDto dto = StudyPlaceMapper.INSTANCE.studyPlaceToStudyPlaceDto(studyPlace); | ||
studyPlaceDtos.add(dto); | ||
} | ||
|
||
return StudyPlaceResponse.builder().data(studyPlaceDtos).build(); | ||
} | ||
} |
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.catspot.studyplace; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class StudyPlaceDto { | ||
private Long placeIdx; | ||
private String placeName; | ||
private String url; | ||
private Integer allSeats; | ||
private Integer useSeats; | ||
private Integer restSeats; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/catspot/studyplace/StudyPlaceMapper.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,13 @@ | ||
package com.catspot.studyplace; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface StudyPlaceMapper { | ||
|
||
StudyPlaceMapper INSTANCE = Mappers.getMapper(StudyPlaceMapper.class); | ||
|
||
StudyPlaceDto studyPlaceToStudyPlaceDto(StudyPlace studyPlace); | ||
} |
2 changes: 1 addition & 1 deletion
2
...catspot/crawler/StudyPlaceRepository.java → ...spot/studyplace/StudyPlaceRepository.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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/catspot/studyplace/StudyPlaceResponse.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,13 @@ | ||
package com.catspot.studyplace; | ||
|
||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@Builder | ||
public class StudyPlaceResponse { | ||
private List<StudyPlaceDto> data; | ||
} |
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
51 changes: 51 additions & 0 deletions
51
src/test/java/com/catspot/studyplace/StudyPlaceControllerTest.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,51 @@ | ||
package com.catspot.studyplace; | ||
|
||
import static org.mockito.Mockito.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
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; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
@WebMvcTest(StudyPlaceController.class) | ||
public class StudyPlaceControllerTest { | ||
@MockBean | ||
private StudyPlaceRepository studyPlaceRepository; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
void 열람실_데이터_조회() throws Exception { | ||
// given | ||
List<StudyPlace> response = studyPlaceResponse(); | ||
doReturn(response).when(studyPlaceRepository).findAll(); | ||
|
||
// then | ||
ResultActions resultActions = mockMvc.perform( | ||
MockMvcRequestBuilders.get("/api/study-seat")) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
private List<StudyPlace> studyPlaceResponse() { | ||
List<StudyPlace> response = new ArrayList<StudyPlace>(); | ||
for (int i = 0; i < 5; i++) { | ||
StudyPlace studyPlace = StudyPlace.builder() | ||
.placeIdx((long) i) | ||
.placeName("열람실A") | ||
.url("https://열람실A.com") | ||
.allSeats(100) | ||
.useSeats(10) | ||
.restSeats(90) | ||
.build(); | ||
response.add(studyPlace); | ||
} | ||
return response; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/com/catspot/studyplace/StudyPlaceDtoTest.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,20 @@ | ||
package com.catspot.studyplace; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class StudyPlaceDtoTest { | ||
@Test | ||
public void DTO_생성_테스트() { | ||
StudyPlaceDto dto = StudyPlaceDto.builder() | ||
.placeIdx(1L) | ||
.placeName("1") | ||
.url("url") | ||
.allSeats(10) | ||
.useSeats(2) | ||
.restSeats(8) | ||
.build(); | ||
|
||
Assertions.assertEquals(dto.getPlaceIdx(), 1); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/com/catspot/studyplace/StudyPlaceMapperTest.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,43 @@ | ||
package com.catspot.studyplace; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class StudyPlaceMapperTest { | ||
@Test | ||
public void DTO_매핑_테스트() { | ||
StudyPlace studyPlace = getStudyPlace(); | ||
|
||
StudyPlaceDto studyPlaceDto = StudyPlaceMapper.INSTANCE.studyPlaceToStudyPlaceDto(studyPlace); | ||
|
||
assertNotNull(studyPlaceDto); | ||
assertEquals(studyPlaceDto.getPlaceIdx(), studyPlace.getPlaceIdx()); | ||
assertEquals(studyPlaceDto.getPlaceName(), studyPlace.getPlaceName()); | ||
assertEquals(studyPlaceDto.getUrl(), studyPlace.getUrl()); | ||
assertEquals(studyPlaceDto.getAllSeats(), studyPlace.getAllSeats()); | ||
assertEquals(studyPlaceDto.getUseSeats(), studyPlace.getUseSeats()); | ||
assertEquals(studyPlaceDto.getRestSeats(), studyPlace.getRestSeats()); | ||
} | ||
|
||
@Test | ||
public void DTO_null_매핑_테스트() { | ||
StudyPlace studyPlace = null; | ||
|
||
StudyPlaceDto studyPlaceDto = StudyPlaceMapper.INSTANCE.studyPlaceToStudyPlaceDto(studyPlace); | ||
|
||
assertNull(studyPlaceDto); | ||
} | ||
|
||
private StudyPlace getStudyPlace() { | ||
StudyPlace studyPlace = StudyPlace.builder() | ||
.placeIdx(1L) | ||
.placeName("1") | ||
.url("url") | ||
.allSeats(10) | ||
.useSeats(2) | ||
.restSeats(8) | ||
.build(); | ||
return studyPlace; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...pot/crawler/StudyPlaceRepositoryTest.java → .../studyplace/StudyPlaceRepositoryTest.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
35 changes: 35 additions & 0 deletions
35
src/test/java/com/catspot/studyplace/StudyPlaceResponseTest.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,35 @@ | ||
package com.catspot.studyplace; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class StudyPlaceResponseTest { | ||
@Test | ||
void 열람실_응답클래스_생성() { | ||
List<StudyPlaceDto> studyPlaces = studyPlaceResponse(); | ||
StudyPlaceResponse studyPlaceResponse = new StudyPlaceResponse(studyPlaces); | ||
|
||
assertFalse(studyPlaceResponse.getData().isEmpty()); | ||
} | ||
|
||
private List<StudyPlaceDto> studyPlaceResponse() { | ||
List<StudyPlaceDto> response = new ArrayList<>(); | ||
for (int i = 0; i < 5; i++) { | ||
StudyPlaceDto studyPlaceDto = StudyPlaceDto.builder() | ||
.placeIdx((long) i) | ||
.placeName("열람실A") | ||
.url("https://열람실A.com") | ||
.allSeats(100) | ||
.useSeats(10) | ||
.restSeats(90) | ||
.build(); | ||
|
||
response.add(studyPlaceDto); | ||
} | ||
return response; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/com/catspot/crawler/StudyPlaceTest.java → ...om/catspot/studyplace/StudyPlaceTest.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