Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Mojacknong/Farmus-Spring int…
Browse files Browse the repository at this point in the history
…o fix_52/채소-일기
  • Loading branch information
Ryeolee committed Jul 31, 2024
2 parents 2cc23fd + 2419930 commit 81085e5
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 48 deletions.
25 changes: 15 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,25 @@ tasks.named('test') {
useJUnitPlatform()
}

// Querydsl 설정부
def generated = 'src/main/generated'

// querydsl QClass 파일 생성 위치를 지정
tasks.withType(JavaCompile) {
options.getGeneratedSourceOutputDirectory().set(file(generated))
test {
useJUnitPlatform()
}

// java source set 에 querydsl QClass 위치 추가
def generatedDir = "src/main/generated"


sourceSets {
main.java.srcDirs += [ generated ]
main {
java {
srcDirs = ['src/main/java']
}
// Mybatis 쿼리 xml 위치때문에 조정
resources{
srcDir "${project.projectDir}/src/main/java"
}
}
}

// gradle clean 시에 QClass 디렉토리 삭제
clean {
delete file(generated)
delete file(generatedDir)
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ public BaseResponseDto<?> deleteMissionPostLike(
return BaseResponseDto.of(SuccessCode.SUCCESS, null);
}

@GetMapping("/{id}/mission")
@GetMapping("/{farmClubId}/mission")
public BaseResponseDto<?> getMissionPostList(
@PathVariable Long id
@AuthenticationPrincipal CustomUser user,
@PathVariable Long farmClubId
) {
return BaseResponseDto.of(SuccessCode.SUCCESS, missionPostService.getMissionPostList(id));
return BaseResponseDto.of(SuccessCode.SUCCESS, missionPostService.getMissionPostList(user.getUserId(), farmClubId));
}

@GetMapping("/mission/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode;
import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubEntityNotFoundException;
import com.modernfarmer.farmusspring.domain.farmclub.repository.MissionPostRepository;
import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostVo;
import com.modernfarmer.farmusspring.domain.history.vo.MissionPostHistoryVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -26,6 +27,10 @@ public List<MissionPostHistoryVo> getMissionPostHistory(Long userFarmClubId) {
return missionPostRepository.getMissionPostHistory(userFarmClubId);
}

public List<MissionPostVo> getMissionPostList(Long userId, Long missionPostId) {
return missionPostRepository.getMissionPostList(userId, missionPostId);
}

@Transactional
public void deleteMissionPostLike(Long userId, Long missionPostId) {
missionPostRepository.deleteMissionPostLike(userId, missionPostId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface MissionPostRepositoryCustom {

List<GetMissionPostListVo> getMissionPostStepNumAndImage(Long farmClubId);
List<MissionPostCommentVo> getMissionPostComment(Long missionPostId);
List<MissionPostVo> getMissionPostList(Long missionPostId);
List<MissionPostVo> getMissionPostList(Long userId, Long missionPostId);
List<MissionPostHistoryVo> getMissionPostHistory(Long missionPostId);
void deleteMissionPostLike(Long userId, Long missionPostId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<MissionPostCommentVo> getMissionPostComment(Long missionPostId) {
}

@Override
public List<MissionPostVo> getMissionPostList(Long farmClubId) {
public List<MissionPostVo> getMissionPostList(Long userId, Long farmClubId) {

return queryFactory
.select(new QMissionPostVo(
Expand All @@ -62,7 +62,13 @@ public List<MissionPostVo> getMissionPostList(Long farmClubId) {
.where(missionPostLike.missionPost.eq(missionPost)),
JPAExpressions.select(missionPostComment.count())
.from(missionPostComment)
.where(missionPostComment.missionPost.eq(missionPost))))
.where(missionPostComment.missionPost.eq(missionPost)),
JPAExpressions.selectOne()
.from(missionPostLike)
.where(missionPostLike.missionPost.eq(missionPost)
.and(missionPostLike.user.id.eq(userId)))
.exists()
))
.from(missionPost)
.join(missionPost.userFarmClub, userFarmClub)
.join(userFarmClub.myVeggie, myVeggie)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void deleteMissionPostLike(Long userId, Long missionPostId) {
missionPostHelper.deleteMissionPostLike(userId, missionPostId);
}

public GetMissionPostListResponseDto getMissionPostList(Long farmClubId) {
List<MissionPostVo> missionPosts = missionPostRepository.getMissionPostList(farmClubId);
public GetMissionPostListResponseDto getMissionPostList(Long userId, Long farmClubId) {
List<MissionPostVo> missionPosts = missionPostHelper.getMissionPostList(userId, farmClubId);
return GetMissionPostListResponseDto.of(missionPosts);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public record MissionPostVo(
String image,
String content,
Long likeCount,
Long commentCount
Long commentCount,
Boolean isLiked
) {
@QueryProjection
public MissionPostVo(MissionPost missionPost, User user, Long likeCount, Long commentCount)
public MissionPostVo(MissionPost missionPost, User user, Long likeCount, Long commentCount, Boolean isLiked)
{
this(
missionPost.getId(),
Expand All @@ -25,7 +26,8 @@ public MissionPostVo(MissionPost missionPost, User user, Long likeCount, Long co
missionPost.getImage(),
missionPost.getContent(),
likeCount,
commentCount
commentCount,
isLiked
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public BaseResponseDto<CheckTodayDiaryResponse> checkTodayDiary(
}

@GetMapping(value = "/{myVeggieId}/one")
public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(
@PathVariable("myVeggieId") Long myVeggieId
) {
public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(@PathVariable("myVeggieId") Long myVeggieId) {
return myVeggieDiaryService.selectDiaryOne(MyVeggie.builder().id(myVeggieId).build());
}

Expand Down Expand Up @@ -105,14 +103,9 @@ public BaseResponseDto<?> cancelLike(
return BaseResponseDto.of(SuccessCode.SUCCESS, null);
}

@GetMapping(value = "/{diaryId}/{farmClubId}/comment")
public BaseResponseDto<?> selectComment(
@AuthenticationPrincipal CustomUser user,
@PathVariable("diaryId") Long diaryId,
@PathVariable("farmClubId") Long farmClubId
) {
List<DiaryCommentContent> diaryCommentList = myVeggieDiaryService.selectComment(user.getUserId(), diaryId, farmClubId);

@GetMapping(value = "/{diaryId}/comment")
public BaseResponseDto<?> selectComment(@AuthenticationPrincipal CustomUser user, @PathVariable("diaryId") Long diaryId) {
List<DiaryCommentContent> diaryCommentList = myVeggieDiaryService.selectComment(user.getUserId(), diaryId);
return BaseResponseDto.of(SuccessCode.SUCCESS, diaryCommentList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public BaseResponseDto<?> checkVeggieRoutine(@Validated @RequestBody RoutineChec
}

@GetMapping(value = "/{myVeggieId}")
public BaseResponseDto<?> selectMyVeggieRoutineById(
@PathVariable("myVeggieId") Long myVeggieId
) {
public BaseResponseDto<?> selectRoutineToday(@PathVariable("myVeggieId") Long myVeggieId) {
MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build();
List<MyVeggieRoutine> result = myVeggieRoutineService.selectMyVeggieRoutineById(myVeggie);
return BaseResponseDto.of(SuccessCode.SUCCESS, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ public interface DiaryRepository extends JpaRepository<Diary, Long> {
"JOIN FETCH dc.diary AS d " +
"JOIN FETCH d.myVeggie AS mv " +
"JOIN FETCH mv.user " +
"JOIN FETCH d.farmClub " +
"WHERE d.id = :diaryId AND d.farmClub.id = :farmClubId AND d.isOpen = true")
List<DiaryComment> findDiary(@Param("diaryId") Long diaryId, @Param("farmClubId") Long farmClubId);
"WHERE d.id = :diaryId")
List<DiaryComment> findDiaryById(@Param("diaryId") Long diaryId);


@Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll(d, " +
Expand All @@ -60,4 +59,9 @@ public interface DiaryRepository extends JpaRepository<Diary, Long> {
"ORDER BY d.createdDate DESC")
List<DiaryAll> findDiariesByMyVeggie(@Param("myVeggie") MyVeggie myVeggie, @Param("userId") Long userId);

@Query("SELECT d FROM diary AS d WHERE d.myVeggie = :myVeggie AND FUNCTION('DATE', d.createdDate) = CURRENT_DATE")
List<Diary> findDiaryByToday(@Param("myVeggie") MyVeggie myVeggie);



}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ public interface RoutineRepository extends JpaRepository<Routine, Long> {
"FUNCTION('YEAR', r.date) = FUNCTION('YEAR', :month) AND FUNCTION('MONTH', r.date) = FUNCTION('MONTH', :month)")
List<Routine> findRoutineAndRoutineAndMyVeggieByMonthWithUser(@Param("month") Date month, @Param("user") User user );


@Query("SELECT r FROM routine AS r WHERE r.myVeggie = :myVeggie AND r.date = CURRENT_DATE")
List<Routine> findRoutineByIdAndToday(@Param("myVeggie") MyVeggie myVeggie);
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ public void updateComment(User user, Long diaryCommentId, String content) {
myVeggieRepository.updateDiaryCommentByIdAndUserId(diaryCommentId, user, content);
}
@Transactional
public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(
MyVeggie myVeggie
) {
List<Diary> diaryList = selectDiaryByMyVeggie(myVeggie);
public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(MyVeggie myVeggie) {
List<Diary> diaryList = diaryRepository.findDiaryByToday(myVeggie);
if(diaryList.isEmpty()) {
return BaseResponseDto.of(MyVeggieGardenSuccessCode.NOT_FOUND_DIARY, null);
}
Expand All @@ -161,11 +159,8 @@ public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(


@Transactional
public List<DiaryCommentContent> selectComment(
Long userId, Long diaryId, Long farmClubId
) {

List<DiaryComment> diaryCommentList = diaryRepository.findDiary(diaryId, farmClubId);
public List<DiaryCommentContent> selectComment(Long userId, Long diaryId) {
List<DiaryComment> diaryCommentList = diaryRepository.findDiaryById(diaryId);
List<DiaryCommentContent> diaryCommentContent = DiaryCommentContent.processData(diaryCommentList, userId);
return diaryCommentContent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void eraseRoutine(RoutineDelete routineDelete) {

@Transactional
public List<MyVeggieRoutine> selectMyVeggieRoutineById(MyVeggie myVeggie) {
List<Routine> routineList = myVeggieRepository.findMyVeggieRoutineById(myVeggie);
List<Routine> routineList = routineRepository.findRoutineByIdAndToday(myVeggie);
return MyVeggieRoutine.processData(routineList);
}

Expand Down

0 comments on commit 81085e5

Please sign in to comment.