Skip to content

Commit

Permalink
Merge pull request #660 from woowacourse-teams/dev
Browse files Browse the repository at this point in the history
데벨업 v2.0.1 Release
  • Loading branch information
lilychoibb authored Oct 11, 2024
2 parents b911df1 + 0c36920 commit 6e5cc7e
Show file tree
Hide file tree
Showing 122 changed files with 1,385 additions and 622 deletions.
2 changes: 1 addition & 1 deletion backend/secrets
3 changes: 2 additions & 1 deletion backend/src/main/java/develup/api/SolutionApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public ResponseEntity<ApiResponse<SolutionResponse>> deleteSolution(
@GetMapping("/solutions")
@Operation(summary = "솔루션 목록 조회 API", description = "솔루션 목록을 조회합니다.")
public ResponseEntity<ApiResponse<List<SummarizedSolutionResponse>>> getSolutions(
@RequestParam(defaultValue = "all") String mission,
@RequestParam(defaultValue = "all") String hashTag
) {
List<SummarizedSolutionResponse> responses = solutionReadService.getCompletedSummaries(hashTag);
List<SummarizedSolutionResponse> responses = solutionReadService.getCompletedSummaries(mission, hashTag);

return ResponseEntity.ok(new ApiResponse<>(responses));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<SummarizedDiscussionResponse> getSummaries(String mission, String ha
}

public List<SummarizedDiscussionResponse> getDiscussionsByMemberId(Long memberId) {
List<Discussion> myDiscussions = discussionRepositoryCustom.findAllByMemberId(memberId);
List<Discussion> myDiscussions = discussionRepositoryCustom.findAllByMemberIdOrderByDesc(memberId);
DiscussionCommentCounts discussionCommentCounts = new DiscussionCommentCounts(
discussionRepositoryCustom.findAllDiscussionCommentCounts()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public record SummarizedDiscussionResponse(
Long id,
String title,
String content,
String mission,
List<HashTagResponse> hashTags,
MemberResponse member,
Expand All @@ -25,6 +26,7 @@ public static SummarizedDiscussionResponse of(Discussion discussion, Long count)
return new SummarizedDiscussionResponse(
discussion.getId(),
discussion.getTitle(),
discussion.getContent(),
discussion.getMissionTitle(),
hashTagResponses,
MemberResponse.from(discussion.getMember()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import java.util.List;
import develup.api.exception.DevelupException;
import develup.api.exception.ExceptionType;
import develup.domain.discussion.DiscussionRepositoryCustom;
import develup.domain.discussion.comment.DiscussionComment;
import develup.domain.discussion.comment.DiscussionCommentCounts;
import develup.domain.discussion.comment.DiscussionCommentRepository;
import develup.domain.discussion.comment.DiscussionCommentRepositoryCustom;
import develup.domain.discussion.comment.MyDiscussionComment;
Expand All @@ -21,7 +19,6 @@ public class DiscussionCommentReadService {
private final DiscussionCommentGroupingService commentGroupingService;
private final DiscussionCommentRepositoryCustom discussionCommentRepositoryCustom;
private final DiscussionCommentRepository discussionCommentRepository;
private final DiscussionRepositoryCustom discussionRepositoryCustom;

public DiscussionComment getById(Long commentId) {
DiscussionComment comment = discussionCommentRepository.findById(commentId)
Expand All @@ -41,22 +38,10 @@ public List<DiscussionCommentRepliesResponse> getCommentsWithReplies(Long discus
}

public List<MyDiscussionCommentResponse> getMyComments(Long memberId) {
List<MyDiscussionComment> mySolutionComments = discussionCommentRepositoryCustom.findAllMyDiscussionComment(memberId);
DiscussionCommentCounts discussionCommentCounts = new DiscussionCommentCounts(
discussionRepositoryCustom.findAllDiscussionCommentCounts()
);
List<MyDiscussionComment> mySolutionComments = discussionCommentRepositoryCustom.findAllMyDiscussionCommentOrderByCreatedAtDesc(memberId);

return mySolutionComments.stream()
.map(myDiscussionComment -> mapToMyDiscussionCommentResponse(myDiscussionComment, discussionCommentCounts))
.map(MyDiscussionCommentResponse::from)
.toList();
}

private MyDiscussionCommentResponse mapToMyDiscussionCommentResponse(
MyDiscussionComment myDiscussionComment,
DiscussionCommentCounts discussionCommentCounts
) {
Long discussionId = myDiscussionComment.discussionId();
Long commentCount = discussionCommentCounts.getCount(discussionId);
return MyDiscussionCommentResponse.of(myDiscussionComment, commentCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ public record MyDiscussionCommentResponse(
Long discussionId,
String content,
LocalDateTime createdAt,
String discussionTitle,
Long discussionCommentCount
String discussionTitle
) {

public static MyDiscussionCommentResponse of(MyDiscussionComment myDiscussionComment, Long discussionCommentCount) {
public static MyDiscussionCommentResponse from(MyDiscussionComment myDiscussionComment) {
return new MyDiscussionCommentResponse(
myDiscussionComment.id(),
myDiscussionComment.discussionId(),
myDiscussionComment.content(),
myDiscussionComment.createdAt(),
myDiscussionComment.discussionTitle(),
discussionCommentCount
myDiscussionComment.discussionTitle()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<MissionResponse> getMissions(String hashTagName) {
}

public List<MissionResponse> getInProgressMissions(Long memberId) {
return solutionRepository.findAllByMember_IdAndStatus(memberId, SolutionStatus.IN_PROGRESS)
return solutionRepository.findAllByMember_IdAndStatusOrderByIdDesc(memberId, SolutionStatus.IN_PROGRESS)
.stream()
.map(Solution::getMission)
.distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static MySolutionResponse from(Solution solution) {
solution.getId(),
solution.getMissionThumbnail(),
solution.getTitle(),
solution.getCreatedAt()
solution.getSubmittedAt()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@ public SolutionResponse getById(Long id) {
}

public List<MySolutionResponse> getSubmittedSolutionsByMemberId(Long memberId) {
List<Solution> mySolutions = solutionRepository.findAllByMember_IdAndStatus(memberId, SolutionStatus.COMPLETED);
List<Solution> mySolutions = solutionRepository.findAllByMember_IdAndStatusOrderBySubmittedAtDesc(memberId, SolutionStatus.COMPLETED);
return mySolutions.stream()
.map(MySolutionResponse::from)
.toList();
}

public List<SummarizedSolutionResponse> getCompletedSummaries(String hashTagName) {
if (hashTagName.equalsIgnoreCase("all")) {
return solutionRepositoryCustom.findAllCompletedSolution().stream()
.map(SummarizedSolutionResponse::from)
.toList();
}
return solutionRepositoryCustom.findAllCompletedSolutionByHashTagName(hashTagName).stream()
public List<SummarizedSolutionResponse> getCompletedSummaries(String missionTitle, String hashTagName) {
return solutionRepositoryCustom.findAllCompletedSolutionByHashTagName(missionTitle, hashTagName).stream()
.map(SummarizedSolutionResponse::from)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ public record MySolutionCommentResponse(
Long solutionId,
String content,
LocalDateTime createdAt,
String solutionTitle,
Long solutionCommentCount
String solutionTitle
) {

public static MySolutionCommentResponse of(MySolutionComment mySolutionComment, Long solutionCommentCount) {
public static MySolutionCommentResponse from(MySolutionComment mySolutionComment) {
return new MySolutionCommentResponse(
mySolutionComment.id(),
mySolutionComment.solutionId(),
mySolutionComment.content(),
mySolutionComment.createdAt(),
mySolutionComment.solutionTitle(),
solutionCommentCount
mySolutionComment.solutionTitle()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import java.util.List;
import develup.api.exception.DevelupException;
import develup.api.exception.ExceptionType;
import develup.domain.solution.SolutionRepositoryCustom;
import develup.domain.solution.comment.MySolutionComment;
import develup.domain.solution.comment.SolutionComment;
import develup.domain.solution.comment.SolutionCommentCounts;
import develup.domain.solution.comment.SolutionCommentRepository;
import develup.domain.solution.comment.SolutionCommentRepositoryCustom;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,7 +18,6 @@ public class SolutionCommentReadService {

private final CommentGroupingService commentGroupingService;
private final SolutionCommentRepository solutionCommentRepository;
private final SolutionRepositoryCustom solutionRepositoryCustom;
private final SolutionCommentRepositoryCustom solutionCommentRepositoryCustom;

public SolutionComment getById(Long commentId) {
Expand All @@ -43,22 +40,10 @@ public List<SolutionCommentRepliesResponse> getCommentsWithReplies(Long solution

public List<MySolutionCommentResponse> getMyComments(Long memberId) {
List<MySolutionComment> mySolutionComments = solutionCommentRepositoryCustom
.findAllMySolutionComment(memberId);
SolutionCommentCounts solutionCommentCounts = new SolutionCommentCounts(
solutionRepositoryCustom.findAllSolutionCommentCounts()
);
.findAllMySolutionCommentOrderByDesc(memberId);

return mySolutionComments.stream()
.map(mySolutionComment -> mapToMySolutionCommentResponse(mySolutionComment, solutionCommentCounts))
.map(MySolutionCommentResponse::from)
.toList();
}

private MySolutionCommentResponse mapToMySolutionCommentResponse(
MySolutionComment mySolutionComment,
SolutionCommentCounts solutionCommentCounts
) {
Long solutionId = mySolutionComment.solutionId();
Long commentCount = solutionCommentCounts.getCount(solutionId);
return MySolutionCommentResponse.of(mySolutionComment, commentCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ public Optional<Discussion> findFetchById(Long id) {
return Optional.ofNullable(result);
}

public List<Discussion> findAllByMemberId(Long memberId) {
public List<Discussion> findAllByMemberIdOrderByDesc(Long memberId) {
return queryFactory
.selectFrom(discussion)
.innerJoin(discussion.member, member).fetchJoin()
.leftJoin(discussion.mission, mission).fetchJoin()
.leftJoin(discussion.discussionHashTags.hashTags, discussionHashTag).fetchJoin()
.leftJoin(discussionHashTag.hashTag, hashTag).fetchJoin()
.where(member.id.eq(memberId))
.orderBy(discussion.id.desc())
.fetch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public List<DiscussionComment> findAllByDiscussionIdOrderByCreatedAtAsc(Long dis
.fetch();
}

public List<MyDiscussionComment> findAllMyDiscussionComment(Long memberId) {
public List<MyDiscussionComment> findAllMyDiscussionCommentOrderByCreatedAtDesc(Long memberId) {
return queryFactory.select(Projections.constructor(MyDiscussionComment.class,
discussionComment.id,
discussionComment.discussion.id,
Expand All @@ -36,6 +36,7 @@ public List<MyDiscussionComment> findAllMyDiscussionComment(Long memberId) {
.join(discussionComment.discussion, discussion)
.join(discussionComment.member)
.where(discussionComment.member.id.eq(memberId).and(discussionComment.deletedAt.isNull()))
.orderBy(discussionComment.createdAt.desc())
.fetch();
}
}
10 changes: 8 additions & 2 deletions backend/src/main/java/develup/domain/solution/Solution.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package develup.domain.solution;

import java.time.LocalDateTime;
import java.util.Set;
import develup.api.exception.DevelupException;
import develup.api.exception.ExceptionType;
Expand Down Expand Up @@ -47,14 +48,17 @@ public class Solution extends CreatedAtAuditableEntity {
@Enumerated(EnumType.STRING)
private SolutionStatus status = SolutionStatus.IN_PROGRESS;

private LocalDateTime submittedAt;

public Solution(
Long id,
Mission mission,
Member member,
SolutionTitle title,
String description,
PullRequestUrl pullRequestUrl,
SolutionStatus status
SolutionStatus status,
LocalDateTime submittedAt
) {
super(id);
this.mission = mission;
Expand All @@ -63,10 +67,11 @@ public Solution(
this.description = description;
this.pullRequestUrl = pullRequestUrl;
this.status = status;
this.submittedAt = submittedAt;
}

public static Solution start(Mission mission, Member member) {
return new Solution(mission, member, null, null, null, SolutionStatus.IN_PROGRESS);
return new Solution(mission, member, null, null, null, SolutionStatus.IN_PROGRESS, null);
}

public void submit(SolutionSubmit solutionSubmit) {
Expand All @@ -77,6 +82,7 @@ public void submit(SolutionSubmit solutionSubmit) {
this.description = solutionSubmit.description();
this.pullRequestUrl = createPullRequestUrl(solutionSubmit.url());
this.status = SolutionStatus.COMPLETED;
this.submittedAt = LocalDateTime.now();
}

public void update(SolutionSubmit solutionSubmit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public interface SolutionRepository extends JpaRepository<Solution, Long> {

boolean existsByMember_IdAndMission_IdAndStatus(Long memberId, Long missionId, SolutionStatus status);

List<Solution> findAllByMember_IdAndStatus(Long memberId, SolutionStatus status);
List<Solution> findAllByMember_IdAndStatusOrderBySubmittedAtDesc(Long memberId, SolutionStatus status);

Optional<Solution> findByMember_IdAndMission_IdAndStatus(Long memberId, Long missionId, SolutionStatus status);

List<Solution> findAllByMember_IdAndStatusOrderByIdDesc(Long memberId, SolutionStatus solutionStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import java.util.List;
import java.util.Optional;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import develup.domain.solution.comment.SolutionCommentCount;
import jakarta.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

Expand All @@ -20,36 +21,36 @@
public class SolutionRepositoryCustom {

private final JPAQueryFactory queryFactory;
private final EntityManager entityManager;

public List<Solution> findAllCompletedSolutionByHashTagName(String name) {
public List<Solution> findAllCompletedSolutionByHashTagName(String missionTitle, String hashTagName) {
return queryFactory.selectFrom(solution)
.join(solution.mission, mission).fetchJoin()
.join(mission.missionHashTags.hashTags, missionHashTag).fetchJoin()
.join(missionHashTag.hashTag).fetchJoin()
.where(
solution.status.eq(SolutionStatus.COMPLETED)
.and(JPAExpressions.selectOne()
.from(missionHashTag)
.join(missionHashTag.hashTag)
.where(
missionHashTag.mission.id.eq(mission.id)
.and(missionHashTag.hashTag.name.eq(name))
)
.exists()
)
)
.where(eqCompleted(), eqMissionTitle(missionTitle), eqHashTagName(hashTagName))
.orderBy(solution.id.desc())
.fetch();
}

public List<Solution> findAllCompletedSolution() {
return queryFactory.selectFrom(solution)
.join(solution.mission, mission).fetchJoin()
.join(mission.missionHashTags.hashTags, missionHashTag).fetchJoin()
.join(missionHashTag.hashTag).fetchJoin()
.where(solution.status.eq(SolutionStatus.COMPLETED))
.orderBy(solution.id.desc())
.fetch();
private BooleanExpression eqCompleted() {
return solution.status.eq(SolutionStatus.COMPLETED);
}

private BooleanExpression eqMissionTitle(String missionTitle) {
if ("all".equalsIgnoreCase(missionTitle)) {
return null;
}

return mission.title.eq(missionTitle);
}

private BooleanExpression eqHashTagName(String hashTagName) {
if ("all".equalsIgnoreCase(hashTagName)) {
return null;
}

return missionHashTag.hashTag.name.eq(hashTagName);
}

public Optional<Solution> findFetchById(Long solutionId) {
Expand All @@ -67,6 +68,9 @@ public void deleteAllComments(Long solutionId) {
queryFactory.delete(solutionComment)
.where(solutionComment.solution.id.eq(solutionId))
.execute();

entityManager.flush();
entityManager.clear();
}

public List<SolutionCommentCount> findAllSolutionCommentCounts() {
Expand Down
Loading

0 comments on commit 6e5cc7e

Please sign in to comment.