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

[BE] feat: Recipe에 생성 시간 추가 #417

Merged
merged 4 commits into from
Aug 14, 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
9 changes: 9 additions & 0 deletions backend/src/main/java/com/funeat/recipe/domain/Recipe.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.funeat.recipe.domain;

import com.funeat.member.domain.Member;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand All @@ -19,6 +21,9 @@ public class Recipe {

private String content;

@Column(nullable = false)
private LocalDateTime createdAt = LocalDateTime.now();

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;
Expand Down Expand Up @@ -53,4 +58,8 @@ public Member getMember() {
public Long getFavoriteCount() {
return favoriteCount;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}
}
10 changes: 5 additions & 5 deletions backend/src/main/java/com/funeat/recipe/dto/RecipeAuthorDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
public class RecipeAuthorDto {

private final String profileImage;
private final String nickName;
private final String nickname;

private RecipeAuthorDto(final String profileImage, final String nickName) {
private RecipeAuthorDto(final String profileImage, final String nickname) {
this.profileImage = profileImage;
this.nickName = nickName;
this.nickname = nickname;
}

public static RecipeAuthorDto toDto(final Member member) {
Expand All @@ -20,7 +20,7 @@ public String getProfileImage() {
return profileImage;
}

public String getNickName() {
return nickName;
public String getNickname() {
return nickname;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.funeat.product.domain.Product;
import com.funeat.recipe.domain.Recipe;
import com.funeat.recipe.domain.RecipeImage;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -17,11 +18,13 @@ public class RecipeDetailResponse {
private final Long totalPrice;
private final Long favoriteCount;
private final Boolean favorite;
private final LocalDateTime createdAt;

private RecipeDetailResponse(final Long id, final List<String> images, final String title, final String content,
public RecipeDetailResponse(final Long id, final List<String> images, final String title, final String content,
final RecipeAuthorDto author,
final List<ProductRecipeDto> products, final Long totalPrice, final Long favoriteCount,
final Boolean favorite) {
final Boolean favorite,
final LocalDateTime createdAt) {
this.id = id;
this.images = images;
this.title = title;
Expand All @@ -31,10 +34,11 @@ private RecipeDetailResponse(final Long id, final List<String> images, final Str
this.totalPrice = totalPrice;
this.favoriteCount = favoriteCount;
this.favorite = favorite;
this.createdAt = createdAt;
}

public static RecipeDetailResponse toResponse(final Recipe recipe, final List<RecipeImage> recipeImages,
final List<Product> products, final Long totalPrice, final Boolean favorite) {
final List<Product> products, final Long totalPrice, final Boolean favorite) {
final RecipeAuthorDto authorDto = RecipeAuthorDto.toDto(recipe.getMember());
final List<ProductRecipeDto> productDtos = products.stream()
.map(ProductRecipeDto::toDto)
Expand All @@ -43,7 +47,7 @@ public static RecipeDetailResponse toResponse(final Recipe recipe, final List<Re
.map(RecipeImage::getImage)
.collect(Collectors.toList());
return new RecipeDetailResponse(recipe.getId(), images, recipe.getTitle(), recipe.getContent(),
authorDto, productDtos, totalPrice, recipe.getFavoriteCount(), favorite);
authorDto, productDtos, totalPrice, recipe.getFavoriteCount(), favorite, recipe.getCreatedAt());
}

public Long getId() {
Expand Down Expand Up @@ -81,4 +85,8 @@ public Long getFavoriteCount() {
public Boolean getFavorite() {
return favorite;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ class create_성공_테스트 {

// then
assertThat(actual).usingRecursiveComparison()
.ignoringFields("id")
.ignoringFields("id", "createdAt")
.isEqualTo(expected);
assertThat(actual.getCreatedAt()).isNotNull();
}
}

Expand Down
Loading