Skip to content

Commit

Permalink
Merge pull request #100 from WOONGEYA/feat
Browse files Browse the repository at this point in the history
Feat
  • Loading branch information
Woongbin06 authored Dec 13, 2023
2 parents 4cc8784 + 0d51b74 commit 984e388
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void execute(Long id) {
.build()
);

notificationRepository.deleteByApplicationId(id);
applicationRepository.delete(application);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CommentResponse {
private String content;
private LocalDateTime createTime;
private Long userId;
private String userName;
private String userNickName;
private String userImg;
private Integer reCommentCount;

Expand All @@ -26,7 +26,7 @@ public static CommentResponse of(Comment comment, User user) {
.createTime(comment.getCreateTime())
.reCommentCount(comment.getReCommentCount())
.userId(user.getId())
.userName(user.getName())
.userNickName(user.getNickName())
.userImg(user.getImgUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ReCommentResponse {
private String content;
private LocalDateTime createTime;
private Long userId;
private String userName;
private String userNickName;
private String userImg;

public static ReCommentResponse of(ReComment reComment, User user) {
Expand All @@ -24,7 +24,7 @@ public static ReCommentResponse of(ReComment reComment, User user) {
.content(reComment.getContent())
.createTime(reComment.getCreateTime())
.userId(user.getId())
.userName(user.getName())
.userNickName(user.getNickName())
.userImg(user.getImgUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Optional;

public interface LikeRepository extends JpaRepository<Like, Long> {
void deleteByProjectId(Long projectId);
Optional<Like> findByUserIdAndProjectId(Long userId, Long projectId);
List<Like> findByProjectId(Long projectId);
List<Like> findByUserId(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;

public interface NotificationRepository extends JpaRepository<Notification, Long> {
void deleteByApplicationId(Long applicationId);
Long countByToUserIdAndState(Long toUserId, NotificationState state);
List<Notification> findByToUserId(Long toUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DeleteAllNotificationService {

public void execute() {
User user = userFacade.getCurrentUser();
List<Notification> notifications = notificationRepository.findByUserId(user.getId());
List<Notification> notifications = notificationRepository.findByToUserId(user.getId());

notificationRepository.deleteAll(notifications);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PostResponse {
private String postImg;
private LocalDateTime createTime;
private Long userId;
private String userName;
private String userNickName;
private String userImg;

public static PostResponse of(Post post, User user) {
Expand All @@ -32,7 +32,7 @@ public static PostResponse of(Post post, User user) {
.createTime(post.getCreateTime())
.viewCount(post.getViewCount())
.userId(user.getId())
.userName(user.getName())
.userNickName(user.getNickName())
.userImg(user.getImgUrl())
.commentCount(post.getCommentCount())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface CustomProjectRepository {
List<Project> findProjectLikeDesc();

List<Project> findProjectByStateLikeDesc(ProjectState state);

List<Project> findMyApplicationProject(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.woongeya.zoing.domain.project.domain.repository;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.woongeya.zoing.domain.application.domain.QApplication;
import com.woongeya.zoing.domain.project.domain.Project;
import com.woongeya.zoing.domain.project.domain.type.ProjectState;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.woongeya.zoing.domain.application.domain.QApplication.application;
import static com.woongeya.zoing.domain.like.domain.QLike.like;
import static com.woongeya.zoing.domain.project.domain.QMember.member;
import static com.woongeya.zoing.domain.project.domain.QProject.project;
Expand Down Expand Up @@ -43,7 +45,7 @@ public List<Project> findProjectLikeDesc() {
.selectFrom(project)
.leftJoin(like).on(project.id.eq(like.projectId))
.groupBy(project)
.orderBy(like.count().desc())
.orderBy(like.count().desc(), project.id.desc())
.fetch();
}

Expand All @@ -54,7 +56,17 @@ public List<Project> findProjectByStateLikeDesc(ProjectState state) {
.leftJoin(like).on(project.id.eq(like.projectId))
.where(project.state.eq(state))
.groupBy(project)
.orderBy(like.count().desc())
.orderBy(like.count().desc(), project.id.desc())
.fetch();
}

@Override
public List<Project> findMyApplicationProject(Long userId) {
return jpaQueryFactory
.selectFrom(project)
.join(application).on(project.id.eq(application.projectId))
.where(application.userId.eq(userId))
.orderBy(application.id.desc())
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.woongeya.zoing.domain.project.service;

import com.woongeya.zoing.domain.application.domain.repository.ApplicationRepository;
import com.woongeya.zoing.domain.like.domain.repository.LikeRepository;
import com.woongeya.zoing.domain.project.domain.Member;
import com.woongeya.zoing.domain.project.domain.Project;
import com.woongeya.zoing.domain.project.domain.repository.*;
Expand All @@ -22,6 +23,7 @@ public class DeleteProjectService {
private final MemberRepository memberRepository;
private final CoopRepository coopRepository;
private final PositionRepository positionRepository;
private final LikeRepository likeRepository;
private final SkillRepository skillRepository;
private final MoodRepository moodRepository;
private final ProjectFacade projectFacade;
Expand All @@ -48,6 +50,7 @@ private void deleteAll(Project project) {
skillRepository.deleteByProjectId(project.getId());
coopRepository.deleteByProjectId(project.getId());
positionRepository.deleteByProjectId(project.getId());
likeRepository.deleteByProjectId(project.getId());
projectRepository.delete(project);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.woongeya.zoing.domain.project.service;

import com.woongeya.zoing.domain.application.domain.Application;
import com.woongeya.zoing.domain.application.domain.repository.ApplicationRepository;
import com.woongeya.zoing.domain.like.domain.repository.LikeRepository;
import com.woongeya.zoing.domain.project.domain.Project;
import com.woongeya.zoing.domain.project.facade.ProjectFacade;
import com.woongeya.zoing.domain.project.domain.repository.ProjectRepository;
import com.woongeya.zoing.domain.project.presetation.dto.response.ProjectResponseDto;
import com.woongeya.zoing.domain.user.UserFacade;
import com.woongeya.zoing.domain.user.domain.User;
Expand All @@ -20,17 +18,15 @@
public class FindMyApplicationProjectService {

private final UserFacade userFacade;
private final ProjectFacade projectFacade;
private final ApplicationRepository applicationRepository;
private final LikeRepository likeRepository;
private final ProjectRepository projectRepository;

@Transactional(readOnly = true)
public List<ProjectResponseDto> execute() {
User user = userFacade.getCurrentUser();
List<Application> applications = applicationRepository.findByUserId(user.getId());
List<Project> projects = projectRepository.findMyApplicationProject(user.getId());

return applications.stream()
.map(application -> projectFacade.getProject(application.getProjectId()))
return projects.stream()
.map(project -> {
Integer likeCount = likeRepository.countByProjectId(project.getId());
return ProjectResponseDto.of(project, likeCount, checkLike(project, user));
Expand Down

0 comments on commit 984e388

Please sign in to comment.