-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: 백신 도메인 리펙토링 #230
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
Changes from 19 commits
2a8be2c
fa2ce91
7b7500f
1639886
83a61a5
b532571
b5ec7cd
059dc77
5e99212
a08b320
3074e83
d3341a1
570ff58
6755d20
9d1b15c
efc9328
522f719
7cd744e
525f7d6
5c8499c
ad1f8ec
10a592a
70dbed7
512e31e
2e9f2e3
6107a6a
5ecc46e
392a4ea
6a7272e
c8b94a1
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 |
|---|---|---|
|
|
@@ -2,14 +2,18 @@ | |
|
|
||
| import com.kau.capstone.entity.pet.Pet; | ||
| import com.kau.capstone.entity.vaccination.Vaccination; | ||
| import com.kau.capstone.v2.vaccination.exception.VaccinationNotFoundExceptionV2; | ||
| import lombok.NonNull; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface VaccinationRepository extends JpaRepository<Vaccination, Long> { | ||
|
|
||
| @Query("SELECT v FROM Vaccination v WHERE v.pet = :pet ORDER BY v.timeYear DESC, v.timeMonth DESC, v.timeDay DESC") | ||
| List<Vaccination> findAllByMemberAndPet(@Param("pet") Pet pet); | ||
| List<Vaccination> findAllByPetOrderByVaccinatedAtDesc(@Param("pet") Pet pet); | ||
|
|
||
| default @NonNull Vaccination getById(@NonNull Long id) { | ||
| return findById(id).orElseThrow(VaccinationNotFoundExceptionV2::new); | ||
|
Contributor
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. @NotNull을 사용하는 이유가 따로 있나요?
Collaborator
Author
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. interface 구현에 따라서, validation 적용 |
||
| } | ||
| } | ||
|
Collaborator
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. build() 빼도 될 것 같습니다
Collaborator
Author
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. v1은 수정하지 않았습니다. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ public class VaccinationController implements VaccinationApi { | |
| public ResponseEntity<Void> createVaccinationInfoForPet(@LoginUser LoginInfo loginInfo, | ||
| @PathVariable Long petId, | ||
| @RequestBody CreateVaccinationRequest request) { | ||
| vaccinationService.createVaccinationInfo(loginInfo.memberId(), petId, request); | ||
| vaccinationService.createVaccinationInfo(petId, request); | ||
|
Contributor
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. 왜 제대로된 LoginInfo인지 확인은 안해주나요,,
Collaborator
Author
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. 반영했어요 |
||
|
|
||
| return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
| } | ||
|
|
||
|
Collaborator
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. 생성자 of로 통일하기로 하지 않았나요?
Collaborator
Author
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. v1은 수정하지 않았습니다. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,12 @@ | ||
| package com.kau.capstone.v1.vaccination.dto; | ||
|
|
||
| import com.kau.capstone.entity.pet.Pet; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record PetVaccinationResponse( | ||
| String name | ||
| ) { | ||
|
|
||
| public static PetVaccinationResponse toResponse(Pet pet) { | ||
| return PetVaccinationResponse.builder() | ||
| .name(pet.getName()) | ||
| .build(); | ||
| return new PetVaccinationResponse(pet.getName()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.kau.capstone.v2.vaccination.controller; | ||
|
|
||
| import com.kau.capstone._core.dto.ApiResponse; | ||
| import com.kau.capstone.v1.auth.dto.LoginInfo; | ||
| import com.kau.capstone.v1.auth.util.LoginUser; | ||
| import com.kau.capstone.v2.vaccination.dto.CreateVaccinationReqV2; | ||
| import com.kau.capstone.v2.vaccination.dto.PutVaccinationReqV2; | ||
| import com.kau.capstone.v2.vaccination.dto.VaccinationsResV2; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 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; | ||
|
|
||
| @Tag(name = "보건정보 API") | ||
| public interface VaccinationApiV2 { | ||
|
|
||
| @Operation(summary = "보건정보 등록 v2", description = "반려견의 보건정보를 등록하는 기능입니다.") | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "201", | ||
| description = "보건정보 등록 성공" | ||
| ) | ||
| @PostMapping("/api/v2/pets/{petId}/vaccination") | ||
| ResponseEntity<ApiResponse<Void>> createVaccinationInfoForPet( | ||
| @Parameter(description = "로그인 정보") @LoginUser LoginInfo loginInfo, | ||
| @Parameter(description = "반려동물 ID") @PathVariable Long petId, | ||
| @Parameter(description = "보건정보 관련 이름, 접종시기") @RequestBody CreateVaccinationReqV2 request | ||
| ); | ||
|
|
||
| @Operation(summary = "반려동물 보건정보 목록 조회 v2", description = "반려견에게 등록된 보건정보 목록입니다.") | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "200", | ||
| description = "보건정보 목록 조회 성공", | ||
| content = @Content(schema = @Schema(implementation = VaccinationsResV2.class)) | ||
| ) | ||
| @GetMapping("/api/v2/pets/{petId}/vaccination") | ||
| ResponseEntity<ApiResponse<VaccinationsResV2>> getVaccinationInfoForPet( | ||
| @Parameter(description = "반려동물 ID") @PathVariable Long petId | ||
| ); | ||
|
|
||
| @Operation(summary = "보건정보 수정 v2", description = "반려견에게 등록된 보건정보를 수정하는 기능입니다.") | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "200", | ||
| description = "보건정보 수정 성공" | ||
| ) | ||
| @PutMapping("/api/v2/pets/{petId}/vaccination/{vaccinationId}") | ||
| ResponseEntity<ApiResponse<Void>> putVaccinationInfoForPet( | ||
| @Parameter(description = "로그인 정보") @LoginUser LoginInfo loginInfo, | ||
| @Parameter(description = "반려동물 ID") @PathVariable Long petId, | ||
| @Parameter(description = "보건정보 ID") @PathVariable Long vaccinationId, | ||
| @Parameter(description = "수정할 보건정보 관련 이름, 접종시기") @RequestBody PutVaccinationReqV2 request | ||
| ); | ||
|
|
||
| @Operation(summary = "보건정보 삭제 v2", description = "반려견에게 등록된 보건정보를 삭제하는 기능입니다.") | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "200", | ||
| description = "보건정보 삭제 성공" | ||
| ) | ||
| @DeleteMapping("/api/v2/pets/{petId}/vaccination/{vaccinationId}") | ||
| ResponseEntity<ApiResponse<Void>> deleteVaccinationInfoForPet( | ||
| @Parameter(description = "로그인 정보") @LoginUser LoginInfo loginInfo, | ||
| @Parameter(description = "반려동물 ID") @PathVariable Long petId, | ||
| @Parameter(description = "보건정보 ID") @PathVariable Long vaccinationId | ||
| ); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.kau.capstone.v2.vaccination.controller; | ||
|
|
||
| import com.kau.capstone._core.dto.ApiResponse; | ||
| import com.kau.capstone.v1.auth.dto.LoginInfo; | ||
| import com.kau.capstone.v1.auth.util.LoginUser; | ||
| import com.kau.capstone.v2.vaccination.dto.CreateVaccinationReqV2; | ||
| import com.kau.capstone.v2.vaccination.dto.PutVaccinationReqV2; | ||
| import com.kau.capstone.v2.vaccination.dto.VaccinationsResV2; | ||
| import com.kau.capstone.v2.vaccination.service.VaccinationServiceV2; | ||
| 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.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class VaccinationControllerV2 implements VaccinationApiV2 { | ||
|
|
||
| private final VaccinationServiceV2 vaccinationService; | ||
|
|
||
| @PostMapping("/api/v2/pets/{petId}/vaccination") | ||
| public ResponseEntity<ApiResponse<Void>> createVaccinationInfoForPet( | ||
| @LoginUser LoginInfo loginInfo, | ||
| @PathVariable Long petId, | ||
| @RequestBody CreateVaccinationReqV2 request | ||
| ) { | ||
| vaccinationService.createVaccinationInfo(petId, request); | ||
| return ApiResponse.create(); | ||
| } | ||
|
|
||
| @GetMapping("/api/v2/pets/{petId}/vaccination") | ||
| public ResponseEntity<ApiResponse<VaccinationsResV2>> getVaccinationInfoForPet( | ||
| @PathVariable Long petId | ||
| ) { | ||
| VaccinationsResV2 response = vaccinationService.getVaccinationInfo(petId); | ||
| return ApiResponse.ok(response); | ||
| } | ||
|
|
||
| @PutMapping("/api/v2/pets/{petId}/vaccination/{vaccinationId}") | ||
| public ResponseEntity<ApiResponse<Void>> putVaccinationInfoForPet( | ||
| @LoginUser LoginInfo loginInfo, | ||
| @PathVariable Long petId, | ||
| @PathVariable Long vaccinationId, | ||
| @RequestBody PutVaccinationReqV2 request | ||
| ) { | ||
| vaccinationService.putVaccinationInfo(vaccinationId, request); | ||
| return ApiResponse.ok(); | ||
| } | ||
|
|
||
| @DeleteMapping("/api/v2/pets/{petId}/vaccination/{vaccinationId}") | ||
| public ResponseEntity<ApiResponse<Void>> deleteVaccinationInfoForPet( | ||
| @LoginUser LoginInfo loginInfo, | ||
| @PathVariable Long petId, | ||
| @PathVariable Long vaccinationId | ||
| ) { | ||
| vaccinationService.deleteVaccinationInfo(vaccinationId); | ||
| return ApiResponse.ok(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.kau.capstone.v2.vaccination.dto; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| public record CreateVaccinationReqV2( | ||
| String name, | ||
| LocalDate vaccinatedAt | ||
| ) { | ||
|
|
||
| } |
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.
@query 부분 삭제했는데 @param은 왜 남아있는건가요?
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.
반영했어요