-
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.
Browse files
Browse the repository at this point in the history
#6 여행지 관련 기본기능 구현
- Loading branch information
Showing
16 changed files
with
563 additions
and
0 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
96 changes: 96 additions & 0 deletions
96
src/main/java/com/haejwo/tripcometrue/domain/place/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,96 @@ | ||
package com.haejwo.tripcometrue.domain.place.controller; | ||
|
||
import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDTO; | ||
import com.haejwo.tripcometrue.domain.place.dto.response.PlaceResponseDTO; | ||
import com.haejwo.tripcometrue.domain.place.service.PlaceService; | ||
import com.haejwo.tripcometrue.global.util.ResponseDTO; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/v1/places") | ||
@RequiredArgsConstructor | ||
public class PlaceController { | ||
|
||
private final PlaceService placeService; | ||
|
||
@PostMapping | ||
public ResponseEntity<ResponseDTO<PlaceResponseDTO>> placeAdd( | ||
@RequestBody PlaceRequestDTO requestDto | ||
) { | ||
|
||
PlaceResponseDTO responseDto = placeService.addPlace(requestDto); | ||
ResponseDTO<PlaceResponseDTO> responseBody = ResponseDTO.okWithData(responseDto); | ||
|
||
return ResponseEntity | ||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
} | ||
|
||
@GetMapping("/{placeId}") | ||
public ResponseEntity<ResponseDTO<PlaceResponseDTO>> placeDetails( | ||
@PathVariable Long placeId | ||
) { | ||
|
||
PlaceResponseDTO responseDto = placeService.findPlace(placeId); | ||
ResponseDTO<PlaceResponseDTO> responseBody = ResponseDTO.okWithData(responseDto); | ||
|
||
return ResponseEntity | ||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<ResponseDTO<Page<PlaceResponseDTO>>> placeList( | ||
Pageable pageable, | ||
@RequestParam Integer storedCount | ||
) { | ||
|
||
Page<PlaceResponseDTO> placePage = placeService.findPlaces(pageable, storedCount); | ||
|
||
ResponseDTO responseBody = ResponseDTO.okWithData(placePage); | ||
|
||
return ResponseEntity | ||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
} | ||
|
||
@PutMapping("/{placeId}") | ||
public ResponseEntity<ResponseDTO<PlaceResponseDTO>> placeModify( | ||
@PathVariable Long placeId, | ||
@RequestBody PlaceRequestDTO requestDto | ||
) { | ||
|
||
PlaceResponseDTO responseDto = placeService.modifyPlace(placeId, requestDto); | ||
ResponseDTO<PlaceResponseDTO> responseBody = ResponseDTO.okWithData(responseDto); | ||
|
||
return ResponseEntity | ||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
} | ||
|
||
@DeleteMapping("/{placeId}") | ||
public ResponseEntity<ResponseDTO> placeRemove( | ||
@PathVariable Long placeId | ||
) { | ||
|
||
placeService.removePlace(placeId); | ||
ResponseDTO responseBody = ResponseDTO.ok(); | ||
|
||
return ResponseEntity | ||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceControllerAdvice.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.haejwo.tripcometrue.domain.place.controller; | ||
|
||
import com.haejwo.tripcometrue.domain.place.exception.PlaceNotFoundException; | ||
import com.haejwo.tripcometrue.global.util.ResponseDTO; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class PlaceControllerAdvice { | ||
|
||
@ExceptionHandler(PlaceNotFoundException.class) | ||
public ResponseEntity<ResponseDTO<Void>> placeNotFoundExceptionHandler( | ||
PlaceNotFoundException e | ||
) { | ||
HttpStatus status = e.getErrorCode().getHttpStatus(); | ||
|
||
return ResponseEntity | ||
.status(status) | ||
.body(ResponseDTO.errorWithMessage(status, e.getMessage())); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/haejwo/tripcometrue/domain/place/dto/PlaceDto.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,38 @@ | ||
package com.haejwo.tripcometrue.domain.place.dto; | ||
|
||
import java.time.LocalTime; | ||
import lombok.Builder; | ||
|
||
public record PlaceDto( | ||
Long id, | ||
String name, | ||
String address, | ||
String description, | ||
LocalTime weekdayOpenTime, | ||
LocalTime weekdayCloseTime, | ||
LocalTime weekendOpenTime, | ||
LocalTime weekendCloseTime, | ||
Integer storedCount) { | ||
|
||
@Builder | ||
public PlaceDto( | ||
Long id, | ||
String name, | ||
String address, | ||
String description, | ||
LocalTime weekdayOpenTime, | ||
LocalTime weekdayCloseTime, | ||
LocalTime weekendOpenTime, | ||
LocalTime weekendCloseTime, | ||
Integer storedCount) { | ||
this.id = id; | ||
this.name = name; | ||
this.address = address; | ||
this.description = description; | ||
this.weekdayOpenTime = weekdayOpenTime; | ||
this.weekdayCloseTime = weekdayCloseTime; | ||
this.weekendOpenTime = weekendOpenTime; | ||
this.weekendCloseTime = weekendCloseTime; | ||
this.storedCount = storedCount; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/haejwo/tripcometrue/domain/place/dto/request/PlaceFilterRequestDTO.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.haejwo.tripcometrue.domain.place.dto.request; | ||
|
||
public record PlaceFilterRequestDTO( | ||
Integer stored_count, | ||
Integer storedCount | ||
) { | ||
|
||
// record는 Compact Constructor라는 기능있어, 생성자 내부의 변수에 대한 로직이 마지막으로 동작하여 변수 초기화를 한다. | ||
public PlaceFilterRequestDTO { | ||
storedCount = stored_count; | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/haejwo/tripcometrue/domain/place/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,57 @@ | ||
package com.haejwo.tripcometrue.domain.place.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.haejwo.tripcometrue.domain.place.entity.Place; | ||
import java.time.LocalTime; | ||
import lombok.Builder; | ||
|
||
public record PlaceRequestDTO( | ||
String name, | ||
String address, | ||
String description, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayOpenTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayCloseTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendOpenTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendCloseTime, | ||
Integer storedCount, | ||
Long cityId | ||
) { | ||
|
||
@Builder | ||
public PlaceRequestDTO( | ||
String name, | ||
String address, | ||
String description, | ||
LocalTime weekdayOpenTime, | ||
LocalTime weekdayCloseTime, | ||
LocalTime weekendOpenTime, | ||
LocalTime weekendCloseTime, | ||
Integer storedCount, | ||
Long cityId | ||
) { | ||
this.name = name; | ||
this.address = address; | ||
this.description = description; | ||
this.weekdayOpenTime = weekdayOpenTime; | ||
this.weekdayCloseTime = weekdayCloseTime; | ||
this.weekendOpenTime = weekendOpenTime; | ||
this.weekendCloseTime = weekendCloseTime; | ||
this.storedCount = storedCount; | ||
this.cityId = cityId; | ||
} | ||
|
||
public Place toEntity() { | ||
return Place.builder() | ||
.name(this.name) | ||
.address(this.address) | ||
.description(this.description) | ||
.weekdayOpenTime(this.weekdayOpenTime) | ||
.weekdayCloseTime(this.weekdayCloseTime) | ||
.weekendOpenTime(this.weekendOpenTime) | ||
.weekendCloseTime(this.weekendCloseTime) | ||
.storedCount(this.storedCount) | ||
.cityId(this.cityId) | ||
.build(); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/haejwo/tripcometrue/domain/place/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,60 @@ | ||
package com.haejwo.tripcometrue.domain.place.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.haejwo.tripcometrue.domain.place.entity.Place; | ||
import java.time.LocalTime; | ||
import lombok.Builder; | ||
public record PlaceResponseDTO( | ||
Long id, | ||
String name, | ||
String address, | ||
String description, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayOpenTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayCloseTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendOpenTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendCloseTime, | ||
Integer storedCount, | ||
Long cityId | ||
) { | ||
|
||
@Builder | ||
public PlaceResponseDTO( | ||
Long id, | ||
String name, | ||
String address, | ||
String description, | ||
LocalTime weekdayOpenTime, | ||
LocalTime weekdayCloseTime, | ||
LocalTime weekendOpenTime, | ||
LocalTime weekendCloseTime, | ||
Integer storedCount, | ||
Long cityId | ||
) { | ||
this.id = id; | ||
this.name = name; | ||
this.address = address; | ||
this.description = description; | ||
this.weekdayOpenTime = weekdayOpenTime; | ||
this.weekdayCloseTime = weekdayCloseTime; | ||
this.weekendOpenTime = weekendOpenTime; | ||
this.weekendCloseTime = weekendCloseTime; | ||
this.storedCount = storedCount; | ||
this.cityId = cityId; | ||
} | ||
|
||
public static PlaceResponseDTO fromEntity(Place entity) { | ||
return PlaceResponseDTO.builder() | ||
.id(entity.getId()) | ||
.name(entity.getName()) | ||
.address(entity.getAddress()) | ||
.description(entity.getDescription()) | ||
.weekdayOpenTime(entity.getWeekdayOpenTime()) | ||
.weekdayCloseTime(entity.getWeekdayCloseTime()) | ||
.weekendOpenTime(entity.getWeekendOpenTime()) | ||
.weekendCloseTime(entity.getWeekendCloseTime()) | ||
.storedCount(entity.getStoredCount()) | ||
.cityId(entity.getCityId()) | ||
.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.