-
Notifications
You must be signed in to change notification settings - Fork 3
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
보호소 정보 수정 API 추가 #151
Merged
보호소 정보 수정 API 추가 #151
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9194d20
보호소 정보 수정 API 추가
jminkkk 4282a49
보호소 정보 수정 서비스단 테스트 작성
jminkkk a4c6db6
보호소 수정 시 권한 체크
jminkkk 1ce2f3d
assertAll로 변경
jminkkk d52e7e3
보호소 수정 시 권한 체크 테스트 추가
jminkkk 9f5077a
fix: 계정 비교 시 pk이용으로 변경
jminkkk b982667
AccountFixture의 account에 id값 설정
jminkkk d412871
보호소 정소 수정 로직에 @Transactional 추가
jminkkk 411be81
AccountFixture에서 pk제거
jminkkk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package com.daggle.animory.domain.shelter; | ||
|
||
import com.daggle.animory.common.error.exception.Forbidden403; | ||
import com.daggle.animory.common.error.exception.NotFound404; | ||
import com.daggle.animory.domain.account.entity.Account; | ||
import com.daggle.animory.domain.pet.repository.PetRepository; | ||
import com.daggle.animory.domain.shelter.dto.request.ShelterUpdateDto; | ||
import com.daggle.animory.domain.shelter.dto.response.ShelterLocationDto; | ||
import com.daggle.animory.domain.shelter.dto.response.ShelterProfilePage; | ||
import com.daggle.animory.domain.shelter.dto.response.ShelterUpdateSuccessDto; | ||
import com.daggle.animory.domain.shelter.entity.Shelter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -31,4 +36,20 @@ public List<ShelterLocationDto> filterExistShelterListByLocationId(final List<In | |
.map(ShelterLocationDto::of) | ||
.toList(); | ||
} | ||
|
||
public ShelterUpdateSuccessDto updateShelterInfo(Account account, Integer shelterId, ShelterUpdateDto shelterUpdateDto) { | ||
Shelter shelter = shelterRepository.findById(shelterId).orElseThrow( | ||
() -> new NotFound404("해당하는 보호소가 존재하지 않습니다.") | ||
); | ||
|
||
if (!shelter.getAccount().getEmail().equals(account.getEmail())) { | ||
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. 맞는데.. 여기서는 ID(PK)가 아닌 Email로 비교를 하셨네요 ?? 나중에 무슨무슨 이유로 Email이 변경될 수 있게하자! 라고 기능이 바뀐다면, 이 코드를 찾아와야 하지 않을까 라는 생각들을 해본건데.. |
||
throw new Forbidden403("보호소 정보를 수정할 권한이 없습니다."); | ||
} | ||
|
||
shelter.updateInfo(shelterUpdateDto); | ||
|
||
return ShelterUpdateSuccessDto.builder() | ||
.shelterId(shelterId) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../src/main/java/com/daggle/animory/domain/shelter/dto/request/ShelterAddressUpdateDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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 lombok.Builder; | ||
|
||
import javax.validation.constraints.NotNull; | ||
@Builder | ||
public record ShelterAddressUpdateDto( | ||
@NotNull(message = "광역시/도를 입력해주세요.") Province province, | ||
@NotNull(message = "시/군/구를 입력해주세요.") String city, | ||
@NotNull(message = "도로명을 입력해주세요.") String roadName, | ||
String detail) { | ||
public ShelterAddress getShelterAddress() { | ||
return ShelterAddress.builder() | ||
.province(province) | ||
.city(city) | ||
.roadName(roadName) | ||
.detail(detail) | ||
.build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
animory/src/main/java/com/daggle/animory/domain/shelter/dto/request/ShelterUpdateDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.daggle.animory.domain.shelter.dto.request; | ||
|
||
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) { | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/main/java/com/daggle/animory/domain/shelter/dto/response/ShelterUpdateSuccessDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.daggle.animory.domain.shelter.dto.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ShelterUpdateSuccessDto { | ||
private final String message = "수정이 완료되었습니다."; | ||
private final Integer shelterId; | ||
|
||
@Builder | ||
public ShelterUpdateSuccessDto(final Integer shelterId) { | ||
this.shelterId = shelterId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
마찬가지로 Service 로직 어딘가에서 요청한 계정이 Dto에 담긴 Shelter Id에 대한 수정권한이 있는지 확인해줄 필요가 있을 듯 ? ?