-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: 유저 펫 조회 api 추가 #156
Changes from all commits
420ab80
1633f7a
c32a369
0c75093
5b93c82
deeb0c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ public class ApiV1NotiController { | |
private final NotiService notiService; | ||
private final UserService userService; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 라인의 코드 삭제 이유가 명확하지 않습니다. 삭제 이유를 주석으로 명시해주세요. 혹시 실수로 삭제한 부분이라면 원복하는 것이 좋겠습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 라인의 코드 삭제 이유가 명확하지 않습니다. 코드 삭제의 의도와 어떤 기능이 제거되었는지 주석으로 설명해주세요. 또한, 이 삭제로 인해 다른 부분에 영향을 미치는지 확인해야 합니다. |
||
|
||
@GetMapping("") | ||
public GlobalResponse<List<NotiDto>> getNoti(@AuthenticationPrincipal OAuth2User oAuth2User) { | ||
String username = oAuth2User.getName(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,15 @@ public class PetController { | |
private final CustomOAuth2UserService userService; | ||
private final PetService petService; | ||
|
||
// 현재 펫 경험치 상승 및 상승 시 레벨업 처리 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 API 엔드포인트 추가입니다. 좋은데, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 |
||
@GetMapping("/getall") | ||
public ResponseEntity<List<PetsDto>> getUserPets(@AuthenticationPrincipal CustomOAuth2User oAuth2User){ | ||
String username = oAuth2User.getName(); // CustomOAuth2User의 getName()은 user.getUsername()을 반환 | ||
|
||
List<PetsDto> userPetDto = petService.getAllPets(username); | ||
return ResponseEntity.ok(userPetDto); | ||
} | ||
|
||
// 현재 펫 경험치 상승 및 상승 시 레벨업 처리 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@GetMapping("/exp") | ||
public ResponseEntity<UserPetDto> getPetExp(@AuthenticationPrincipal CustomOAuth2User oAuth2User){ | ||
|
@@ -31,13 +40,6 @@ public ResponseEntity<UserPetDto> getPetExp(@AuthenticationPrincipal CustomOAuth | |
return ResponseEntity.ok(userPetDto); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존의 |
||
@GetMapping("/getall") | ||
public ResponseEntity<List<PetsDto>> getUserAllPets(@AuthenticationPrincipal CustomOAuth2User oAuth2User){ | ||
String username = oAuth2User.getName(); | ||
List<PetsDto> userPetDto = petService.getAllPets(username); | ||
return ResponseEntity.ok(userPetDto); | ||
} | ||
|
||
// ************************************* | ||
// TODO : 아래는 확장 기능, 추가 시 개선 필요 | ||
// ************************************* | ||
|
@@ -54,11 +56,6 @@ public ResponseEntity<Pet> createPet(@AuthenticationPrincipal CustomOAuth2User o | |
return ResponseEntity.ok(pet); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존의 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존의 모든 펫 조회 기능이 삭제되었습니다. 이 기능이 더 이상 필요하지 않은 이유를 설명해주세요. 관련된 다른 부분에 영향을 미치는지 확인해야 합니다. |
||
// 모든 펫 조회 | ||
@GetMapping | ||
public List<Pet> getAllPets() { | ||
return petService.getAllPets(); | ||
} | ||
|
||
// 특정 펫 조회 | ||
@GetMapping("/{petId}") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
package cmf.commitField.domain.pet.controller; | ||
|
||
|
||
import cmf.commitField.domain.pet.entity.Pet; | ||
import cmf.commitField.domain.pet.dto.UserPetListDto; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pet 엔티티 대신 UserPetListDto를 import 합니다. DTO를 사용하는 것은 좋은데, UserPetListDto의 내용을 확인하여 적절한지 검토해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 import문( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User 엔티티 대신 CustomOAuth2User를 import 합니다. Spring Security의 AuthenticationPrincipal 어노테이션과 함께 사용하는 것으로 보이며, 사용자 인증 방식과 일관성을 유지하는지 확인해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import cmf.commitField.domain.user.service.CustomOAuth2UserService; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GlobalResponse와 관련된 import 문이 삭제되었습니다. GlobalResponse 클래스가 어떤 역할을 했는지 확인하고, 삭제된 이유와 대체 로직이 있는지 확인해야 합니다. ResponseEntity로 변경된 부분과의 연관성을 확인하세요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 import문( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 import가 삭제되었습니다. |
||
import cmf.commitField.global.globalDto.GlobalResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필요한 import문( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필요한 import 추가: |
||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PathVariable을 사용한 userId 파라미터가 삭제되고, @AuthenticationPrincipal을 사용하여 CustomOAuth2User를 주입받도록 변경되었습니다. 사용자 인증 방식이 변경된 것으로 보이며, 보안 및 기능적인 측면에서 검토가 필요합니다. 이 변경으로 인해 발생할 수 있는 문제점을 고려해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 import문( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 import 삭제: |
||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getUserPetCollection 메서드의 반환 타입이 GlobalResponse<List>에서 ResponseEntity로 변경되었습니다. GlobalResponse를 사용하지 않는 이유를 확인하고, ResponseEntity를 사용하는 것이 적절한지 확인해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 import문( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 import 삭제: |
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/user-pets") | ||
@RequestMapping("/api/user/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RequestMapping 경로 변경: |
||
@RequiredArgsConstructor | ||
public class UserPetController { | ||
|
||
private final UserPetService userPetService; | ||
private final CustomOAuth2UserService customOAuth2UserService; | ||
private final PetService petService; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 주석 // TODO: 기능 확장시 추가 예정 이 삭제되었습니다. TODO 주석은 개발 과정에서 중요한 정보이므로, 삭제 이유를 확인해야 합니다. 만약 기능 확장 계획이 변경되었다면, commit message에 명확히 기록해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존의 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 주석 제거: |
||
// TODO: 기능 확장시 추가 예정 | ||
// 유저의 도감 조회 (보유한 펫 목록) | ||
@GetMapping("/collection/{userId}") | ||
public GlobalResponse<List<Pet>> getUserPetCollection(@PathVariable Long userId) { | ||
User user = customOAuth2UserService.getUserById(userId).orElse(null); | ||
return GlobalResponse.success(userPetService.getUserPetCollection(user)); | ||
@GetMapping("/collection") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존의 getUserPetCollection 메소드가 수정되었습니다. PathVariable userId를 사용하지 않고, AuthenticationPrincipal을 이용하여 사용자 정보를 가져오도록 변경되었습니다. 보안 및 성능 측면을 고려하여 이 변경이 적절한지 검토해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public ResponseEntity<UserPetListDto> getUserPetCollection(@AuthenticationPrincipal CustomOAuth2User oAuth2User) { | ||
String username = oAuth2User.getName(); | ||
UserPetListDto userPetListDto = petService.getUserCollection(username); | ||
return ResponseEntity.ok(userPetListDto); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ public class UserPetDto { | |
private long petId; | ||
private String petName; | ||
private String grow; | ||
private int type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
private long exp; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cmf.commitField.domain.pet.dto; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 DTO 클래스 UserPetListDto가 추가되었습니다. 이 DTO가 어떤 목적으로 사용되는지 확인하고, 필드의 타입과 이름이 적절한지 검토해야 합니다. 특히, petList Map의 Integer 키는 펫 타입을 나타내는 것으로 보이는데, 100개의 타입을 지원하는 것이 적절한지 확인하고, 더 효율적인 방법이 있는지 고려해봐야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 DTO 클래스가 추가되었습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 DTO 클래스 |
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class UserPetListDto { | ||
private String username; | ||
private Map<Integer, Integer> petList; // 아이디, 소유 갯수 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UserPetListDto import 추가. DTO를 사용하는 것은 좋은데, UserPetListDto의 내용을 확인하여 적절한지 검토해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필요한 import문( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import cmf.commitField.domain.pet.entity.Pet; | ||
import cmf.commitField.domain.pet.entity.PetGrow; | ||
import cmf.commitField.domain.pet.repository.PetRepository; | ||
|
@@ -13,10 +14,7 @@ | |
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Random; | ||
import java.util.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. import 수정: |
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
|
@@ -37,9 +35,26 @@ public Pet createPet(String petname, String username) throws IOException { | |
return petRepository.save(newPet); | ||
} | ||
|
||
// 모든 펫 조회 | ||
public List<Pet> getAllPets() { | ||
return petRepository.findAll(); | ||
// 유저가 소유한 펫 도감 조회 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 메서드 |
||
public UserPetListDto getUserCollection(String username) { | ||
List<Pet> pets = petRepository.findByUserUsername(username); | ||
int[] petsNum = new int[100]; //FIXME: 차후 갯수 수정 필요 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 메서드 |
||
int max = 0; | ||
Map<Integer, Integer> petList = new HashMap<>(); | ||
for(Pet pet : pets){ | ||
int type = pet.getType(); | ||
petsNum[type]++; | ||
if(max<type) max = type; | ||
} | ||
|
||
for(int i=0;i<=max;i++){ | ||
petList.put(i, petsNum[i]); | ||
} | ||
|
||
return UserPetListDto.builder(). | ||
username(username). | ||
petList(petList). | ||
build(); | ||
} | ||
|
||
// 특정 펫 조회 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ApiV1NotiController에서 코드 한 줄이 삭제되었습니다. 의도한 변경인지 확인하고, 삭제된 코드의 기능이 다른 곳에서 처리되는지 확인해야 합니다. 삭제 이유를 commit message에 명확히 명시해주세요.