-
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.
Merge pull request #59 from TrainingDiary/feature/pt-contract-swagger
PT 계약 관련 API 수정
- Loading branch information
Showing
8 changed files
with
108 additions
and
118 deletions.
There are no files selected for viewing
72 changes: 44 additions & 28 deletions
72
src/main/java/com/project/trainingdiary/controller/PtContractController.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 |
---|---|---|
@@ -1,69 +1,85 @@ | ||
package com.project.trainingdiary.controller; | ||
|
||
import com.project.trainingdiary.dto.request.AddPtContractSessionRequestDto; | ||
import com.project.trainingdiary.dto.request.CreatePtContractRequestDto; | ||
import com.project.trainingdiary.dto.request.TerminatePtContractRequestDto; | ||
import com.project.trainingdiary.dto.response.CommonResponse; | ||
import com.project.trainingdiary.dto.response.CreatePtContractResponseDto; | ||
import com.project.trainingdiary.dto.response.PtContractResponseDto; | ||
import com.project.trainingdiary.model.PtContractSort; | ||
import com.project.trainingdiary.service.PtContractService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
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.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "6 - PT 계약") | ||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("api/pt-contracts") | ||
public class PtContractController { | ||
|
||
private final PtContractService ptContractService; | ||
|
||
@Operation( | ||
summary = "PT 계약을 생성", | ||
description = "트레이너가 트레이니와 PT 계약을 생성함" | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "성공"), | ||
@ApiResponse(responseCode = "409", description = "트레이너와 트레이니가 이미 계약이 있습니다.", content = @Content) | ||
}) | ||
@PreAuthorize("hasRole('TRAINER')") | ||
@PostMapping | ||
public CommonResponse<?> createPtContract( | ||
public ResponseEntity<CreatePtContractResponseDto> createPtContract( | ||
@RequestBody @Valid CreatePtContractRequestDto dto | ||
) { | ||
ptContractService.createPtContract(dto); | ||
return CommonResponse.created(); | ||
return ResponseEntity.ok(ptContractService.createPtContract(dto)); | ||
} | ||
|
||
@Operation( | ||
summary = "PT 계약 목록을 조회", | ||
description = "자신의 PT 계약 목록을 조회함" | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "성공") | ||
}) | ||
@GetMapping | ||
public CommonResponse<?> getPtContractList( | ||
Pageable pageable, | ||
public ResponseEntity<Page<PtContractResponseDto>> getPtContractList( | ||
@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(defaultValue = "20") int size, | ||
@RequestParam PtContractSort sortBy | ||
) { | ||
Page<PtContractResponseDto> ptContracts = ptContractService.getPtContractList(pageable, sortBy); | ||
return CommonResponse.success(ptContracts); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public CommonResponse<?> getPtContract( | ||
@PathVariable long id | ||
) { | ||
PtContractResponseDto ptContract = ptContractService.getPtContract(id); | ||
return CommonResponse.success(ptContract); | ||
} | ||
|
||
@PostMapping("/add-session") | ||
public CommonResponse<?> addPtContractSession( | ||
@RequestBody @Valid AddPtContractSessionRequestDto dto | ||
) { | ||
ptContractService.addPtContractSession(dto); | ||
return CommonResponse.success(); | ||
Pageable pageable = PageRequest.of(page, size); | ||
return ResponseEntity.ok(ptContractService.getPtContractList(pageable, sortBy)); | ||
} | ||
|
||
@Operation( | ||
summary = "PT 계약 종료", | ||
description = "트레이너가 PT 계약을 종료함" | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "성공"), | ||
@ApiResponse(responseCode = "404", description = "계약이 없습니다.") | ||
}) | ||
@PreAuthorize("hasRole('TRAINER')") | ||
@PostMapping("/terminate") | ||
public CommonResponse<?> terminatePtContract( | ||
public ResponseEntity<Void> terminatePtContract( | ||
@RequestBody @Valid TerminatePtContractRequestDto dto | ||
) { | ||
ptContractService.terminatePtContract(dto); | ||
return CommonResponse.success(); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
8 changes: 3 additions & 5 deletions
8
src/main/java/com/project/trainingdiary/dto/request/CreatePtContractRequestDto.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 |
---|---|---|
@@ -1,17 +1,15 @@ | ||
package com.project.trainingdiary.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.PositiveOrZero; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class CreatePtContractRequestDto { | ||
|
||
@NotNull(message = "traineeEmail를 입력하세요") | ||
@NotNull(message = "traineeEmail을 입력하세요") | ||
@Schema(example = "[email protected]") | ||
private String traineeEmail; | ||
|
||
@PositiveOrZero(message = "sessionCount는 0 이상이어야 합니다") | ||
private int sessionCount; | ||
} |
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/com/project/trainingdiary/dto/response/CreatePtContractResponseDto.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 com.project.trainingdiary.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class CreatePtContractResponseDto { | ||
|
||
@Schema(example = "1") | ||
private Long ptContractId; | ||
} |
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
Oops, something went wrong.