|
| 1 | +package umc.th.juinjang.api.limjang.controller.request; |
| 2 | + |
| 3 | +import jakarta.validation.constraints.NotNull; |
| 4 | +import jakarta.validation.constraints.Pattern; |
| 5 | +import umc.th.juinjang.domain.limjang.model.Address; |
| 6 | +import umc.th.juinjang.domain.limjang.model.LimjangPrice; |
| 7 | +import umc.th.juinjang.domain.limjang.model.LimjangPriceType; |
| 8 | +import umc.th.juinjang.domain.limjang.model.LimjangPurpose; |
| 9 | +import umc.th.juinjang.domain.limjang.repository.NotePriceFactory; |
| 10 | + |
| 11 | +public record NotePatchRequestV2( |
| 12 | + @NotNull |
| 13 | + LimjangPriceType priceType, |
| 14 | + |
| 15 | + @Pattern(regexp = "^[0-9]+$", message = "가격은 숫자만 입력해야 합니다.") |
| 16 | + String price, |
| 17 | + @Pattern(regexp = "^[0-9]+$", message = "가격은 숫자만 입력해야 합니다.") |
| 18 | + String monthlyRent, |
| 19 | + |
| 20 | + String roadAddress, |
| 21 | + String addressDetail, |
| 22 | + |
| 23 | + String bcode, |
| 24 | + |
| 25 | + String nickname, |
| 26 | + |
| 27 | + String floor, |
| 28 | + Integer pyong, //null 처리를 위해 Integer로 변경 |
| 29 | + String sido, |
| 30 | + String sigungu, |
| 31 | + String bname1, |
| 32 | + String bname2 |
| 33 | +) { |
| 34 | + |
| 35 | + public LimjangPrice toUpdatedPrice(LimjangPurpose purpose) { |
| 36 | + if (price == null && monthlyRent == null) { |
| 37 | + return LimjangPrice.empty(); |
| 38 | + } |
| 39 | + return NotePriceFactory.create(purpose, priceType, price, monthlyRent); |
| 40 | + } |
| 41 | + |
| 42 | + public Address toUpdatedAddress() { |
| 43 | + // 둘 다 없음 -> 삭제(주소 null 처리 유도) |
| 44 | + if (isDeleteAddressIntent()) { |
| 45 | + return Address.empty(); |
| 46 | + } |
| 47 | + |
| 48 | + // 상세주소만 -> 정책상 금지 |
| 49 | + if (isDetailOnly()) { |
| 50 | + throw new IllegalArgumentException("본주소 없이 상세주소만 입력할 수 없습니다."); |
| 51 | + } |
| 52 | + |
| 53 | + // 본주소가 있으면 생성 |
| 54 | + return Address.create(roadAddress, addressDetail, bcode, sido, sigungu, bname1, bname2); |
| 55 | + } |
| 56 | + |
| 57 | + private boolean isBlank(String s) { |
| 58 | + return s == null || s.isBlank(); |
| 59 | + } |
| 60 | + |
| 61 | + private boolean isDeleteAddressIntent() { // 4번 |
| 62 | + return isBlank(roadAddress) && isBlank(addressDetail); |
| 63 | + } |
| 64 | + |
| 65 | + private boolean isDetailOnly() { // 3번 |
| 66 | + return isBlank(roadAddress) && !isBlank(addressDetail); |
| 67 | + } |
| 68 | +} |
0 commit comments