Skip to content

Commit

Permalink
feat(InternalMeeting): 가장 빠르게 신청한 모임 N개 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekks committed Jan 29, 2025
1 parent eeffc59 commit 2c60abe
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.sopt.makers.crew.main.internal;

import org.sopt.makers.crew.main.internal.dto.ApprovedStudyCountResponseDto;
import org.sopt.makers.crew.main.internal.dto.TopFastestAppliedMeetingsResponseDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -20,4 +22,13 @@ public interface InternalMeetingStatsApi {
@ApiResponse(responseCode = "404", description = "존재하지 않는 유저입니다.", content = @Content(mediaType = "application/json"))})
ResponseEntity<ApprovedStudyCountResponseDto> getApprovedStudyCountByOrgId(
@Parameter(description = "플레이그라운드 유저 ID(orgId)", example = "1") Integer orgId);

@Operation(summary = "[Internal] 특정 유저가 가장 빠르게 신청한 모임 조회", description = "특정 유저가 가장 빠르게 신청한 모임 조회하는 API입니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "가장 빠르게 신청한 모임 조회 성공"),
@ApiResponse(responseCode = "204", description = "모임 신청한 기록이 없는 경우", content = @Content(mediaType = "application/json", schema = @Schema(example = "{\"topFastestAppliedMeetings\": null}"))),
@ApiResponse(responseCode = "404", description = "존재하지 않는 유저입니다.", content = @Content(mediaType = "application/json"))})
ResponseEntity<TopFastestAppliedMeetingsResponseDto> getTopFastestAppliedMeetings(
@Parameter(description = "플레이그라운드 유저 ID(orgId)", example = "1") Integer orgId,
@RequestParam(name = "queryCount", required = false, defaultValue = "3") Integer queryCount);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.sopt.makers.crew.main.internal;

import org.sopt.makers.crew.main.internal.dto.ApprovedStudyCountResponseDto;
import org.sopt.makers.crew.main.internal.dto.TopFastestAppliedMeetingsResponseDto;
import org.sopt.makers.crew.main.internal.service.InternalMeetingStatsService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import lombok.RequiredArgsConstructor;
Expand All @@ -16,11 +19,28 @@
public class InternalMeetingStatsController implements InternalMeetingStatsApi {
private final InternalMeetingStatsService internalMeetingStatsService;

@Override
@GetMapping("/approved-studies/{orgId}")
public ResponseEntity<ApprovedStudyCountResponseDto> getApprovedStudyCountByOrgId(
@PathVariable Integer orgId
) {
ApprovedStudyCountResponseDto response = internalMeetingStatsService.getApprovedStudyCountByOrgId(orgId);
return ResponseEntity.ok(response);
}

@Override
@GetMapping("/fastest-applied/{orgId}")
public ResponseEntity<TopFastestAppliedMeetingsResponseDto> getTopFastestAppliedMeetings(
@PathVariable Integer orgId,
@RequestParam(name = "query-count", required = false, defaultValue = "3") Integer queryCount) {

TopFastestAppliedMeetingsResponseDto response = internalMeetingStatsService.getTopFastestAppliedMeetings(
orgId, queryCount);

if (response.topFastestAppliedMeetings() == null) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(response);
}

return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.sopt.makers.crew.main.internal.service;

import java.util.List;
import java.util.Optional;

import org.sopt.makers.crew.main.entity.apply.Apply;
import org.sopt.makers.crew.main.entity.apply.ApplyRepository;
import org.sopt.makers.crew.main.entity.apply.enums.EnApplyStatus;
import org.sopt.makers.crew.main.entity.meeting.enums.MeetingCategory;
import org.sopt.makers.crew.main.entity.user.User;
import org.sopt.makers.crew.main.entity.user.UserRepository;
import org.sopt.makers.crew.main.internal.dto.ApprovedStudyCountResponseDto;
import org.sopt.makers.crew.main.internal.dto.TopFastestAppliedMeetingResponseDto;
import org.sopt.makers.crew.main.internal.dto.TopFastestAppliedMeetingsResponseDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -30,4 +36,20 @@ public ApprovedStudyCountResponseDto getApprovedStudyCountByOrgId(Integer orgId)

return ApprovedStudyCountResponseDto.of(user.getOrgId(), approvedStudyCount);
}

public TopFastestAppliedMeetingsResponseDto getTopFastestAppliedMeetings(Integer orgId, Integer queryCount) {
Optional<User> user = userRepository.findByOrgId(orgId);

if (user.isEmpty()) {
return TopFastestAppliedMeetingsResponseDto.of(null);
}

List<Apply> applies = applyRepository.findTopFastestAppliedMeetings(user.get().getId(), queryCount);

List<TopFastestAppliedMeetingResponseDto> responseDtos = applies.stream()
.map(apply -> TopFastestAppliedMeetingResponseDto.of(apply.getMeeting()))
.toList();

return TopFastestAppliedMeetingsResponseDto.of(responseDtos);
}
}

0 comments on commit 2c60abe

Please sign in to comment.