Skip to content

Commit 5e5558c

Browse files
committed
fix: petAPI responseType
1 parent fdaf6eb commit 5e5558c

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

โ€Žsrc/main/java/cmf/commitField/domain/pet/controller/UserPetController.javaโ€Ž

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package cmf.commitField.domain.pet.controller;
22

33

4+
import cmf.commitField.domain.pet.dto.UserPetDto;
45
import cmf.commitField.domain.pet.entity.Pet;
5-
import cmf.commitField.domain.pet.entity.UserPet;
66
import cmf.commitField.domain.pet.service.PetService;
77
import cmf.commitField.domain.pet.service.UserPetService;
88
import cmf.commitField.domain.user.entity.User;
99
import cmf.commitField.domain.user.service.CustomOAuth2UserService;
10+
import cmf.commitField.global.globalDto.GlobalResponse;
1011
import lombok.RequiredArgsConstructor;
1112
import org.springframework.web.bind.annotation.*;
1213

@@ -23,16 +24,17 @@ public class UserPetController {
2324

2425
// ์œ ์ €๊ฐ€ ํŽซ์„ ๋ถ€ํ™”
2526
@PostMapping("/hatch")
26-
public UserPet hatchPet(@RequestParam Long userId, @RequestParam Long petId) {
27+
public GlobalResponse<UserPetDto> hatchPet(@RequestParam Long userId, @RequestParam Long petId) {
2728
User user = customOAuth2UserService.getUserById(userId).orElse(null);
2829
Pet pet = petService.getPetById(petId);
29-
return userPetService.hatchPet(user, pet);
30+
UserPetDto userPetDto = new UserPetDto(userPetService.hatchPet(user, pet));
31+
return GlobalResponse.success(userPetDto);
3032
}
3133

3234
// ์œ ์ €์˜ ๋„๊ฐ ์กฐํšŒ (๋ณด์œ ํ•œ ํŽซ ๋ชฉ๋ก)
3335
@GetMapping("/collection/{userId}")
34-
public List<Pet> getUserPetCollection(@PathVariable Long userId) {
36+
public GlobalResponse<List<Pet>> getUserPetCollection(@PathVariable Long userId) {
3537
User user = customOAuth2UserService.getUserById(userId).orElse(null);
36-
return userPetService.getUserPetCollection(user);
38+
return GlobalResponse.success(userPetService.getUserPetCollection(user));
3739
}
3840
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cmf.commitField.domain.pet.dto;
2+
3+
import cmf.commitField.domain.pet.entity.UserPet;
4+
import lombok.Getter;
5+
6+
@Getter
7+
public class UserPetDto {
8+
private Long userId;
9+
private String username;
10+
private Long petId;
11+
private String petName;
12+
private boolean isHatched;
13+
14+
public UserPetDto(UserPet userPet) {
15+
this.userId = userPet.getUser().getId();
16+
this.username = userPet.getUser().getUsername();
17+
this.petId = userPet.getPet().getId();
18+
this.petName = userPet.getPet().getName();
19+
this.isHatched = userPet.isHatched();
20+
}
21+
}

โ€Žsrc/main/java/cmf/commitField/domain/pet/entity/UserPet.javaโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
public class UserPet extends BaseEntity {
2323

2424
@ManyToOne
25-
@JoinColumn(name = "user_id")
25+
@JoinColumn(name = "user_id", nullable = false)
2626
private User user;
2727

2828
@ManyToOne
29-
@JoinColumn(name = "pet_id")
29+
@JoinColumn(name = "pet_id", nullable = false)
3030
private Pet pet;
3131

3232
private boolean isHatched; // ๋ถ€ํ™” ์—ฌ๋ถ€

0 commit comments

Comments
ย (0)