Skip to content

Commit

Permalink
Conflict Resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
HyoBN committed Oct 1, 2023
2 parents 792ddd5 + a5dc21e commit f8b0f8b
Show file tree
Hide file tree
Showing 20 changed files with 501 additions and 19 deletions.
10 changes: 8 additions & 2 deletions src/main/java/zipdabang/server/base/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public enum Code {
ALREADY_BLOCKED_MEMBER(HttpStatus.OK, 4062, "이미 차단된 사용자입니다."),
BLOCK_SELF(HttpStatus.OK, 4063, "자신을 차단할 수 없습니다."),

// BAD_REQUEST
TARGET_MEMBER_NOT_FOUND(HttpStatus.OK, 4064,"대상 사용자가 없습니다.."),

//FORBIDDEN
SELF_FOLLOW_FORBIDDEN(HttpStatus.OK, 4065, "스스로 팔로우는 안됩니다."),

// market error

Expand All @@ -115,11 +119,13 @@ public enum Code {
//BAD_REQUEST
NOT_COMMENT_OWNER(HttpStatus.OK, 4108, "본인이 작성한 댓글이 아닙니다. 변경할 수 없습니다"),
//BAD_REQUEST
RECIPE_OWNER(HttpStatus.OK, 4109, "본인의 레시피입니다. 신고/차단할 수 없습니다"),
RECIPE_OWNER(HttpStatus.OK, 4109, "본인의 레시피입니다. 좋아요/스크랩/신고/차단할 수 없습니다"),
//BAD_REQUEST
COMMENT_OWNER(HttpStatus.OK, 4110, "본인의 댓글입니다. 신고/차단할 수 없습니다"),
COMMENT_OWNER(HttpStatus.OK, 4110, "본인의 댓글입니다. 좋아요/스크랩/신고/차단할 수 없습니다"),
//BAD_REQUEST
NO_TEMP_RECIPE_EXIST(HttpStatus.OK, 4111, "해당 임시저장 Id가 존재하지 않습니다."),


//INTERNAL_SERVER_ERROR
INTERNAL_ERROR(HttpStatus.OK, 5000, "Internal server Error"),
//INTERNAL_SERVER_ERROR
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/zipdabang/server/converter/MemberConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,65 @@ public static MemberResponseDto.PagingMemberListDto toPagingMemberListDto(Page<M
.build();
}

public static Follow toFollow(){
return Follow.builder().build();
}

public static MemberResponseDto.FollowingResultDto toFollowingResultDto(Follow follow){
return MemberResponseDto.FollowingResultDto.builder()
.targetId(follow.getTargetMember().getMemberId())
.followAt(LocalDateTime.now())
.build();
}

public static MemberResponseDto.FollowInfoDto toFollowInfoDto(Member member){
return MemberResponseDto.FollowInfoDto.builder()
.id(member.getMemberId())
.caption(member.getCaption())
.nickname(member.getNickname())
.imageUrl(member.getProfileUrl())
.build();
}

public static MemberResponseDto.FollowerInfoDto toFollowerInfoDto(Member member, Member owner){

List<Member> followingMembers = owner.getFollowingList().stream()
.map(Follow::getTargetMember).collect(Collectors.toList());

return MemberResponseDto.FollowerInfoDto.builder()
.id(member.getMemberId())
.caption(member.getCaption())
.nickname(member.getNickname())
.imageUrl(member.getProfileUrl())
.isFollowing(followingMembers.contains(member))
.build();
}

public static MemberResponseDto.FollowingListDto toFollowingListDto(Page<Follow> followList){
List<MemberResponseDto.FollowInfoDto> followInfoDtoList = followList.stream()
.map(follow -> toFollowInfoDto(follow.getTargetMember())).collect(Collectors.toList());

return MemberResponseDto.FollowingListDto.builder()
.followingList(followInfoDtoList)
.isFirst(followList.isFirst())
.isLast(followList.isLast())
.totalPage(followList.getTotalPages())
.totalElements(followList.getTotalElements())
.currentPageElements(followList.getNumberOfElements())
.build();
}

public static MemberResponseDto.FollowerListDto toFollowerListDto(Page<Follow> followList, Member owner){
List<MemberResponseDto.FollowerInfoDto> followerInfoDtoList = followList.stream()
.map(follow -> toFollowerInfoDto(follow.getFollowingMember(), owner)).collect(Collectors.toList());

return MemberResponseDto.FollowerListDto.builder()
.followerList(followerInfoDtoList)
.isFirst(followList.isFirst())
.isLast(followList.isLast())
.totalPage(followList.getTotalPages())
.totalElements(followList.getTotalElements())
.currentPageElements(followList.getNumberOfElements())
.build();
}
}
22 changes: 22 additions & 0 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ public class RecipeConverter {
private static AmazonS3Manager staticAmazonS3Manager;
private static TimeConverter staticTimeConverter;

public static RecipeResponseDto.PerCategoryPreview toPerCategoryPreview(Long categoryId, List<Recipe> recipeList, Member member) {
return RecipeResponseDto.PerCategoryPreview.builder()
.categoryId(categoryId)
.totalElements(recipeList.size())
.recipeList(recipeList.stream()
.map(recipe -> toRecipePreviewDto(recipe,member))
.collect(Collectors.toList()))
.build();
}

public static RecipeResponseDto.RecipePreviewDto toRecipePreviewDto(Recipe recipe, Member member) {
return RecipeResponseDto.RecipePreviewDto.builder()
.recipeId(recipe.getId())
.recipeName(recipe.getName())
.nickname(recipe.getMember().getNickname())
.likes(recipe.getTotalLike())
.scraps(recipe.getTotalScrap())
.isLiked(staticLikesRepository.findByRecipeAndMember(recipe, member).isPresent())
.isScrapped(staticScrapRepository.findByRecipeAndMember(recipe,member).isPresent())
.build();
}


@PostConstruct
public void init() {
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/zipdabang/server/domain/member/Follow.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,28 @@ public class Follow extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// follow 객체
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_id")
private Member member;
private Member targetMember;

// follow 주체
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "following_id")
private Member followingMember;

public void setTargetMember(Member targetMember){
if (this.targetMember != null)
targetMember.getFollowerList().remove(this);
this.targetMember = targetMember;
targetMember.getFollowerList().add(this);
}

public void setFollowingMember(Member followingMember){
if (this.followingMember != null)
followingMember.getFollowerList().remove(this);
this.followingMember = followingMember;
followingMember.getFollowerList().add(this);
}

}
9 changes: 9 additions & 0 deletions src/main/java/zipdabang/server/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Member extends BaseEntity {
@Column(length = 18)
private String phoneNum;

private String caption;

@Column(length = 6)
private String birth;

Expand Down Expand Up @@ -107,6 +109,13 @@ public class Member extends BaseEntity {
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Inquery> inqueryList;

// 나를 따르는 = follow 테이블에서 targetMember가 나인,
@OneToMany(mappedBy = "targetMember", cascade = CascadeType.ALL)
private List<Follow> followerList;

// 내가 따르는 = follow 테이블에서 followingMember가 나인,
@OneToMany(mappedBy = "followingMember", cascade = CascadeType.ALL)
private List<Follow> followingList;

public void setProfileUrl(String profileUrl) {
this.profileUrl = profileUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package zipdabang.server.repository.memberRepositories;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import zipdabang.server.domain.member.Follow;
import zipdabang.server.domain.member.Member;

public interface FollowRepository extends JpaRepository<Follow, Long> {

Page<Follow> findAllByTargetMember(Member member, PageRequest pageRequest);
Page<Follow> findAllByFollowingMember(Member member, PageRequest pageRequest);
}
9 changes: 9 additions & 0 deletions src/main/java/zipdabang/server/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import zipdabang.server.domain.Category;
import zipdabang.server.domain.member.Follow;
import zipdabang.server.domain.member.Inquery;
import zipdabang.server.domain.enums.DeregisterType;
import zipdabang.server.domain.member.Member;
Expand All @@ -22,6 +23,8 @@ public interface MemberService {

Optional<Member> checkExistNickname(String nickname);

Optional<Member> findMemberById(Long id);

public void existByPhoneNumber(String phoneNum);

OAuthJoin.OAuthJoinDto joinInfoComplete(MemberRequestDto.MemberInfoDto request, String type);
Expand Down Expand Up @@ -56,4 +59,10 @@ public interface MemberService {
public void blockMember(Member owner, Long blocked);
public void unblockMember(Member owner, Long blockedId);
public Page<Member> findBlockedMember(Integer page, Member member);

public Follow createFollow(Long targetId, Member member);

Page<Follow> findFollowing(Member member, Integer page);

Page<Follow> findFollower(Member member, Integer page);
}
2 changes: 2 additions & 0 deletions src/main/java/zipdabang/server/service/RecipeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ public interface RecipeService {
TempRecipe tempCreate(RecipeRequestDto.TempRecipeDto request, MultipartFile thumbnail, List<MultipartFile> stepImages, Member member) throws IOException;

TempRecipe tempUpdate(Long tempId, RecipeRequestDto.TempRecipeDto request, MultipartFile thumbnail, List<MultipartFile> stepImages, Member member) throws IOException;

List<Recipe> getTop5RecipePerCategory(Long categoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public class MemberServiceImpl implements MemberService {
private final DeregisterRepository deregisterRepository;
private final DeregisterReasonRepository deregisterReasonRepository;
private final BlockedMemberRepository blockedMemberRepository;
<<<<<<< HEAD
=======

private final FollowRepository followRepository;
>>>>>>> a5dc21e0132e8f3e84329ab4d71729bbff08fef8

@Value("${paging.size}")
private Integer pageSize;
Expand Down Expand Up @@ -120,6 +125,11 @@ public Optional<Member> checkExistNickname(String nickname){
return memberRepository.findByNickname(nickname);
}

@Override
public Optional<Member> findMemberById(Long id) {
return memberRepository.findById(id);
}

@Override
public void existByPhoneNumber(String phoneNum) {
if (memberRepository.existsByPhoneNum(phoneNum)) {
Expand Down Expand Up @@ -356,6 +366,40 @@ public Page<Member> findBlockedMember(Integer page, Member member) {
return blockedMembers;

}

@Override
@Transactional
public Follow createFollow(Long targetId, Member member) {

if(targetId.equals(member.getMemberId()))
throw new MemberException(Code.SELF_FOLLOW_FORBIDDEN);
Follow follow = MemberConverter.toFollow();
follow.setFollowingMember(member);
follow.setTargetMember(memberRepository.findById(targetId).get());
return followRepository.save(follow);
}

@Override
public Page<Follow> findFollowing(Member member, Integer page) {
page -= 1;
Page<Follow> followingMember = followRepository.findAllByFollowingMember(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt")));

if(followingMember.getTotalPages() <= page)
throw new MemberException(Code.OVER_PAGE_INDEX_ERROR);

return followingMember;
}

@Override
public Page<Follow> findFollower(Member member, Integer page) {
page -= 1;
Page<Follow> followerMember = followRepository.findAllByTargetMember(member, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "createdAt")));

if(followerMember.getTotalPages() <= page)
throw new MemberException(Code.OVER_PAGE_INDEX_ERROR);

return followerMember;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import static zipdabang.server.domain.recipe.QComment.comment;
Expand Down Expand Up @@ -306,6 +307,9 @@ private List<Member> getBlockedMember(Member member) {
public Recipe updateLikeOnRecipe(Long recipeId, Member member) {
Recipe recipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST));

if(recipe.getMember() == member)
throw new RecipeException(Code.RECIPE_OWNER);

Optional<Likes> likesExist = likesRepository.findByRecipeAndMember(recipe,member);

if(likesExist.isEmpty()) {
Expand All @@ -325,6 +329,9 @@ public Recipe updateLikeOnRecipe(Long recipeId, Member member) {
public Recipe updateScrapOnRecipe(Long recipeId, Member member) {
Recipe recipe = recipeRepository.findById(recipeId).orElseThrow(() -> new RecipeException(Code.NO_RECIPE_EXIST));

if(recipe.getMember() == member)
throw new RecipeException(Code.RECIPE_OWNER);

Optional<Scrap> scrapExist = scrapRepository.findByRecipeAndMember(recipe,member);

if(scrapExist.isEmpty()) {
Expand All @@ -344,6 +351,27 @@ public List<RecipeCategory> getAllRecipeCategories() {
return recipeCategoryRepository.findAll();
}

@Override
public List<Recipe> getTop5RecipePerCategory(Long categoryId) {
QRecipe qRecipe = recipe;
QRecipeCategoryMapping qRecipeCategoryMapping = recipeCategoryMapping;

AtomicLong index = new AtomicLong(1);
List<Recipe> recipeList = queryFactory
.selectFrom(recipe)
.join(recipe.categoryMappingList, recipeCategoryMapping).fetchJoin()
.where(
recipeCategoryMapping.category.id.eq(categoryId)
)
.limit(5)
.orderBy(recipe.totalLike.desc(), recipe.createdAt.desc())
.fetch();

log.info(recipeList.toString());

return recipeList;
}

@Override
public Page<Recipe> recipeListByCategory(Long categoryId, Integer pageIndex, Member member, String order) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package zipdabang.server.validation.annotation;

import zipdabang.server.validation.validator.ExistMemberRequestBodyValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

@Documented
@Constraint(validatedBy = ExistMemberRequestBodyValidator.class)
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface ExistMember {
String message() default "해당하는 유저가 존재하지 않습니다.";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package zipdabang.server.validation.annotation;


import zipdabang.server.validation.validator.ExistRecipeCategoryValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

@Documented
@Constraint(validatedBy = ExistRecipeCategoryValidator.class)
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface ExistRecipeCategory {
String message() default "범위에 없는 categoryId를 전달했습니다.";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Loading

0 comments on commit f8b0f8b

Please sign in to comment.