Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2a8be2c
fix: 오타수정
parkhs21 Mar 1, 2025
fa2ce91
refactor: 각각의 년월일에서 LocalDate 형태로 변경
parkhs21 Mar 1, 2025
7b7500f
refactor: entity 빌더패턴 제거
parkhs21 Mar 1, 2025
1639886
refactor: DTO에서의 builder 패턴 제거
parkhs21 Mar 1, 2025
83a61a5
refactor: vaccination entity & member 연관관계 제거(pet은 존재)
parkhs21 Mar 4, 2025
b532571
feat: create vaccination v2 작성
parkhs21 Mar 4, 2025
b5ec7cd
feat: delete vaccination v2 작성
parkhs21 Mar 4, 2025
059dc77
feat: put vaccination v2 작성
parkhs21 Mar 4, 2025
5e99212
feat: get vaccinations v2 작성
parkhs21 Mar 4, 2025
a08b320
rename: dto 파일명 컨벤션 적용
parkhs21 Mar 4, 2025
3074e83
test: v2 api 테스트 적용
parkhs21 Mar 4, 2025
d3341a1
refactor: error message 변경
parkhs21 Mar 4, 2025
570ff58
feat: read only transactional 적용
parkhs21 Mar 4, 2025
6755d20
refactor: 불필요 native query 제거
parkhs21 Mar 5, 2025
9d1b15c
Merge pull request #217 from KAU-SMART-PETS/refactor/#216_vaccination…
2dhhh Mar 10, 2025
efc9328
Merge branch 'refactor/#215_vaccination' into feat/#218_vaccination_v2
parkhs21 Mar 10, 2025
522f719
Merge pull request #219 from KAU-SMART-PETS/feat/#218_vaccination_v2
2dhhh Mar 10, 2025
7cd744e
Merge branch 'develop' into refactor/#215_vaccination
parkhs21 Mar 12, 2025
525f7d6
rename: v2 폴더 구조에 따른 이동
parkhs21 Mar 12, 2025
5c8499c
refactor: @Query 삭제에 따른, @Param 삭제
parkhs21 Mar 22, 2025
ad1f8ec
refactor: @Query 삭제에 따른, @Param 삭제
parkhs21 Mar 22, 2025
10a592a
Merge remote-tracking branch 'origin/refactor/#215_vaccination' into …
parkhs21 Mar 22, 2025
70dbed7
feat: v1용 deprecated 선언
parkhs21 Mar 22, 2025
512e31e
fix: pet에 대해 member의 권한 여부 확인(Controller 수정)
parkhs21 Apr 17, 2025
2e9f2e3
fix: PetNotFoundExceptionV2 미반영 내용 적용
parkhs21 Apr 30, 2025
6107a6a
fix: getById @NonNull 적용
parkhs21 Apr 30, 2025
5ecc46e
fix: VaccinationServiceV2에서 LoginInfo로 Pet 정보 미확인 내용 정정
parkhs21 Apr 30, 2025
392a4ea
fix: PetRepository의 getByIdAndMemberAndDeletedAtIsNull 이름 변경에 따른 PetS…
parkhs21 Apr 30, 2025
6a7272e
test: VaccinationControllerV2 관련 테스트 수정
parkhs21 Apr 30, 2025
c8b94a1
Merge branch 'develop' into refactor/#215_vaccination
parkhs21 Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 37 additions & 22 deletions src/main/java/com/kau/capstone/entity/vaccination/Vaccination.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package com.kau.capstone.entity.vaccination;

import com.kau.capstone.entity.member.Member;
import com.kau.capstone.entity.pet.Pet;
import com.kau.capstone.v1.vaccination.dto.CreateVaccinationRequest;
import com.kau.capstone.v2.vaccination.dto.CreateVaccinationReqV2;
import com.kau.capstone.v1.vaccination.dto.PutVaccinationRequest;
import com.kau.capstone.v2.vaccination.dto.PutVaccinationReqV2;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;

