-
Notifications
You must be signed in to change notification settings - Fork 1
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] 여행후기 기본 구현 완료 #39
Changes from all commits
8eeeaea
a336fcb
762d733
312171d
ba7106d
516c7c6
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,83 @@ | ||
package com.haejwo.tripcometrue.domain.triprecord.controller; | ||
|
||
import com.haejwo.tripcometrue.domain.triprecord.dto.request.TripRecordRequestDto; | ||
import com.haejwo.tripcometrue.domain.triprecord.dto.response.TripRecordResponseDto; | ||
import com.haejwo.tripcometrue.domain.triprecord.service.TripRecordService; | ||
import com.haejwo.tripcometrue.global.util.ResponseDTO; | ||
import lombok.RequiredArgsConstructor; | ||
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.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/v1/trip-record") | ||
@RequiredArgsConstructor | ||
public class TripRecordController { | ||
|
||
private final TripRecordService tripRecordService; | ||
|
||
@PostMapping | ||
public ResponseEntity<ResponseDTO<TripRecordResponseDto>> tripRecordAdd( | ||
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 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 commentThe reason will be displayed to describe this comment to others. Learn more. 아하 그렇군요! 제가 알기로도 정해진 건 없다고 들었습니다! 메소드명까지 굳이 통일할 필요가 없다면 재량껏 사용해도 될듯 해요. 다른 분들은 어떻게 생각하시는지 궁금하네요 ㅎㅎ |
||
@RequestBody TripRecordRequestDto requestDto | ||
) { | ||
|
||
TripRecordResponseDto responseDto = tripRecordService.addTripRecord(requestDto); | ||
ResponseDTO<TripRecordResponseDto> responseBody = ResponseDTO.okWithData(responseDto); | ||
|
||
return ResponseEntity | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. 이건 그냥 습관, 성향 차이로 알고 있습니다. |
||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
} | ||
|
||
@GetMapping("/{tripRecordId}") | ||
public ResponseEntity<ResponseDTO<TripRecordResponseDto>> tripRecordDetails( | ||
@PathVariable Long tripRecordId | ||
) { | ||
|
||
TripRecordResponseDto responseDto = tripRecordService.findTripRecord(tripRecordId); | ||
ResponseDTO<TripRecordResponseDto> responseBody = ResponseDTO.okWithData(responseDto); | ||
|
||
return ResponseEntity | ||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
} | ||
|
||
@PutMapping("/{tripRecordId}") | ||
public ResponseEntity<ResponseDTO<TripRecordResponseDto>> tripRecordModify( | ||
@PathVariable Long tripRecordId, | ||
@RequestBody TripRecordRequestDto requestDto | ||
) { | ||
|
||
TripRecordResponseDto responseDto = tripRecordService.modifyTripRecord(tripRecordId, requestDto); | ||
ResponseDTO<TripRecordResponseDto> responseBody = ResponseDTO.okWithData(responseDto); | ||
|
||
return ResponseEntity | ||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
|
||
} | ||
|
||
@DeleteMapping("/{tripRecordId}") | ||
public ResponseEntity<ResponseDTO> tripRecordRemove( | ||
@PathVariable Long tripRecordId | ||
) { | ||
|
||
tripRecordService.removeTripRecord(tripRecordId); | ||
ResponseDTO responseBody = ResponseDTO.ok(); | ||
|
||
return ResponseEntity | ||
.status(responseBody.getCode()) | ||
.body(responseBody); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.haejwo.tripcometrue.domain.triprecord.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.haejwo.tripcometrue.domain.triprecord.entity.ExpenseRangeType; | ||
import com.haejwo.tripcometrue.domain.triprecord.entity.TripRecord; | ||
import java.time.LocalDate; | ||
import lombok.Builder; | ||
|
||
public record TripRecordRequestDto( | ||
String title, | ||
String content, | ||
ExpenseRangeType expenseRangeType, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate tripStartDay, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate tripEndDay, | ||
String countries | ||
) { | ||
|
||
@Builder | ||
public TripRecordRequestDto(String title, String content, ExpenseRangeType expenseRangeType, | ||
LocalDate tripStartDay, LocalDate tripEndDay, String countries) { | ||
this.title = title; | ||
this.content = content; | ||
this.expenseRangeType = expenseRangeType; | ||
this.tripStartDay = tripStartDay; | ||
this.tripEndDay = tripEndDay; | ||
this.countries = countries; | ||
} | ||
|
||
public TripRecord toEntity() { | ||
return TripRecord.builder() | ||
.title(this.title) | ||
.content(this.content) | ||
.expenseRangeType(this.expenseRangeType) | ||
.tripStartDay(this.tripStartDay) | ||
.tripEndDay(this.tripEndDay) | ||
.countries(this.countries) | ||
.build(); | ||
} | ||
|
||
} |
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.
URL에 도메인을 어떻게 표시할지는 추후에 논의해서 통일하면 좋을듯 합니다 :)
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.
원래는 restful 기준에 따르면 소문자와 - _ 이 두개로 표현하는게 정석으로 알고 있습니다.