Skip to content

Commit

Permalink
v2.0.2 (#61)
Browse files Browse the repository at this point in the history
v2.0.2
  • Loading branch information
Go-Jaecheol authored Jun 7, 2024
2 parents 239b076 + 9ec1ed0 commit 4aba8e5
Show file tree
Hide file tree
Showing 58 changed files with 1,611 additions and 268 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ jobs:

steps:
- name: Repository 체크아웃
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: JDK 21 설정
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 21
distribution: corretto

- name: Gradle 캐싱
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand All @@ -45,13 +45,13 @@ jobs:
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: '**/backend/build/test-results/test/TEST-*.xml'
files: '**/build/test-results/test/TEST-*.xml'

- name: 테스트 실패 시, 실패한 코드 라인에 Check 코멘트를 등록
uses: mikepenz/action-junit-report@v3
uses: mikepenz/action-junit-report@v4
if: always()
with:
report_paths: '**/backend/build/test-results/test/TEST-*.xml'
report_paths: '**/build/test-results/test/TEST-*.xml'
token: ${{ github.token }}

- name: build 실패 시 Slack으로 알립니다
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/funeat/member/application/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.funeat.member.exception.MemberException.MemberNotFoundException;
import com.funeat.member.persistence.MemberRepository;
import java.util.Objects;

import com.funeat.recipe.persistence.RecipeRepository;
import com.funeat.review.persistence.ReviewRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -22,10 +25,15 @@
public class MemberService {

private final MemberRepository memberRepository;
private final ReviewRepository reviewRepository;
private final RecipeRepository recipeRepository;
private final ImageUploader imageUploader;

public MemberService(final MemberRepository memberRepository, final ImageUploader imageUploader) {
public MemberService(final MemberRepository memberRepository, final ReviewRepository reviewRepository,
final RecipeRepository recipeRepository, final ImageUploader imageUploader) {
this.memberRepository = memberRepository;
this.reviewRepository = reviewRepository;
this.recipeRepository = recipeRepository;
this.imageUploader = imageUploader;
}

Expand All @@ -49,7 +57,10 @@ public MemberProfileResponse getMemberProfile(final Long memberId) {
final Member findMember = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOT_FOUND, memberId));

return MemberProfileResponse.toResponse(findMember);
final Long reviewCount = reviewRepository.countByMember(findMember);
final Long recipeCount = recipeRepository.countByMember(findMember);

return MemberProfileResponse.toResponse(findMember, reviewCount, recipeCount);
}

@Transactional
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/funeat/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.funeat.member.exception.MemberErrorCode.MEMBER_UPDATE_ERROR;

import com.funeat.member.domain.bookmark.RecipeBookmark;
import com.funeat.member.domain.favorite.RecipeFavorite;
import com.funeat.member.domain.favorite.ReviewFavorite;
import com.funeat.member.exception.MemberException.MemberUpdateException;
Expand Down Expand Up @@ -34,6 +35,9 @@ public class Member {
@OneToMany(mappedBy = "member")
private List<RecipeFavorite> recipeFavorites;

@OneToMany(mappedBy = "member")
private List<RecipeBookmark> recipeBookmarks;

protected Member() {
}

Expand Down Expand Up @@ -71,6 +75,10 @@ public List<RecipeFavorite> getRecipeFavorites() {
return recipeFavorites;
}

public List<RecipeBookmark> getRecipeBookmarks() {
return recipeBookmarks;
}

public void modifyProfile(final String nickname, final String profileImage) {
if (!StringUtils.hasText(nickname) || Objects.isNull(profileImage)) {
throw new MemberUpdateException(MEMBER_UPDATE_ERROR);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.funeat.member.domain.bookmark;

import com.funeat.member.domain.Member;
import com.funeat.recipe.domain.Recipe;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"member_id", "recipe_id"}))
public class RecipeBookmark {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recipe_id")
private Recipe recipe;

private Boolean bookmark;

protected RecipeBookmark() {
}

public RecipeBookmark(final Member member, final Recipe recipe, final Boolean bookmark) {
this.member = member;
this.recipe = recipe;
this.bookmark = bookmark;
}

public static RecipeBookmark create(final Member member, final Recipe recipe, final Boolean bookmark) {
return new RecipeBookmark(member, recipe, bookmark);
}

public void updateBookmark(final Boolean bookmark) {
this.bookmark = bookmark;
}

public Long getId() {
return id;
}

public Member getMember() {
return member;
}

public Recipe getRecipe() {
return recipe;
}

public Boolean getBookmark() {
return bookmark;
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/funeat/member/dto/MemberBookmarkRecipeDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.funeat.member.dto;

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;

public record MemberBookmarkRecipeDto(
Long id,
String title,
String image,
String content,
Boolean favorite,
MemberResponse author,
MemberBookmarkRecipeProductsDto products,
LocalDateTime createdAt
) {

private MemberBookmarkRecipeDto(final Long id, final String title, final String content, final Boolean favorite,
final MemberResponse author, final MemberBookmarkRecipeProductsDto products,
final LocalDateTime createdAt) {
this(id, title, null, content, favorite, author, products, createdAt);
}

public static MemberBookmarkRecipeDto toDto(final Recipe recipe, final List<RecipeImage> findRecipeImages,
final List<Product> recipeInProducts, final Boolean isFavorite) {
final MemberResponse author = MemberResponse.toResponse(recipe.getMember());
final MemberBookmarkRecipeProductsDto products = MemberBookmarkRecipeProductsDto.toDto(recipeInProducts);

if (findRecipeImages.isEmpty()) {
return new MemberBookmarkRecipeDto(recipe.getId(), recipe.getTitle(), recipe.getContent(), isFavorite,
author, products, recipe.getCreatedAt()
);
}
return new MemberBookmarkRecipeDto(recipe.getId(), recipe.getTitle(), findRecipeImages.get(0).getImage(),
recipe.getContent(), isFavorite, author, products, recipe.getCreatedAt()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.funeat.member.dto;

import com.funeat.product.domain.Product;

public record MemberBookmarkRecipeProductDto(
Long id,
String name,
Long price,
String image,
Double averageRating
) {

public static MemberBookmarkRecipeProductDto toDto(final Product product) {
return new MemberBookmarkRecipeProductDto(product.getId(), product.getName(), product.getPrice(),
product.getImage(), product.getAverageRating());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.funeat.member.dto;

import com.funeat.product.domain.Product;

import java.util.List;

public record MemberBookmarkRecipeProductsDto(
List<MemberBookmarkRecipeProductDto> products
) {

public static MemberBookmarkRecipeProductsDto toDto(final List<Product> recipeInProducts) {
final List<MemberBookmarkRecipeProductDto> products = recipeInProducts.stream()
.map(MemberBookmarkRecipeProductDto::toDto)
.toList();

return new MemberBookmarkRecipeProductsDto(products);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.funeat.member.dto;

import com.funeat.common.dto.PageDto;

import java.util.List;

public record MemberBookmarkRecipesResponse(
PageDto page,
List<MemberBookmarkRecipeDto> recipes
) {

public static MemberBookmarkRecipesResponse toResponse(final PageDto page,
final List<MemberBookmarkRecipeDto> recipes) {
return new MemberBookmarkRecipesResponse(page, recipes);
}
}
19 changes: 16 additions & 3 deletions src/main/java/com/funeat/member/dto/MemberProfileResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ public class MemberProfileResponse {

private final String nickname;
private final String profileImage;
private final Long reviewCount;
private final Long recipeCount;

public MemberProfileResponse(final String nickname, final String profileImage) {
public MemberProfileResponse(final String nickname, final String profileImage,
final Long reviewCount, final Long recipeCount) {
this.nickname = nickname;
this.profileImage = profileImage;
this.reviewCount = reviewCount;
this.recipeCount = recipeCount;
}

public static MemberProfileResponse toResponse(final Member member) {
return new MemberProfileResponse(member.getNickname(), member.getProfileImage());
public static MemberProfileResponse toResponse(final Member member, final Long reviewCount, final Long recipeCount) {
return new MemberProfileResponse(member.getNickname(), member.getProfileImage(), reviewCount, recipeCount);
}

public String getNickname() {
Expand All @@ -23,4 +28,12 @@ public String getNickname() {
public String getProfileImage() {
return profileImage;
}

public Long getReviewCount() {
return reviewCount;
}

public Long getRecipeCount() {
return recipeCount;
}
}
41 changes: 18 additions & 23 deletions src/main/java/com/funeat/member/dto/MemberRecipeDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,35 @@ public class MemberRecipeDto {
private final Long id;
private final String title;
private final String content;
private final MemberResponse author;
private final LocalDateTime createdAt;
private final String image;
private final Long favoriteCount;
private final List<MemberRecipeProductDto> products;

private MemberRecipeDto(final Long id, final String title, final String content, final LocalDateTime createdAt,
final Long favoriteCount, final List<MemberRecipeProductDto> products) {
this(id, title, content, createdAt, null, favoriteCount, products);
private MemberRecipeDto(final Long id, final String title, final String content, final MemberResponse author,
final LocalDateTime createdAt) {
this(id, title, content, author, createdAt, null);
}

@JsonCreator
private MemberRecipeDto(final Long id, final String title, final String content, final LocalDateTime createdAt,
final String image, final Long favoriteCount, final List<MemberRecipeProductDto> products) {
private MemberRecipeDto(final Long id, final String title, final String content, final MemberResponse author,
final LocalDateTime createdAt, final String image) {
this.id = id;
this.title = title;
this.content = content;
this.author = author;
this.createdAt = createdAt;
this.image = image;
this.favoriteCount = favoriteCount;
this.products = products;
}

public static MemberRecipeDto toDto(final Recipe recipe, final List<RecipeImage> findRecipeImages,
final List<MemberRecipeProductDto> memberRecipeProductDtos) {
public static MemberRecipeDto toDto(final Recipe recipe, final List<RecipeImage> findRecipeImages) {
final MemberResponse author = MemberResponse.toResponse(recipe.getMember());

if (findRecipeImages.isEmpty()) {
return new MemberRecipeDto(recipe.getId(), recipe.getTitle(), recipe.getContent(), recipe.getCreatedAt(),
recipe.getFavoriteCount(), memberRecipeProductDtos);
return new MemberRecipeDto(recipe.getId(), recipe.getTitle(), recipe.getContent(),author,
recipe.getCreatedAt());
}
return new MemberRecipeDto(recipe.getId(), recipe.getTitle(), recipe.getContent(), recipe.getCreatedAt(),
findRecipeImages.get(0).getImage(), recipe.getFavoriteCount(), memberRecipeProductDtos);
return new MemberRecipeDto(recipe.getId(), recipe.getTitle(), recipe.getContent(), author,
recipe.getCreatedAt(), findRecipeImages.get(0).getImage());
}

public Long getId() {
Expand All @@ -55,19 +54,15 @@ public String getContent() {
return content;
}

public MemberResponse getAuthor() {
return author;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

public String getImage() {
return image;
}

public Long getFavoriteCount() {
return favoriteCount;
}

public List<MemberRecipeProductDto> getProducts() {
return products;
}
}
Loading

0 comments on commit 4aba8e5

Please sign in to comment.