import java.time.LocalDate;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Vaccination {

Expand All @@ -27,32 +28,46 @@ public class Vaccination {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@Comment("사용자 연결")
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne
@Comment("반려동물 연결")
@JoinColumn(name = "pet_id")
private Pet pet;

@Comment("예바접종 이름")
@Comment("예방접종 이름")
private String name;

@Comment("연도")
private Integer timeYear;
@Comment("접종시기")
private LocalDate vaccinatedAt;

@Comment("월")
private Integer timeMonth;
private Vaccination(Pet pet, String name, LocalDate vaccinatedAt) {
this.pet = pet;
this.name = name;
this.vaccinatedAt = vaccinatedAt;
}

@Comment("일")
private Integer timeDay;
public static Vaccination of(Pet pet, CreateVaccinationRequest request) {
return new Vaccination(
pet,
request.name(),
LocalDate.of(request.year(), request.month(), request.day())
);
}

public void modify(String name, Integer year, Integer month, Integer day) {
this.name = name;
this.timeYear = year;
this.timeMonth = month;
this.timeDay = day;
public static Vaccination of(Pet pet, CreateVaccinationReqV2 request) {
return new Vaccination(
pet,
request.name(),
request.vaccinatedAt()
);
}

public void modify(PutVaccinationRequest request) {
this.name = request.name();
this.vaccinatedAt = LocalDate.of(request.year(), request.month(), request.day());
}

public void modify(PutVaccinationReqV2 request) {
this.name = request.name();
this.vaccinatedAt = request.vaccinatedAt();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@query 부분 삭제했는데 @param은 왜 남아있는건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했어요


default @NonNull Vaccination getById(@NonNull Long id) {
return findById(id).orElseThrow(VaccinationNotFoundExceptionV2::new);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NotNull을 사용하는 이유가 따로 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interface 구현에 따라서, validation 적용

}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build() 빼도 될 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1은 수정하지 않았습니다.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 제대로된 LoginInfo인지 확인은 안해주나요,,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했어요


return ResponseEntity.status(HttpStatus.CREATED).build();
}
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생성자 of로 통일하기로 하지 않았나요?
혹시 준희님 코드에 맞춰서 저렇게 일부로 수정하신건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1은 수정하지 않았습니다.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.kau.capstone.v1.vaccination.dto;

import com.kau.capstone.entity.vaccination.Vaccination;
import lombok.Builder;

@Builder
public record OneVaccinationResponse(
Long id,
String name,
Expand All @@ -13,12 +11,12 @@ public record OneVaccinationResponse(
) {

public static OneVaccinationResponse toResponse(Vaccination vaccination) {
return OneVaccinationResponse.builder()
.id(vaccination.getId())
.name(vaccination.getName())
.year(vaccination.getTimeYear())
.month(vaccination.getTimeMonth())
.day(vaccination.getTimeDay())
.build();
return new OneVaccinationResponse(
vaccination.getId(),
vaccination.getName(),
vaccination.getVaccinatedAt().getYear(),
vaccination.getVaccinatedAt().getMonthValue(),
vaccination.getVaccinatedAt().getDayOfMonth()
);
}
}
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
Expand Up @@ -2,11 +2,9 @@

import com.kau.capstone.entity.pet.Pet;
import com.kau.capstone.entity.vaccination.Vaccination;
import lombok.Builder;

import java.util.List;

@Builder
public record VaccinationsResponse(
PetVaccinationResponse pet,
List<OneVaccinationResponse> vaccination
Expand All @@ -18,9 +16,6 @@ public static VaccinationsResponse toResponse(Pet pet, List<Vaccination> vaccina
.map(OneVaccinationResponse::toResponse)
.toList();

return VaccinationsResponse.builder()
.pet(petResponse)
.vaccination(vaccinationResponses)
.build();
return new VaccinationsResponse(petResponse, vaccinationResponses);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kau.capstone.v1.vaccination.service;

import com.kau.capstone.entity.member.Member;
import com.kau.capstone.entity.member.repository.MemberRepository;
import com.kau.capstone.entity.pet.Pet;
import com.kau.capstone.v1.pet.exception.PetNotFoundException;
Expand Down Expand Up @@ -32,33 +31,24 @@ public VaccinationsResponse getVaccinationInfo(Long petId) {
Pet pet = petRepository.findById(petId)
.orElseThrow(() -> new PetNotFoundException());

List<Vaccination> vaccinations = vaccinationRepository.findAllByMemberAndPet(pet);
List<Vaccination> vaccinations = vaccinationRepository.findAllByPetOrderByVaccinatedAtDesc(pet);

return VaccinationsResponse.toResponse(pet, vaccinations);
}

public void createVaccinationInfo(Long memberId, Long petId, CreateVaccinationRequest request) {
Member member = memberRepository.getById(memberId);

public void createVaccinationInfo(Long petId, CreateVaccinationRequest request) {
Pet pet = petRepository.findById(petId)
.orElseThrow(() -> new PetNotFoundException());

Vaccination vaccination = Vaccination.builder()
.member(member)
.pet(pet)
.name(request.name())
.timeYear(request.year())
.timeMonth(request.month())
.timeDay(request.day())
.build();
Vaccination vaccination = Vaccination.of(pet, request);
vaccinationRepository.save(vaccination);
}

public void putVaccinationInfo(Long vaccinationId, PutVaccinationRequest request) {
Vaccination vaccination = vaccinationRepository.findById(vaccinationId)
.orElseThrow(() -> new VaccinationNotFoundException(VACCINATION_NOT_FOUND));

vaccination.modify(request.name(), request.year(), request.month(), request.day());
vaccination.modify(request);
}

public void deleteVaccinationInfo(Long vaccinationId) {
Expand Down
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
) {

}
Loading
Loading