Skip to content

feat: 유저 펫 조회 api 추가 #156

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

feat: 유저 펫 조회 api 추가 #156

wants to merge 2 commits into from

Conversation

whale22
Copy link
Contributor

@whale22 whale22 commented Apr 22, 2025

#️⃣ Issue Number

#150

📝 요약(Summary)

펫 조회 api 추가

🛠️ PR 유형

어떤 변경 사항이 있나요?

  • 새로운 기능 추가
  • 버그 수정
  • CSS 등 사용자 UI 디자인 변경
  • 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
  • 코드 리팩토링
  • 주석 추가 및 수정
  • 문서 수정
  • 테스트 추가, 테스트 리팩토링
  • 빌드 부분 혹은 패키지 매니저 수정
  • 파일 혹은 폴더명 수정
  • 파일 혹은 폴더 삭제

📸스크린샷 (선택)

💬 공유사항 to 리뷰어

✅ PR Checklist

PR이 다음 요구 사항을 충족하는지 확인하세요.

  • 커밋 메시지 컨벤션에 맞게 작성했습니다.
  • 변경 사항에 대한 테스트를 했습니다.(버그 수정/기능에 대한 테스트).

@@ -32,7 +32,6 @@ public class ApiV1NotiController {
private final NotiService notiService;
private final UserService userService;

Choose a reason for hiding this comment

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

ApiV1NotiController에서 코드 한 줄이 삭제되었습니다. 의도한 변경인지 확인하고, 삭제된 코드의 기능이 다른 곳에서 처리되는지 확인해야 합니다. 삭제 이유를 commit message에 명확히 명시해주세요.

@@ -12,8 +12,6 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

Choose a reason for hiding this comment

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

PetController의 getAllPets 메서드가 삭제되었습니다. 이 메서드는 모든 펫을 조회하는 기능을 담당했는데, 삭제 이유와 대체 로직이 있는지 확인해야 합니다. 삭제 이유를 commit message에 명확히 명시해주세요.

@@ -1,20 +1,18 @@
package cmf.commitField.domain.pet.controller;


import cmf.commitField.domain.pet.entity.Pet;
import cmf.commitField.domain.pet.dto.UserPetListDto;

Choose a reason for hiding this comment

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

Pet 엔티티 대신 UserPetListDto를 import 합니다. DTO를 사용하는 것은 좋은데, UserPetListDto의 내용을 확인하여 적절한지 검토해야 합니다.

import cmf.commitField.domain.pet.service.PetService;
import cmf.commitField.domain.pet.service.UserPetService;
import cmf.commitField.domain.user.entity.User;
import cmf.commitField.domain.user.entity.CustomOAuth2User;

Choose a reason for hiding this comment

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

User 엔티티 대신 CustomOAuth2User를 import 합니다. Spring Security의 AuthenticationPrincipal 어노테이션과 함께 사용하는 것으로 보이며, 사용자 인증 방식과 일관성을 유지하는지 확인해야 합니다.

import cmf.commitField.domain.pet.service.PetService;
import cmf.commitField.domain.pet.service.UserPetService;
import cmf.commitField.domain.user.entity.User;
import cmf.commitField.domain.user.entity.CustomOAuth2User;
import cmf.commitField.domain.user.service.CustomOAuth2UserService;

Choose a reason for hiding this comment

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

GlobalResponse와 관련된 import 문이 삭제되었습니다. GlobalResponse 클래스가 어떤 역할을 했는지 확인하고, 삭제된 이유와 대체 로직이 있는지 확인해야 합니다. ResponseEntity로 변경된 부분과의 연관성을 확인하세요.

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;

Choose a reason for hiding this comment

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

@PathVariable을 사용한 userId 파라미터가 삭제되고, @AuthenticationPrincipal을 사용하여 CustomOAuth2User를 주입받도록 변경되었습니다. 사용자 인증 방식이 변경된 것으로 보이며, 보안 및 기능적인 측면에서 검토가 필요합니다. 이 변경으로 인해 발생할 수 있는 문제점을 고려해야 합니다.

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Choose a reason for hiding this comment

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

getUserPetCollection 메서드의 반환 타입이 GlobalResponse<List>에서 ResponseEntity로 변경되었습니다. GlobalResponse를 사용하지 않는 이유를 확인하고, ResponseEntity를 사용하는 것이 적절한지 확인해야 합니다.

@@ -24,11 +22,11 @@ public class UserPetController {
private final CustomOAuth2UserService customOAuth2UserService;
private final PetService petService;

Choose a reason for hiding this comment

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

주석 // TODO: 기능 확장시 추가 예정 이 삭제되었습니다. TODO 주석은 개발 과정에서 중요한 정보이므로, 삭제 이유를 확인해야 합니다. 만약 기능 확장 계획이 변경되었다면, commit message에 명확히 기록해야 합니다.

public GlobalResponse<List<Pet>> getUserPetCollection(@PathVariable Long userId) {
User user = customOAuth2UserService.getUserById(userId).orElse(null);
return GlobalResponse.success(userPetService.getUserPetCollection(user));
@GetMapping("/collection")

Choose a reason for hiding this comment

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

기존의 getUserPetCollection 메소드가 수정되었습니다. PathVariable userId를 사용하지 않고, AuthenticationPrincipal을 이용하여 사용자 정보를 가져오도록 변경되었습니다. 보안 및 성능 측면을 고려하여 이 변경이 적절한지 검토해야 합니다.

@@ -0,0 +1,17 @@
package cmf.commitField.domain.pet.dto;

Choose a reason for hiding this comment

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

새로운 DTO 클래스 UserPetListDto가 추가되었습니다. 이 DTO가 어떤 목적으로 사용되는지 확인하고, 필드의 타입과 이름이 적절한지 검토해야 합니다. 특히, petList Map의 Integer 키는 펫 타입을 나타내는 것으로 보이는데, 100개의 타입을 지원하는 것이 적절한지 확인하고, 더 효율적인 방법이 있는지 고려해봐야 합니다. FIXME: 차후 갯수 수정 필요 부분을 수정해야 합니다. 어떤 방식으로 펫 타입의 갯수를 동적으로 관리할 수 있을지 고려해야 합니다. 예를 들어, enum을 사용하는 것이 좋을 수 있습니다.

@@ -2,6 +2,7 @@

import cmf.commitField.domain.pet.dto.PetsDto;
import cmf.commitField.domain.pet.dto.UserPetDto;
import cmf.commitField.domain.pet.dto.UserPetListDto;

Choose a reason for hiding this comment

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

UserPetListDto import 추가. DTO를 사용하는 것은 좋은데, UserPetListDto의 내용을 확인하여 적절한지 검토해야 합니다.

// 모든 펫 조회
public List<Pet> getAllPets() {
return petRepository.findAll();
// 유저가 소유한 펫 조회

Choose a reason for hiding this comment

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

getAllPets 메서드가 수정되었습니다. 이제 사용자 이름을 받아서 해당 사용자가 소유한 펫 목록을 UserPetListDto 형태로 반환합니다. petsNum 배열의 크기가 100으로 고정되어 있는데, 이는 매우 비효율적이며, 향후 펫 타입이 100개를 넘어가면 문제가 발생합니다. FIXME: 차후 갯수 수정 필요 라는 주석이 있는데, 더 나은 데이터 구조 (예: Map)를 사용하여 펫 타입과 개수를 관리해야 합니다. 또한, max 변수를 사용하여 최대 펫 타입을 찾는 부분도 비효율적입니다. Map을 사용하면 이 부분이 필요 없습니다. 전반적으로 코드의 효율성을 개선해야 합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant