Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/139-remove
Browse files Browse the repository at this point in the history
  • Loading branch information
OJOJIN committed Nov 23, 2023
2 parents d79814a + b5cb698 commit 685706c
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
new AntPathRequestMatcher("/api/contests/search"),
new AntPathRequestMatcher("/api/contests/categories"),
new AntPathRequestMatcher("/api/contests/detail"),
new AntPathRequestMatcher("/api/contests/main-recommendation"),

// 추천사 관련 URI
new AntPathRequestMatcher("/api/reviews/non-user"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

@RestController
public class HealthCheckAPI {

@GetMapping("/api/health")
public String healthCheck() {
return "Wanteam!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.kusithm.meetupd.common.dto.code.SuccessCode;
import com.kusithm.meetupd.domain.contest.dto.response.FindContestsResponseDto;
import com.kusithm.meetupd.domain.contest.dto.response.GetContestDetailInfoResponseDto;
import com.kusithm.meetupd.domain.contest.dto.response.GetMainRecommendationResponseDto;
import com.kusithm.meetupd.domain.contest.service.ContestService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -44,4 +45,10 @@ public ResponseEntity<SuccessResponse<GetContestDetailInfoResponseDto>> getConte
return SuccessResponse.of(SuccessCode.OK, response);
}

@GetMapping("/main-recommendation")
public ResponseEntity<SuccessResponse<GetMainRecommendationResponseDto>> getMainRecommendContestsAndTeams() {
GetMainRecommendationResponseDto response = contestService.getMainRecommendContestsAndTeams();
return SuccessResponse.of(SuccessCode.OK, response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.kusithm.meetupd.domain.contest.dto.response;

import com.kusithm.meetupd.domain.contest.entity.Contest;
import com.kusithm.meetupd.domain.review.dto.response.GetUserReviewResponseDto;
import com.kusithm.meetupd.domain.review.entity.Review;
import com.kusithm.meetupd.domain.team.dto.response.RecruitingTeamResponseDto;
import com.kusithm.meetupd.domain.team.entity.Team;
import com.kusithm.meetupd.domain.user.entity.User;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static com.kusithm.meetupd.domain.review.dto.response.GetUserReviewResponseDto.CommentsResponseDto.createCommentsResponseDtos;
import static com.kusithm.meetupd.domain.review.dto.response.GetUserReviewResponseDto.TeamCultureResponseDto.createTeamCultureResponseDtos;
import static com.kusithm.meetupd.domain.review.dto.response.GetUserReviewResponseDto.WorkMethodResponseDto.createWorkMethodResponseDtos;
import static java.time.temporal.ChronoUnit.DAYS;

@Getter
@Builder
public class GetMainRecommendationResponseDto {

private List<RecommendationContest> recommendationContests;

private List<RecruitingTeamResponseDto> recommendationTeams;

public static GetMainRecommendationResponseDto of(List<Contest> recommendContests, List<RecruitingTeamResponseDto> recommendationTeams, LocalDate nowDate) {
return GetMainRecommendationResponseDto.builder()
.recommendationContests(recommendContests.stream()
.map(it ->RecommendationContest.of(it, nowDate))
.collect(Collectors.toList())
)
.recommendationTeams(recommendationTeams).build();
}

@Getter
@Builder
public static class RecommendationContest {

private String contestId;

private String title;

private String company;

private List<String> images;

private Long remainDay;

private Integer teamNum;

public static RecommendationContest of(Contest contest, LocalDate nowDate) {
return RecommendationContest.builder()
.contestId(contest.getId())
.title(contest.getTitle())
.company(contest.getCompany())
.images(contest.getContestImages())
.remainDay(DAYS.between(nowDate, contest.getRecruitmentEndDate()))
.teamNum(contest.getTeamNum())
.build();
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.kusithm.meetupd.domain.contest.entity.Contest;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.Aggregation;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

Expand All @@ -22,4 +23,12 @@ public interface ContestRepository extends MongoRepository<Contest, String> {

@Query(value = "{recruit_end : {$gte : ?0, $lt : ?1}}")
List<Contest> findAllEndContestsToday(LocalDate start, LocalDate end);


@Aggregation(pipeline = {
"{ $match: { recruit_end: { $gte: ?0 } } }",
"{ '$sort' : { 'team_num' : -1 } }",
"{ '$limit' : 6 }"
})
List<Contest> findRecommendationSixContests(LocalDate date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import com.kusithm.meetupd.common.error.ErrorCode;
import com.kusithm.meetupd.domain.contest.dto.response.FindContestsResponseDto;
import com.kusithm.meetupd.domain.contest.dto.response.GetContestDetailInfoResponseDto;
import com.kusithm.meetupd.domain.contest.dto.response.GetMainRecommendationResponseDto;
import com.kusithm.meetupd.domain.contest.entity.Contest;
import com.kusithm.meetupd.domain.contest.entity.ContestType;
import com.kusithm.meetupd.domain.contest.mongo.ContestRepository;
import com.kusithm.meetupd.domain.review.entity.Review;
import com.kusithm.meetupd.domain.review.mongo.ReviewRepository;
import com.kusithm.meetupd.domain.team.dto.response.RecruitingTeamResponseDto;
import com.kusithm.meetupd.domain.team.entity.Team;
import com.kusithm.meetupd.domain.team.entity.TeamUser;
import com.kusithm.meetupd.domain.team.mysql.TeamRepository;
Expand All @@ -33,6 +35,7 @@
import static com.kusithm.meetupd.common.error.ErrorCode.USER_REVIEW_NOT_FOUND;
import static com.kusithm.meetupd.domain.contest.dto.response.FindContestsResponseDto.createListOf;
import static com.kusithm.meetupd.domain.team.entity.TeamProgressType.RECRUITMENT_COMPLETED;
import static com.kusithm.meetupd.domain.team.entity.TeamUserRoleType.TEAM_LEADER;

@RequiredArgsConstructor
@Service
Expand Down Expand Up @@ -72,6 +75,13 @@ public GetContestDetailInfoResponseDto getContestDetailById(String contestId) {
return GetContestDetailInfoResponseDto.of(findContest, LocalDate.now(), Math.floor(averageContestUserComments * 10) / 10);
}

public GetMainRecommendationResponseDto getMainRecommendContestsAndTeams() {
List<Contest> recommendationContests = contestRepository.findRecommendationSixContests(LocalDate.now());
List<Team> popularTeams = teamRepository.findPopularTeams();
List<RecruitingTeamResponseDto> recruitingTeamResponseDtos = createRecruitingTeamResponseDtos(popularTeams);
return GetMainRecommendationResponseDto.of(recommendationContests, recruitingTeamResponseDtos, LocalDate.now());
}

private List<Team> findAllRecuritTeamByContestTitle(String contestId) {
return teamRepository.findAllByContestIdAndProgressLessThanEqual(contestId, RECRUITMENT_COMPLETED.getNumber());
}
Expand Down Expand Up @@ -124,6 +134,26 @@ private List<Contest> searchContestByText(String searchText, MongoCollection<Doc
return contests;
}

private List<RecruitingTeamResponseDto> createRecruitingTeamResponseDtos(List<Team> popularTeams) {
List<RecruitingTeamResponseDto> recruitingTeamResponseDtos = new ArrayList<>();
for (Team popularTeam : popularTeams) {
Contest teamContest = getContestById(popularTeam.getContestId());
for (TeamUser teamuser : popularTeam.getTeamUsers()) {
if (teamuser.getRole().equals(TEAM_LEADER.getCode())) {
recruitingTeamResponseDtos.add(
new RecruitingTeamResponseDto(teamContest,
popularTeam,
teamuser.getUser())
);
}
}
}
if (recruitingTeamResponseDtos.size() > 4) {
recruitingTeamResponseDtos = recruitingTeamResponseDtos.subList(0, 4);
}
return recruitingTeamResponseDtos;
}

private List<FindContestsResponseDto> findAllContests(LocalDate nowDate) {
List<Contest> findContests = findContestsByDate(nowDate);
return createListOf(findContests, nowDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
Expand All @@ -16,4 +17,25 @@ public interface TeamRepository extends JpaRepository<Team, Long> {
Optional<List<Team>> findAllByIdAndProgress(Long userId, Integer progress);
List<Team> findAllByReviewDateLessThanAndProgress(Date date, Integer Progress);
List<Team> findAllByContestIdAndProgressLessThanEqual(String contestId, Integer teamProgress);

@Query( "SELECT t " +
"FROM Team t " +
"WHERE t.progress = 1 " +
"AND t.id IN (" +
"SELECT tu.team.id " +
"FROM TeamUser tu " +
"WHERE tu.team = t " +
"AND tu.role IN (2, 4) " +
"GROUP BY tu.team.id " +
"ORDER BY COUNT(tu.team.id) DESC" +
") " +
"ORDER BY (" +
"SELECT COUNT(tu2) " +
"FROM TeamUser tu2 " +
"WHERE tu2.team = t " +
"AND tu2.role IN (2, 4)" +
") DESC, t.id DESC"

)
List<Team> findPopularTeams();
}

0 comments on commit 685706c

Please sign in to comment.