-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
901 additions
and
776 deletions.
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
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
49 changes: 49 additions & 0 deletions
49
backend/pium/src/main/java/com/official/pium/domain/vo/PetPlantState.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,49 @@ | ||
package com.official.pium.domain.vo; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PetPlantState { | ||
|
||
@NotBlank | ||
@Column(name = "location", nullable = false) | ||
private String location; | ||
|
||
@NotBlank | ||
@Column(name = "flowerpot", nullable = false) | ||
private String flowerpot; | ||
|
||
@NotBlank | ||
@Column(name = "light", nullable = false) | ||
private String light; | ||
|
||
@NotBlank | ||
@Column(name = "wind", nullable = false) | ||
private String wind; | ||
|
||
@Builder | ||
private PetPlantState(String location, String flowerpot, String light, String wind) { | ||
validateEmptyValue(location); | ||
validateEmptyValue(flowerpot); | ||
validateEmptyValue(light); | ||
validateEmptyValue(wind); | ||
this.location = location; | ||
this.flowerpot = flowerpot; | ||
this.light = light; | ||
this.wind = wind; | ||
} | ||
|
||
private void validateEmptyValue(String value) { | ||
if (value == null || value.isBlank()) { | ||
throw new IllegalArgumentException("반려 식물 속성에는 빈 값 들어올 수 없습니다. value: " + value); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
backend/pium/src/main/java/com/official/pium/domain/vo/WaterDate.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,66 @@ | ||
package com.official.pium.domain.vo; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
import java.time.temporal.ChronoUnit; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class WaterDate { | ||
|
||
@NotNull | ||
@Column(name = "next_water_date", nullable = false) | ||
private LocalDate nextWaterDate; | ||
|
||
@NotNull | ||
@Column(name = "last_water_date", nullable = false) | ||
private LocalDate lastWaterDate; | ||
|
||
@Builder | ||
private WaterDate(LocalDate nextWaterDate, LocalDate lastWaterDate) { | ||
this.nextWaterDate = nextWaterDate; | ||
this.lastWaterDate = lastWaterDate; | ||
} | ||
|
||
public Long calculateDday(LocalDate currentDate) { | ||
return ChronoUnit.DAYS.between(nextWaterDate, currentDate); | ||
} | ||
|
||
public void plusNextWaterDate(Integer waterCycle) { | ||
this.nextWaterDate = lastWaterDate.plusDays(waterCycle); | ||
} | ||
|
||
public void changeNextWaterDate(LocalDate newWaterDate) { | ||
if (newWaterDate.isEqual(LocalDate.now()) || newWaterDate.isBefore(LocalDate.now())) { | ||
throw new IllegalArgumentException("오늘과 그 이전 날짜로 물주기 날짜를 변경할 수는 없습니다. date: " + newWaterDate); | ||
} | ||
this.nextWaterDate = newWaterDate; | ||
} | ||
|
||
public void changeLastWaterDate(LocalDate lastWaterDate) { | ||
this.lastWaterDate = lastWaterDate; | ||
} | ||
|
||
public void water(LocalDate newWaterDate, Integer waterCycle) { | ||
if (newWaterDate.isAfter(LocalDate.now())) { | ||
throw new IllegalArgumentException("오늘 이후 날짜에 물을 줄 수는 없습니다. date: " + newWaterDate); | ||
} | ||
|
||
if (newWaterDate.isEqual(lastWaterDate) || newWaterDate.isBefore(lastWaterDate)) { | ||
throw new IllegalArgumentException("마지막으로 물을 준 날짜와 그 이전 날짜에는 물을 줄 수는 없습니다. date: " + newWaterDate); | ||
} | ||
this.nextWaterDate = newWaterDate.plusDays(waterCycle); | ||
this.lastWaterDate = newWaterDate; | ||
} | ||
|
||
public boolean isDifferentLastWaterDate(LocalDate lastWaterDate) { | ||
return !this.lastWaterDate.isEqual(lastWaterDate); | ||
} | ||
} |
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
Oops, something went wrong.