Skip to content

Commit 0c75093

Browse files
committed
fix: 펫 로직에 문제 발견되어 수정
1 parent c32a369 commit 0c75093

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

src/main/java/cmf/commitField/domain/pet/controller/PetController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@
1313
import org.springframework.web.bind.annotation.*;
1414
import org.springframework.web.multipart.MultipartFile;
1515

16+
import java.util.List;
17+
1618
@RestController
1719
@RequiredArgsConstructor
1820
@RequestMapping("/api/pets")
1921
public class PetController {
2022
private final CustomOAuth2UserService userService;
2123
private final PetService petService;
2224

25+
// 현재 펫 경험치 상승 및 상승 시 레벨업 처리
26+
@GetMapping("/getall")
27+
public ResponseEntity<List<UserPetDto>> getUserPets(@AuthenticationPrincipal CustomOAuth2User oAuth2User){
28+
String username = oAuth2User.getName(); // CustomOAuth2User의 getName()은 user.getUsername()을 반환
29+
30+
List<UserPetDto> userPetDto = petService.getAllPets(username);
31+
return ResponseEntity.ok(userPetDto);
32+
}
33+
2334
// 현재 펫 경험치 상승 및 상승 시 레벨업 처리
2435
@GetMapping("/exp")
2536
public ResponseEntity<UserPetDto> getUserTier(@AuthenticationPrincipal CustomOAuth2User oAuth2User){

src/main/java/cmf/commitField/domain/pet/controller/UserPetController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class UserPetController {
2626
@GetMapping("/collection")
2727
public ResponseEntity<UserPetListDto> getUserPetCollection(@AuthenticationPrincipal CustomOAuth2User oAuth2User) {
2828
String username = oAuth2User.getName();
29-
UserPetListDto userPetListDto = petService.getAllPets(username);
29+
UserPetListDto userPetListDto = petService.getUserCollection(username);
3030
return ResponseEntity.ok(userPetListDto);
3131
}
3232
}

src/main/java/cmf/commitField/domain/pet/dto/UserPetDto.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public class UserPetDto {
1414
private long petId;
1515
private String petName;
1616
private String grow;
17+
private int type;
1718
private long exp;
1819
}

src/main/java/cmf/commitField/domain/pet/service/PetService.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,26 @@ public Pet createPet(String name, MultipartFile imageFile, User user) throws IOE
3636
return petRepository.save(pet);
3737
}
3838

39-
// 유저가 소유한 펫 조회
40-
public UserPetListDto getAllPets(String username) {
39+
public List<UserPetDto> getAllPets(String username){
40+
List<Pet> pets = petRepository.findByUserUsername(username);
41+
List<UserPetDto> userPetDtoList = new ArrayList<>();
42+
43+
for(Pet pet : pets){
44+
userPetDtoList.add(UserPetDto.builder().
45+
username(username).
46+
petId(pet.getId()).
47+
petName(pet.getName()).
48+
grow(pet.getGrow().toString()).
49+
type(pet.getType()).
50+
build());
51+
}
52+
53+
return userPetDtoList;
54+
}
55+
56+
57+
// 유저가 소유한 펫 도감 조회
58+
public UserPetListDto getUserCollection(String username) {
4159
List<Pet> pets = petRepository.findByUserUsername(username);
4260
int[] petsNum = new int[100]; //FIXME: 차후 갯수 수정 필요
4361
int max = 0;

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spring:
1818
jpa:
1919
open-in-view: false
2020
hibernate:
21-
ddl-auto: create
21+
ddl-auto: update
2222
properties:
2323
hibernate:
2424
default_batch_fetch_size: 100

0 commit comments

Comments
 (0)