Skip to content
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

Shelter 수정 시 zonecode(우편번호) 입력 추가 #237

Merged
merged 1 commit into from
Nov 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ public List<ShelterLocationDto> filterExistShelterListByLocationId(final List<In
public ShelterUpdateSuccessDto updateShelterInfo(final UserDetailsImpl userDetails,
final Integer shelterId,
final ShelterUpdateDto shelterUpdateDto) {
final Shelter shelter = shelterRepository.findById(shelterId).orElseThrow(
ShelterNotFoundException::new
);

if (!shelter.getAccount().getEmail().equals(userDetails.getEmail())) {
throw new ShelterPermissionDeniedException();
}
final Shelter shelter = shelterRepository.findById(shelterId)
.orElseThrow(ShelterNotFoundException::new);
validateShelterOwner(shelter, userDetails);

shelter.updateInfo(shelterUpdateDto);

return ShelterUpdateSuccessDto.builder()
.shelterId(shelterId)
.build();
}

private void validateShelterOwner(final Shelter shelter, final UserDetailsImpl userDetails) {
if (!shelter.equalsByAccountEmail(userDetails.getEmail())) {
throw new ShelterPermissionDeniedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
package com.daggle.animory.domain.shelter.dto.request;

import com.daggle.animory.domain.shelter.entity.Province;
import com.daggle.animory.domain.shelter.entity.ShelterAddress;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.Builder;

import javax.validation.constraints.NotNull;

@Builder
public record ShelterAddressUpdateDto(
@NotNull(message = "광역시/도를 입력해주세요.") Province province,
String city,
@NotNull(message = "도로명을 입력해주세요.") String roadName,
String detail) {
@NotNull(message = "광역시/도를 입력해주세요.") Province province,
String city,
@NotNull(message = "도로명을 입력해주세요.") String roadName,
String detail,
String zonecode) {


@Hidden
public ShelterAddress getShelterAddress() {
return ShelterAddress.builder()
.province(province)
.city(city)
.roadName(roadName)
.detail(detail)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
package com.daggle.animory.domain.shelter.dto.request;

import com.daggle.animory.domain.shelter.entity.ShelterAddress;
import lombok.Builder;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@Builder
public record ShelterUpdateDto(
@NotNull(message = "보호소 이름을 입력해주세요.") String name,
@NotNull(message = "보호소 연락처를 입력해주세요.") String contact,
@Valid @NotNull(message = "보호소 주소를 입력해주세요.") ShelterAddressUpdateDto shelterAddressUpdateDto) {
@NotNull(message = "보호소 이름을 입력해주세요.") String name,
@NotNull(message = "보호소 연락처를 입력해주세요.") String contact,
@Valid @NotNull(message = "보호소 주소를 입력해주세요.") ShelterAddressUpdateDto shelterAddressUpdateDto) {


public ShelterAddress buildShelterAddress() {
return ShelterAddress.builder()
.province(shelterAddressUpdateDto.province())
.city(shelterAddressUpdateDto.city())
.roadName(shelterAddressUpdateDto.roadName())
.detail(shelterAddressUpdateDto.detail())
.zonecode(shelterAddressUpdateDto.zonecode())
.build();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ public class Shelter extends BaseEntity {
@JoinColumn(name = "account_id")
private Account account;

public void updateInfo(ShelterUpdateDto shelterUpdateDto) {
public void updateInfo(final ShelterUpdateDto shelterUpdateDto) {
this.name = shelterUpdateDto.name();
this.contact = shelterUpdateDto.contact();
this.address = shelterUpdateDto.shelterAddressUpdateDto().getShelterAddress();
this.address = shelterUpdateDto.buildShelterAddress();
}

public boolean equalsByAccountEmail(final String email) {
return this.account.getEmail().equals(email);
}
}