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

Bug 130/클라이언트 버그 수정 #131

Merged
merged 5 commits into from
Sep 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Slf4j
@Component
@RequiredArgsConstructor
Expand All @@ -30,6 +32,10 @@ public UserFarmClub findByUserIdAndFarmClubId(Long userId, Long farmClubId) {
.orElseThrow(() -> new FarmClubEntityNotFoundException("해당 팜클럽에 가입한 유저가 아닙니다.", FarmClubErrorCode.USER_FARM_CLUB_NOT_FOUND));
}

public Optional<UserFarmClub> findFarmClubByMyVeggieId(Long myVeggieId){
return userFarmClubRepository.findFarmClubByMyVeggieId(myVeggieId);
}

public SuccessFarmClubVo getFarmClubRecord(Long userId, Long farmClubId) {
return userFarmClubRepository.getFarmClubRecord(userId, farmClubId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface UserFarmClubRepositoryCustom {
SuccessFarmClubVo getFarmClubRecord(Long userId, Long farmClubId);

void deleteFarmClubDomain(List<MyVeggie> myVeggieList);

Optional<UserFarmClub> findFarmClubByMyVeggieId(Long myVeggieId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,20 @@ public SuccessFarmClubVo getFarmClubRecord(Long userId, Long farmClubId) {


@Override
public void deleteFarmClubDomain(List<MyVeggie> myVeggieList){
public void deleteFarmClubDomain(List<MyVeggie> myVeggieList) {
queryFactory
.delete(userFarmClub)
.where(userFarmClub.myVeggie.id.in(myVeggieList.stream().map(MyVeggie::getId).toList()))
.execute();
}

@Override
public Optional<UserFarmClub> findFarmClubByMyVeggieId(Long myVeggieId) {
return Optional.ofNullable(queryFactory
.select(userFarmClub)
.from(userFarmClub)
.where(userFarmClub.myVeggie.id.eq(myVeggieId))
.fetchOne());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
public class MyVeggieDiaryInsert {
@NotNull(message = "null 값을 가지면 안됩니다.")
String content;

Boolean isOpen;
@NotNull(message = "null 값을 가지면 안됩니다.")
String state;
@NotNull(message = "null 값을 가지면 안됩니다.")
Long myVeggieId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ public class Diary extends BaseEntity {
@JoinColumn(name = "farm_club_id")
private FarmClub farmClub;

public static Diary createDiary(String content, Boolean isOpen, String image, String state, MyVeggie myVeggie){
public static Diary createDiary(String content, Boolean isOpen, String image, String state, MyVeggie myVeggie, FarmClub farmClubId){
Diary newDiary = Diary.builder()
.content(content)
.isOpen(isOpen)
.image(image)
.state(state)
.myVeggie(myVeggie)
.farmClub(farmClubId)
.build();

myVeggie.addDiary(newDiary);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.service;

import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub;
import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub;
import com.modernfarmer.farmusspring.domain.farmclub.helper.UserFarmClubHelper;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.DiaryCommentReportDto;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.DiaryDeleteDto;
Expand Down Expand Up @@ -44,7 +47,7 @@ public class MyVeggieDiaryService {
private final MyVeggieRepository myVeggieRepository;
private final UserService userService;
private final DiaryRepository diaryRepository;
private final DiaryCommentRepository diaryCommentRepository;
private final UserFarmClubHelper userFarmClubHelper;
private final DiaryLikeRepository diaryLikeRepository;
private final UserHelper userHelper;
private final DiaryCommentHelper diaryCommentHelper;
Expand All @@ -59,12 +62,24 @@ public BaseResponseDto<Void> settingMyVeggieDiary(
Long myVeggieId
) throws IOException {
String imageUrl = getImageUrl(multipartFile);
addMyyVeggieDiary(
content,
isOpen,
imageUrl,
state,
myVeggieId
Optional<UserFarmClub> userFarmClub = userFarmClubHelper.findFarmClubByMyVeggieId(myVeggieId);
userFarmClub.ifPresentOrElse(
farmClub -> addMyyVeggieDiary(
content,
isOpen,
imageUrl,
state,
myVeggieId,
farmClub.getFarmClub()
),
() -> addMyyVeggieDiary(
content,
isOpen,
imageUrl,
state,
myVeggieId,
null
)
);
return BaseResponseDto.of(SuccessCode.SUCCESS,null);
}
Expand Down Expand Up @@ -126,12 +141,19 @@ private List<FarmClubDiary> proccessFarmClubData(List<SortedMyLikeDiary> diaryAl
user,
DateManager.dotDateTime(allDiary.getDiary().getCreatedDate()),
allDiary.getDiary().getDiaryLikes().size(),
allDiary.getDiary().getDiaryComments().size(),
distinguishReportComment(allDiary.getDiary().getDiaryComments(), user.getId()),
allDiary.isMyLike(),
allDiary.isMyDiary(),
allDiary.getDiary().getState()
);}).toList();
}

private int distinguishReportComment(List<DiaryComment> diaryCommentList, Long userId) {
return (int) diaryCommentList.stream()
.filter(comment -> comment.getDiaryCommentReports().stream()
.noneMatch(report -> report.getUser().getId().equals(userId)))
.count();
}
@Transactional
public List<AllDairy> selectDiaryAll(MyVeggie myVeggie, Long userId) {
List<SortedMyLikeDiary> diaryList = diaryRepository.findDiariesByMyVeggie(myVeggie, userId);
Expand Down Expand Up @@ -197,10 +219,11 @@ public DiaryInteractionsDto selectComment(Long userId, Long diaryId) {
List<DiaryComment> diaryCommentList = diaryRepository.findDiaryByIdWithUserId(diaryId, userId);
List<DiaryCommentContent> diaryCommentContent = DiaryCommentContent.processData(diaryCommentList, userId);
int likeCount = diaryLikeRepository.findDiaryLikeCountById(diaryId);
int commentCount = diaryCommentRepository.findDiaryCommentCountById(diaryId);
Optional<DiaryLike> diaryLike = diaryLikeRepository.findDiaryLikeByDiaryIdAndUserId(diaryId, userId);
return DiaryInteractionsDto.of(diaryCommentContent,likeCount,commentCount, diaryLike.isPresent());
return DiaryInteractionsDto.of(diaryCommentContent,likeCount,diaryCommentList.size(), diaryLike.isPresent());
}


public void insertComment(String content, User user, Diary diary){
DiaryComment diaryComment = DiaryComment.createDiaryComment(content, diary, user);
diary.addDiaryComment(diaryComment);
Expand Down Expand Up @@ -244,15 +267,17 @@ private void addMyyVeggieDiary(
Boolean isOpen,
String image,
String state,
Long myVeggieId
Long myVeggieId,
FarmClub farmClub
){
MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(myVeggieId);
Diary newDiary = Diary.createDiary(
content,
isOpen,
image,
state,
myVeggie
myVeggie,
farmClub
);
myVeggie.addDiary(newDiary);
}
Expand Down
Loading