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

UI 관련 API 수정 요청 반영, PetVideo 조회 로직의 오류 수정 등 #258

Merged
merged 4 commits into from
Nov 11, 2023
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 @@ -73,6 +73,7 @@ public Response<SosPetProfilesDto> getPetSosProfiles(
return Response.success(petReadService.getPetSosProfiles(pageable));
}


@GetMapping("/profiles/new")
public Response<NewPetProfilesDto> getPetNewProfiles(
@PageableDefault(size = 8, sort = "createdAt", direction = Direction.DESC) final Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -27,7 +28,7 @@ public interface PetControllerApi {

@Operation(summary = "[로그인 필요: 보호소] Pet 등록 요청",
description = "Pet 등록 요청 API 입니다. Swagger Test가 작동하지 않을 수 있습니다.(https://github" +
".com/springdoc/springdoc-openapi/issues/820)",
".com/springdoc/springdoc-openapi/issues/820)",
parameters = {
@Parameter(
in = ParameterIn.HEADER,
Expand All @@ -41,10 +42,10 @@ public interface PetControllerApi {
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "저장 성공"),
@ApiResponse(responseCode = "400", description = "1. 이미지 형식이 jpg, jpeg, png, gif, bmp, tiff 중 하나가 아닐 경우" +
"\t\n 2. 비디오 형식이 mp4, avi, mov, wmv, flv, mkv, webm 중 하나가 아닐 경우" +
"\t\n 3. 빈 이미지 파일일 경우" +
"\t\n 4. 빈 비디오 파일일 경우" +
"\t\n 5. 잘못된 나이 형식일 경우", content = @Content),
"\t\n 2. 비디오 형식이 mp4, avi, mov, wmv, flv, mkv, webm 중 하나가 아닐 경우" +
"\t\n 3. 빈 이미지 파일일 경우" +
"\t\n 4. 빈 비디오 파일일 경우" +
"\t\n 5. 잘못된 나이 형식일 경우", content = @Content),
@ApiResponse(responseCode = "404", description = "로그인되어 있는 보호소의 권한 체크 중 해당 보호소를 DB에서 찾을 수 없는 경우", content = @Content),
@ApiResponse(responseCode = "500", description = "S3 저장 오류", content = @Content)
})
Expand All @@ -68,7 +69,7 @@ Response<PetRegisterInfoDto> getPetRegisterInfo(UserDetailsImpl userDetails,
// Pet 수정 요청
@Operation(summary = "[로그인 필요: 보호소] Pet 수정 요청",
description = "보호소 계정 권한이 필요합니다. Swagger Test가 작동하지 않을 수 있습니다.(https://github" +
".com/springdoc/springdoc-openapi/issues/820)",
".com/springdoc/springdoc-openapi/issues/820)",
parameters = {
@Parameter(
in = ParameterIn.HEADER,
Expand All @@ -82,10 +83,10 @@ Response<PetRegisterInfoDto> getPetRegisterInfo(UserDetailsImpl userDetails,
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "저장 성공"),
@ApiResponse(responseCode = "400", description = "1. 이미지 형식이 jpg, jpeg, png, gif, bmp, tiff 중 하나가 아닐 경우" +
"\t\n 2. 비디오 형식이 mp4, avi, mov, wmv, flv, mkv, webm 중 하나가 아닐 경우" +
"\t\n 3. 빈 이미지 파일일 경우" +
"\t\n 4. 빈 비디오 파일일 경우" +
"\t\n 5. 잘못된 나이 형식일 경우", content = @Content),
"\t\n 2. 비디오 형식이 mp4, avi, mov, wmv, flv, mkv, webm 중 하나가 아닐 경우" +
"\t\n 3. 빈 이미지 파일일 경우" +
"\t\n 4. 빈 비디오 파일일 경우" +
"\t\n 5. 잘못된 나이 형식일 경우", content = @Content),
@ApiResponse(responseCode = "403", description = "해당 펫을 수정할 권한이 없는 경세", content = @Content),
@ApiResponse(responseCode = "404", description = "존재하지 않는 펫을 수정하려는 경우", content = @Content),
@ApiResponse(responseCode = "500", description = "S3 저장 오류", content = @Content)
Expand Down Expand Up @@ -146,7 +147,7 @@ Response<SosPetProfilesDto> getPetSosProfiles(
)
Response<NewPetProfilesDto> getPetNewProfiles(
@Parameter(hidden = true)
@PageableDefault(size = 8) Pageable pageable);
@PageableDefault(size = 8, sort = "createdAt", direction = Sort.Direction.DESC) final Pageable pageable);

@Operation(summary = "Pet 상세 조회",
description = "")
Expand All @@ -157,7 +158,6 @@ Response<NewPetProfilesDto> getPetNewProfiles(
Response<PetDto> getPetDetail(@PathVariable int petId);



@Operation(summary = "[로그인 필요: 보호소] Pet 입양 완료 처리",
description = "입양 상태가 변경되고, 보호만료날짜가 삭제됩니다.",
parameters = {
Expand All @@ -171,10 +171,10 @@ Response<NewPetProfilesDto> getPetNewProfiles(
}
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "펫 입양 처리 성공"),
@ApiResponse(responseCode = "403", description = "해당 펫을 수정할 권한이 없는 경우", content = @Content),
@ApiResponse(responseCode = "404", description = "1. 존재하지 않는 펫인 경우" +
"\t\n 2. 로그인되어 있는 보호소의 권한 체크 중 해당 보호소를 DB에서 찾을 수 없는 경우", content = @Content)
@ApiResponse(responseCode = "200", description = "펫 입양 처리 성공"),
@ApiResponse(responseCode = "403", description = "해당 펫을 수정할 권한이 없는 경우", content = @Content),
@ApiResponse(responseCode = "404", description = "1. 존재하지 않는 펫인 경우" +
"\t\n 2. 로그인되어 있는 보호소의 권한 체크 중 해당 보호소를 DB에서 찾을 수 없는 경우", content = @Content)
})
Response<Void> updatePetAdopted(@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable int petId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package com.daggle.animory.domain.pet.dto.response;

import com.daggle.animory.domain.pet.entity.AdoptionStatus;
import com.daggle.animory.domain.pet.entity.Pet;
import com.daggle.animory.domain.pet.entity.Sex;
import com.daggle.animory.domain.pet.util.PetAgeToBirthDateConverter;
import lombok.Builder;

@Builder
public record NewPetDto(
Integer petId,
String petName,
String petAge,
String profileImageUrl,
String adoptionStatus,
Integer shelterId,
String shelterName
Integer petId,
String petName,
String petAge,
Sex sex,
String profileImageUrl,
String adoptionStatus,
Integer shelterId,
String shelterName
) {

public static NewPetDto fromEntity(final Pet pet) {
return NewPetDto.builder()
.petId(pet.getId())
.petName(pet.getName())
.petAge(PetAgeToBirthDateConverter.birthDateToAge(pet.getBirthDate()))
.profileImageUrl(pet.getProfileImageUrl())
.adoptionStatus(pet.getAdoptionStatus().getMessage())
.shelterId(pet.getShelter().getId())
.shelterName(pet.getShelter().getName())
.build();
.petId(pet.getId())
.petName(pet.getName())
.petAge(PetAgeToBirthDateConverter.birthDateToAge(pet.getBirthDate()))
.sex(pet.getSex())
.profileImageUrl(pet.getProfileImageUrl())
.adoptionStatus(pet.getAdoptionStatus().getMessage())
.shelterId(pet.getShelter().getId())
.shelterName(pet.getShelter().getName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
package com.daggle.animory.domain.pet.dto.response;

import com.daggle.animory.domain.pet.entity.Pet;
import com.daggle.animory.domain.pet.entity.Sex;
import com.daggle.animory.domain.pet.util.PetAgeToBirthDateConverter;
import lombok.Builder;

import java.time.LocalDate;

@Builder
public record SosPetDto(
Integer petId,
String petName,
String petAge,
String profileImageUrl,
LocalDate protectionExpirationDate,
Integer shelterId,
String shelterName
Integer petId,
String petName,
String petAge,
Sex sex,
String profileImageUrl,
LocalDate protectionExpirationDate,
Integer shelterId,
String shelterName
) {

public static SosPetDto fromEntity(final Pet pet) {
return SosPetDto.builder()
.petId(pet.getId())
.petName(pet.getName())
.petAge(PetAgeToBirthDateConverter.birthDateToAge(pet.getBirthDate()))
.profileImageUrl(pet.getProfileImageUrl())
.protectionExpirationDate(pet.getProtectionExpirationDate())
.shelterId(pet.getShelter().getId())
.shelterName(pet.getShelter().getName())
.build();
.petId(pet.getId())
.petName(pet.getName())
.petAge(PetAgeToBirthDateConverter.birthDateToAge(pet.getBirthDate()))
.sex(pet.getSex())
.profileImageUrl(pet.getProfileImageUrl())
.protectionExpirationDate(pet.getProtectionExpirationDate())
.shelterId(pet.getShelter().getId())
.shelterName(pet.getShelter().getName())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PetVideo extends BaseEntity {


@Builder
public PetVideo(String videoUrl, Pet pet) {
public PetVideo(final String videoUrl, final Pet pet) {
this.videoUrl = videoUrl;
this.likeCount = 0;
this.pet = pet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.daggle.animory.domain.pet.entity.Pet;
import com.daggle.animory.domain.pet.entity.PetVideo;
import com.daggle.animory.domain.pet.util.PetAgeToBirthDateConverter;
import com.daggle.animory.domain.shelter.entity.Shelter;
import com.daggle.animory.domain.shortform.util.LikeCountToStringConverter;
import lombok.Builder;

Expand All @@ -20,15 +21,16 @@ public record ShortFormDto(
) {
public static ShortFormDto of(final PetVideo petVideo) {
final Pet pet = petVideo.getPet();
final Shelter shelter = pet.getShelter();

return ShortFormDto.builder()
.petId(pet.getId())
.name(pet.getName())
.age(PetAgeToBirthDateConverter.birthDateToAge(pet.getBirthDate()))
.shelterId(pet.getShelter().getId())
.shelterName(pet.getShelter().getName())
.profileShortFormUrl(pet.getPetVideo().getVideoUrl())
.likeCount(LikeCountToStringConverter.convert(pet.getPetVideo().getLikeCount()))
.shelterId(shelter.getId())
.shelterName(shelter.getName())
.profileShortFormUrl(petVideo.getVideoUrl())
.likeCount(LikeCountToStringConverter.convert(petVideo.getLikeCount()))
.adoptionStatus(pet.getAdoptionStatus().getMessage())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface PetVideoJpaRepository extends JpaRepository<PetVideo, Integer>
@Query("""
select pv.id
from PetVideo pv
order by pv.likeCount desc
order by pv.likeCount desc, pv.id desc
""")
Slice<Integer> findPetVideoIdsBy(Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Slice<Integer> findPetVideoIdsBy(final PetType petType, final Province pr
left join pv.pet p
left join p.shelter s
%s
order by pv.likeCount desc""".formatted(switch (getFilterCondition(petType, province)) {
order by pv.likeCount desc, pv.id desc""".formatted(switch (getFilterCondition(petType, province)) {
case BOTH -> " where p.type = :petType and s.address.province = :province";
case ONLY_PET -> " where p.type = :petType";
case ONLY_PROVINCE -> " where s.address.province = :province";
Expand Down
3 changes: 3 additions & 0 deletions animory/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ server:
forward-headers-strategy: framework

spring:
devtools.add-properties: false

# MVC
web.resources.add-mappings: false # endpoint 에 없는 리소스의 경우, 정적 매핑을 하지 않는다.
mvc:
throw-exception-if-no-handler-found: true
dispatch-options-request: false
log-resolved-exception: true

# DB
datasource:
Expand Down