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

🐛 assign over 24 hours on recipe #391

Open
wants to merge 2 commits into
base: be/dev
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions backend/src/main/java/net/pengcook/recipe/domain/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import lombok.AccessLevel;
Expand Down Expand Up @@ -35,6 +36,9 @@ public class Recipe {
@Column(nullable = false)
private LocalTime cookingTime;

@Column(nullable = false)
private Duration cookingTimeDuration;

@Column(nullable = false)
private String thumbnail;

Expand All @@ -56,12 +60,13 @@ public class Recipe {
public Recipe(
String title,
User author,
LocalTime cookingTime,
Duration cookingTimeDuration,
String thumbnail,
int difficulty,
String description
) {
this(0L, title, author, cookingTime, thumbnail, difficulty, 0, 0, description, LocalDateTime.now());
this(0L, title, author, LocalTime.MIN, cookingTimeDuration, thumbnail, difficulty, 0, 0, description,
LocalDateTime.now());
}

public void increaseLikeCount() {
Expand Down
25 changes: 24 additions & 1 deletion backend/src/main/java/net/pengcook/recipe/dto/RecipeRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,40 @@
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import java.time.Duration;
import java.util.List;
import net.pengcook.ingredient.dto.IngredientCreateRequest;

public record RecipeRequest(
@NotBlank String title,
@NotBlank String cookingTime,
@NotBlank @Pattern(regexp = "^\\d+:\\d+:\\d+$") String cookingTime,
@NotBlank String thumbnail,
@Min(0) @Max(10) int difficulty,
@NotBlank String description,
@NotEmpty List<String> categories,
@NotEmpty List<IngredientCreateRequest> ingredients,
List<RecipeStepRequest> recipeSteps
) {
public Duration parseCookingTime() {
String[] parts = cookingTime.split(":");

int hours = Integer.parseInt(parts[0]);
int minutes = Integer.parseInt(parts[1]);
int seconds = Integer.parseInt(parts[2]);

if (seconds >= 60) {
minutes += seconds / 60;
seconds %= 60;
}

if (minutes >= 60) {
hours += minutes / 60;
minutes %= 60;
}

return Duration.ofHours(hours)
.plusMinutes(minutes)
.plusSeconds(seconds);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.pengcook.recipe.service;

import java.time.LocalTime;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -153,7 +152,7 @@ public RecipeResponse createRecipe(UserInfo userInfo, RecipeRequest recipeReques
Recipe recipe = new Recipe(
recipeRequest.title(),
author,
LocalTime.parse(recipeRequest.cookingTime()),
recipeRequest.parseCookingTime(),
thumbnailUrl,
recipeRequest.difficulty(),
recipeRequest.description()
Expand Down
Loading