Skip to content

Commit

Permalink
Merge pull request #78 from GDSC-KNU/develop
Browse files Browse the repository at this point in the history
merge the develop branch into the main branch.
  • Loading branch information
yooonwodyd authored Feb 25, 2024
2 parents 6d75b45 + 7850bbf commit f817708
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.gdsc.pikpet.config.security.UserSecurityDto;
import com.gdsc.pikpet.dto.UserLikeResponse;
import com.gdsc.pikpet.dto.response.AnimalDetailResponseDto;
import com.gdsc.pikpet.service.UserAccountService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -12,6 +13,8 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userInfo")
@RequiredArgsConstructor
Expand Down Expand Up @@ -44,7 +47,8 @@ public ResponseEntity<UserLikeResponse> likeAnimal(
//TODO: fixMe: 좋아하는 "동물" 조회하도록 변경해야함
@GetMapping("/likeAnimal")
public ResponseEntity<?> getLikeAnimal(Authentication authentication) {
return ResponseEntity.ok().body(userAccountService.getLikeAnimal((UserSecurityDto) authentication.getPrincipal()));
List<AnimalDetailResponseDto> likeAnimals = userAccountService.getLikeAnimal((UserSecurityDto) authentication.getPrincipal());
return ResponseEntity.ok().body(likeAnimals);
}

@GetMapping("/application/{animalId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,25 @@ public static AnimalDetailResponseDto from(Animal animal, Boolean isLiked) {
isLiked
);
}
public static AnimalDetailResponseDto from(UserLike userLike) {
return new AnimalDetailResponseDto(
userLike.getAnimal().getId(),
userLike.getAnimal().getImageUrl(),
userLike.getAnimal().getSpecies(),
userLike.getAnimal().getGender(),
userLike.getAnimal().getSize(),
userLike.getAnimal().getDisease(),
userLike.getAnimal().getShelter(),
userLike.getAnimal().isNeutralized(),
userLike.getAnimal().isCheckUp(),
userLike.getAnimal().getCaptureDate(),
userLike.getAnimal().getEnthanasiaDate(),
userLike.getAnimal().getAnimalColors().stream()
.map(AnimalColor::getColor)
.toList(),
userLike.getAnimal().getAge(),
userLike.getAnimal().getBreed(),
true
);
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/gdsc/pikpet/service/UserAccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gdsc.pikpet.config.security.UserSecurityDto;
import com.gdsc.pikpet.dto.UserLikeResponse;
import com.gdsc.pikpet.dto.response.AnimalDetailResponseDto;
import com.gdsc.pikpet.entity.animal.Animal;
import com.gdsc.pikpet.entity.Application;
import com.gdsc.pikpet.entity.UserAccount;
Expand Down Expand Up @@ -47,9 +48,9 @@ public UserLikeResponse addlikeAnimal(UserSecurityDto userSecurityDto, Long anim
}

@Transactional(readOnly = true)
public List<UserLike> getLikeAnimal(UserSecurityDto userSecurityDto) {
public List<AnimalDetailResponseDto> getLikeAnimal(UserSecurityDto userSecurityDto) {
UserAccount userAccount = getUserAccount(userSecurityDto);
return likeRepository.findAllByUserAccount(userAccount);
return likeRepository.findAllByUserAccount(userAccount).stream().map(AnimalDetailResponseDto::from).toList();
}

@Transactional
Expand Down

0 comments on commit f817708

Please sign in to comment.