Skip to content
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

[merge] main 브랜치 재배포 #206

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ResponseEntity<PetResponse> updatePet(
}
//근처 반려동물 조회
@GetMapping("/nearby")
@Operation(summary = "근처의 반려동물 목록을 조회", description = "클라이언트로부터 위도 경도 ,시/군/구 등의 데이터를 받았을때 위도 경도를 기준으로 거리를 계산하여 반경내(20km)의 반려동물 목록을 조회")
@Operation(summary = "근처의 반려동물 목록을 조회", description = "클라이언트로부터 위도 경도 ,시/군/구 등의 데이터를 받았을때 위도 경도를 기준으로 거리를 계산하여 최대 반경내(50km)의 반려동물 목록을 조회")
public ResponseEntity<PetNearbyPageResponse> getNearbyPets(
@ModelAttribute PetLocationRequest petLocationDTO,
@ModelAttribute PageRequest pageRequestDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public interface PetRepository extends JpaRepository<Pet, Long> {

//반경 내 반려동물 조회
@Query(value = """
SELECT p.* FROM Pet p \
JOIN Member m ON p.member_id = m.member_id \
SELECT p.* FROM pet p \
JOIN member m ON p.member_id = m.member_id \
JOIN address a ON a.member_id = m.member_id \
WHERE p.is_open_profile = true \
AND p.is_active = true \
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/mallangs/domain/pet/service/PetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public PetResponse updatePet(PetUpdateRequest petUpdateRequest, Long petId, Cust
Pet pet = petRepository.findById(petId).orElseThrow(() -> new MallangsCustomException(ErrorCode.PET_NOT_FOUND));
Member member = getMember(customMemberDetails);

//반려동물 수정시도시 예외 던짐
//타인의 반려동물 수정시도시 예외 던짐
if (!pet.getMember().getMemberId().equals(member.getMemberId())) {
throw new MallangsCustomException(ErrorCode.PET_NOT_OWNED);
}
Expand Down Expand Up @@ -162,11 +162,12 @@ public PetResponse updatePet(PetUpdateRequest petUpdateRequest, Long petId, Cust
//반려동물 삭제 (비활성화)
public PetResponse deletePet(Long petId, CustomMemberDetails customMemberDetails) {
Member member = getMember(customMemberDetails);
try {

Pet pet = petRepository.findById(petId).orElseThrow(() -> new MallangsCustomException(ErrorCode.PET_NOT_FOUND));
if (!pet.getMember().getMemberId().equals(member.getMemberId())) {
throw new MallangsCustomException(ErrorCode.PET_NOT_OWNED);
}
try {
pet.deactivate();
petRepository.save(pet);
return new PetResponse(pet);
Expand All @@ -179,11 +180,12 @@ public PetResponse deletePet(Long petId, CustomMemberDetails customMemberDetails
//반려동물 복원 (활성화)
public PetResponse restorePet(Long petId, CustomMemberDetails customMemberDetails) {
Member member = getMember(customMemberDetails);
try {

Pet pet = petRepository.findById(petId).orElseThrow(() -> new MallangsCustomException(ErrorCode.PET_NOT_FOUND));
if (!pet.getMember().getMemberId().equals(member.getMemberId())) {
throw new MallangsCustomException(ErrorCode.PET_NOT_OWNED);
}
try {
pet.activate();
petRepository.save(pet);
return new PetResponse(pet);
Expand All @@ -196,9 +198,9 @@ public PetResponse restorePet(Long petId, CustomMemberDetails customMemberDetail
//반경 내 반려동물 조회
public Page<PetNearbyResponse> getNearbyPets(PetLocationRequest petLocationRequest,
PageRequest pageRequest) {
try {
validateLocationSearch(petLocationRequest);

validateLocationSearch(petLocationRequest);
try {
Sort sort = Sort.by("pet_Id").descending();
Pageable pageable = pageRequest.getPageable(sort);

Expand Down Expand Up @@ -243,7 +245,7 @@ private void validateLocationSearch(PetLocationRequest petLocationRequest) {

if (y < -90 || y > 90 || //북위는 양수로 남위는 음수로 표현
x < -180 || x > 180 || //동경은 양수로 서경은 음수로 표현
petLocationRequest.getRadius() <= 0 || petLocationRequest.getRadius() > 20) { // 최대 반경 20km
petLocationRequest.getRadius() <= 0 || petLocationRequest.getRadius() > 50) { // 최대 반경 50km
throw new MallangsCustomException(ErrorCode.LOCATION_INVALIDE_RANGE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ReviewInfoResponse createReview(ReviewCreateRequest reviewCreateRequest,
return new ReviewInfoResponse(savedReview);
}catch (DataAccessException e) {
log.error("Failed to create review: {}" ,e.getMessage());
throw new MallangsCustomException(ErrorCode.ARTICLE_NOT_FOUND);
throw new MallangsCustomException(ErrorCode.REVIEW_NOT_CREATED);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/mallangs/global/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public enum ErrorCode {
PET_NOT_FOUND(NOT_FOUND, "반려동물 정보를 찾을 수 없습니다"),
PET_NOT_ACTIVATE(HttpStatus.GONE, "반려동물이 비활성화(삭제) 상태입니다."),
PET_NOT_PROFILE_OPEN(HttpStatus.FORBIDDEN, "반려동물 비공개 상태입니다."),
PET_NOT_CREATE(HttpStatus.BAD_REQUEST, "반려동물 등록에 실패하였습니다."),
PET_NOT_CREATE(HttpStatus.INTERNAL_SERVER_ERROR, "반려동물 등록에 실패하였습니다."),
PET_NOT_UPDATE(HttpStatus.INTERNAL_SERVER_ERROR, "반려동물 수정에 실패하였습니다."),
PET_NOT_DELETE(HttpStatus.INTERNAL_SERVER_ERROR, "반려동물 삭제(비활성화)에 실패하였습니다."),
PET_NOT_RESTORE(HttpStatus.INTERNAL_SERVER_ERROR, "반려동물 복원(활성화)에 실패하였습니다."),
Expand All @@ -84,8 +84,8 @@ public enum ErrorCode {
PET_NOT_REPRESENTATIVE(HttpStatus.INTERNAL_SERVER_ERROR, "대표 말랑이(반려동물) 등록에 실패하였습니다."),

//Location
LOCATION_INVALIDE_PARAMS(HttpStatus.INTERNAL_SERVER_ERROR, "입력된 데이터가 유효하지 않습니다."),
LOCATION_INVALIDE_RANGE(HttpStatus.INTERNAL_SERVER_ERROR, "유효하지 않은 범위입니다."),
LOCATION_INVALIDE_PARAMS(BAD_REQUEST, "입력된 데이터가 유효하지 않습니다."),
LOCATION_INVALIDE_RANGE(BAD_REQUEST, "유효하지 않은 위치 범위입니다."),

// Comment
COMMENT_NOT_FOUND(NOT_FOUND, "댓글을 찾을 수 없습니다."),
Expand Down
Loading
Loading