Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/petlog/docs/PetControllerDocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public interface PetControllerDocs {

@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "반려동물 정보 수정에 성공하였습니다.")
@Operation(summary = "반려동물 정보 수정 API")
ResponseEntity<ApiResponse<Void>> updatePetProfile(@PathVariable final Long groupId, @RequestBody final UpdatePetProfileRequestDto request);
ResponseEntity<ApiResponse<Void>> updatePetProfile(@Authenticated final Long memberId, @PathVariable final Long groupId, @RequestBody final UpdatePetProfileRequestDto request);
}
11 changes: 11 additions & 0 deletions src/main/java/com/petlog/pet/controller/PetController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.petlog.pet.service.dto.GetPetProfileDto;
import com.petlog.pet.service.dto.GetPoopInfoDto;
import com.petlog.pet.service.dto.GetWateringInfoDto;
import com.petlog.pet.service.dto.UpdatePetProfileDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -48,9 +49,19 @@ public ResponseEntity<ApiResponse<GetPetInfoResponseDto>> getPetInfo(

@PatchMapping("/{groupId}/pet")
public ResponseEntity<ApiResponse<Void>> updatePetProfile(
@Authenticated final Long memberId,
@PathVariable final Long groupId,
@RequestBody final UpdatePetProfileRequestDto request
) {
final UpdatePetProfileDto dto = new UpdatePetProfileDto(
request.imageUrl(),
request.name(),
request.age(),
request.weight(),
request.gender()
);
petService.updatePetProfile(memberId, groupId, dto);

return ResponseEntity.ok(
ApiResponse.success(UPDATE_PET_PROFILE)
);
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/com/petlog/pet/entity/PetProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public class PetProfile extends BaseEntity {
@Column(name = "age", length = 10, nullable = false)
private String age;

@Column(name = "gender", length = 10, nullable = false)
private String gender;

@Column(name = "weight", length = 10, nullable = false)
private String weight;

@Column(name = "gender", length = 10, nullable = false)
private String gender;

@Column(name = "feeding_cycle", nullable = false)
private int feedingCycle;

Expand All @@ -55,18 +55,32 @@ public PetProfile(
final String imageUrl,
final String name,
final String age,
final String gender,
final String weight,
final String gender,
final int feedingCycle,
final int wateringCycle
) {
this.petGroup = petGroup;
this.imageUrl = imageUrl;
this.name = name;
this.age = age;
this.gender = gender;
this.weight = weight;
this.gender = gender;
this.feedingCycle = feedingCycle;
this.wateringCycle = wateringCycle;
}

public void updatePetProfile(
final String imageUrl,
final String name,
final String age,
final String weight,
final String gender
) {
this.imageUrl = imageUrl;
this.name = name;
this.age = age;
this.weight = weight;
this.gender = gender;
}
}
22 changes: 20 additions & 2 deletions src/main/java/com/petlog/pet/service/PetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.petlog.pet.service.dto.GetPetProfileDto;
import com.petlog.pet.service.dto.GetPoopInfoDto;
import com.petlog.pet.service.dto.GetWateringInfoDto;
import com.petlog.pet.service.dto.UpdatePetProfileDto;
import com.petlog.petgroup.entity.PetGroup;
import com.petlog.petgroup.entity.PetGroupMember;
import com.petlog.petgroup.repository.PetGroupMemberRepository;
Expand Down Expand Up @@ -49,8 +50,8 @@ public GetPetProfileDto getPetProfile(final Long memberId, final Long groupId) {
petProfile.getImageUrl(),
petProfile.getName(),
petProfile.getAge(),
petProfile.getGender(),
petProfile.getWeight()
petProfile.getWeight(),
petProfile.getGender()
);
}

Expand Down Expand Up @@ -127,4 +128,21 @@ private int getTodayPoopRecordCount(final PetProfile petProfile) {

return poopDailyRecordRepository.countByPetProfileAndTimeBetween(petProfile, start, end);
}

@Transactional
public void updatePetProfile(final Long memberId, final Long groupId, final UpdatePetProfileDto dto) {
final Member member = getMember(memberId);
final PetGroup petGroup = getPetGroup(groupId);
getPetGroupMember(member, petGroup);

final PetProfile petProfile = petProfileRepository.findByPetGroupId(groupId);

petProfile.updatePetProfile(
dto.imageUrl(),
dto.name(),
dto.age(),
dto.weight(),
dto.gender()
);
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/petlog/pet/service/dto/GetPetProfileDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ public record GetPetProfileDto(
@Schema(description = "4글자 제한")
String age,

@Schema(description = "FEMALE/MALE")
String gender,

@Schema(description = "6글자 제한")
String weight
String weight,

@Schema(description = "FEMALE/MALE")
String gender


) {
public GetPetProfileDto(
final String imageUrl,
final String name,
final String age,
final String gender,
final String weight
final String weight,
final String gender
) {
this.imageUrl = imageUrl;
this.name = name;
this.age = age;
this.gender = gender;
this.weight = weight;
this.gender = gender;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/petlog/pet/service/dto/UpdatePetProfileDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.petlog.pet.service.dto;

public record UpdatePetProfileDto(

String imageUrl,
String name,
String age,
String weight,
String gender

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void createPetGroup(final Long memberId, final CreatePetGroupDto dto) {
dto.imageUrl(),
dto.name(),
dto.age(),
dto.gender(),
dto.weight(),
dto.gender(),
dto.feedingCycle(),
dto.wateringCycle()
);
Expand Down
Loading