-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: 지역으로 공간리스트 조회 구현
- Loading branch information
Showing
9 changed files
with
131 additions
and
5 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
26 changes: 26 additions & 0 deletions
26
src/main/java/org/sophy/sophy/controller/PlaceController.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 org.sophy.sophy.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sophy.sophy.common.dto.ApiResponseDto; | ||
import org.sophy.sophy.controller.dto.request.PlaceRequestDto; | ||
import org.sophy.sophy.controller.dto.response.PlaceResponseDto; | ||
import org.sophy.sophy.exception.SuccessStatus; | ||
import org.sophy.sophy.service.PlaceService; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/place") | ||
public class PlaceController { | ||
private final PlaceService placeService; | ||
|
||
@GetMapping | ||
public ApiResponseDto<List<PlaceResponseDto>> getPlacesByCity(@RequestBody PlaceRequestDto placeRequestDto) { | ||
return ApiResponseDto.success(SuccessStatus.GET_PLACES_BY_CITY_SUCCESS, placeService.getPlacesByCity(placeRequestDto)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/sophy/sophy/controller/dto/request/PlaceRequestDto.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,9 @@ | ||
package org.sophy.sophy.controller.dto.request; | ||
|
||
import lombok.Getter; | ||
import org.sophy.sophy.domain.City; | ||
|
||
@Getter | ||
public class PlaceRequestDto { | ||
private City city; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/sophy/sophy/controller/dto/response/PlaceResponseDto.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,24 @@ | ||
package org.sophy.sophy.controller.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.sophy.sophy.domain.Place; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PlaceResponseDto { | ||
private Long placeId; | ||
private String placeImage; | ||
private String name; | ||
private String address; | ||
private Integer maximum; | ||
|
||
public static PlaceResponseDto of(Place place) { | ||
return new PlaceResponseDto( | ||
place.getId(), | ||
place.getPlaceImage(), | ||
place.getName(), | ||
place.getAddress(), | ||
place.getMaximum()); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/java/org/sophy/sophy/infrastructure/PlaceRepository.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 org.sophy.sophy.infrastructure; | ||
|
||
import org.sophy.sophy.domain.City; | ||
import org.sophy.sophy.domain.Place; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface PlaceRepository extends JpaRepository<Place, Long> { | ||
List<Place> findAllByCity(City city); | ||
|
||
List<Place> findAll(); | ||
} |
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 @@ | ||
package org.sophy.sophy.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sophy.sophy.controller.dto.request.PlaceRequestDto; | ||
import org.sophy.sophy.controller.dto.response.PlaceResponseDto; | ||
import org.sophy.sophy.domain.City; | ||
import org.sophy.sophy.infrastructure.PlaceRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PlaceService { | ||
private final PlaceRepository placeRepository; | ||
|
||
public List<PlaceResponseDto> getPlacesByCity(PlaceRequestDto placeRequestDto) { | ||
City city = placeRequestDto.getCity(); | ||
//의정부 시이면 전체 조회 | ||
if (city == City.UIJEONGBU_SI) { | ||
return placeRepository.findAll().stream() | ||
.map(PlaceResponseDto::of) | ||
.collect(Collectors.toList()); | ||
} | ||
return placeRepository.findAllByCity(city).stream() | ||
.map(PlaceResponseDto::of) | ||
.collect(Collectors.toList()); | ||
} | ||
} |