Skip to content

Commit

Permalink
[DDING-97] 동아리 지원 폼지 통계 전체조회 API 구현 (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoSeonJe authored Feb 9, 2025
1 parent 5084cc4 commit cb52e2e
Show file tree
Hide file tree
Showing 21 changed files with 1,214 additions and 203 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ddingdong.ddingdongBE.common.utils;

public class CalculationUtils {

public static int calculateRatio(int numerator, int denominator) {
if (denominator == 0) {
return 0;
}
return (int) ((double) numerator / denominator * 100);
}

public static int calculateDifference(int beforeCount, int count) {
return count - beforeCount;
}

public static int calculateDifferenceRatio(int beforeCount, int count) {
int difference = calculateDifference(beforeCount, count);
return calculateRatio(difference, beforeCount);
}
}
41 changes: 23 additions & 18 deletions src/main/java/ddingdong/ddingdongBE/common/utils/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@

public class TimeUtils {

private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm";
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm";

public static LocalDateTime parseToLocalDateTime(String dateString) {
if (dateString == null || dateString.isBlank()) {
return null;
public static LocalDateTime parseToLocalDateTime(String dateString) {
if (dateString == null || dateString.isBlank()) {
return null;
}

return LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT));
}

return LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT));
}
public static LocalDateTime processDate(String dateString, LocalDateTime currentDate) {
if (dateString == null) {
return null;
}

public static LocalDateTime processDate(String dateString, LocalDateTime currentDate) {
if (dateString == null) {
return null;
}
if (dateString.isBlank()) {
return null;
}

if (dateString.isBlank()) {
return null;
return parseToLocalDateTime(dateString);
}

return parseToLocalDateTime(dateString);
}
public static boolean isDateInRange(LocalDate nowDate, LocalDate startDate, LocalDate endDate) {
if (nowDate == null || startDate == null || endDate == null) {
return false;
}
return !nowDate.isBefore(startDate) && !nowDate.isAfter(endDate);
}

public static boolean isDateInRange(LocalDate nowDate, LocalDate startDate, LocalDate endDate) {
if (nowDate == null || startDate == null || endDate == null) {
return false;
public static String getYearAndMonth(LocalDate date) {
return date.getYear() + "-" + date.getMonthValue();
}
return !nowDate.isBefore(startDate) && !nowDate.isAfter(endDate); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ddingdong.ddingdongBE.domain.form.controller.dto.request.UpdateFormRequest;
import ddingdong.ddingdongBE.domain.form.controller.dto.response.FormListResponse;
import ddingdong.ddingdongBE.domain.form.controller.dto.response.FormResponse;
import ddingdong.ddingdongBE.domain.form.controller.dto.response.FormStatisticsResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -29,56 +30,63 @@
@RequestMapping("/server/central")
public interface CentralFormApi {

@Operation(summary = "동아리 지원 폼지 생성 API")
@ApiResponse(responseCode = "201", description = "동아리 지원 폼지 생성 성공")
@ResponseStatus(HttpStatus.CREATED)
@SecurityRequirement(name = "AccessToken")
@PostMapping("/my/forms")
void createForm(
@Valid @RequestBody CreateFormRequest createFormRequest,
@AuthenticationPrincipal PrincipalDetails principalDetails
);
@Operation(summary = "동아리 지원 폼지 생성 API")
@ApiResponse(responseCode = "201", description = "동아리 지원 폼지 생성 성공")
@ResponseStatus(HttpStatus.CREATED)
@SecurityRequirement(name = "AccessToken")
@PostMapping("/my/forms")
void createForm(
@Valid @RequestBody CreateFormRequest createFormRequest,
@AuthenticationPrincipal PrincipalDetails principalDetails
);

@Operation(summary = "동아리 지원 폼지 수정 API")
@ApiResponse(responseCode = "204", description = "동아리 지원 폼지 수정 성공")
@ResponseStatus(HttpStatus.NO_CONTENT)
@SecurityRequirement(name = "AccessToken")
@PutMapping("/my/forms/{formId}")
void updateForm(
@Valid @RequestBody UpdateFormRequest updateFormRequest,
@PathVariable("formId") Long formId,
@AuthenticationPrincipal PrincipalDetails principalDetails
);
@Operation(summary = "동아리 지원 폼지 수정 API")
@ApiResponse(responseCode = "204", description = "동아리 지원 폼지 수정 성공")
@ResponseStatus(HttpStatus.NO_CONTENT)
@SecurityRequirement(name = "AccessToken")
@PutMapping("/my/forms/{formId}")
void updateForm(
@Valid @RequestBody UpdateFormRequest updateFormRequest,
@PathVariable("formId") Long formId,
@AuthenticationPrincipal PrincipalDetails principalDetails
);

@Operation(summary = "동아리 지원 폼지 삭제 API")
@ApiResponse(responseCode = "204", description = "동아리 지원 폼지 삭제 성공")
@ResponseStatus(HttpStatus.NO_CONTENT)
@SecurityRequirement(name = "AccessToken")
@DeleteMapping("/my/forms/{formId}")
void deleteForm(
@PathVariable("formId") Long formId,
@AuthenticationPrincipal PrincipalDetails principalDetails
);
@Operation(summary = "동아리 지원 폼지 삭제 API")
@ApiResponse(responseCode = "204", description = "동아리 지원 폼지 삭제 성공")
@ResponseStatus(HttpStatus.NO_CONTENT)
@SecurityRequirement(name = "AccessToken")
@DeleteMapping("/my/forms/{formId}")
void deleteForm(
@PathVariable("formId") Long formId,
@AuthenticationPrincipal PrincipalDetails principalDetails
);

@Operation(summary = "동아리 지원 폼지 전체조회 API")
@ApiResponse(responseCode = "200", description = "동아리 지원 폼지 전체조회 성공",
content = @Content(
array = @ArraySchema(schema = @Schema(implementation = FormListResponse.class))
))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/my/forms")
List<FormListResponse> getAllMyForm(
@AuthenticationPrincipal PrincipalDetails principalDetails
);
@Operation(summary = "동아리 지원 폼지 전체조회 API")
@ApiResponse(responseCode = "200", description = "동아리 지원 폼지 전체조회 성공",
content = @Content(
array = @ArraySchema(schema = @Schema(implementation = FormListResponse.class))
))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/my/forms")
List<FormListResponse> getAllMyForm(@AuthenticationPrincipal PrincipalDetails principalDetails);

@Operation(summary = "동아리 지원 폼지 상세조회 API")
@ApiResponse(responseCode = "200", description = "동아리 지원 폼지 상세조회 성공",
content = @Content(schema = @Schema(implementation = FormResponse.class)))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/my/forms/{formId}")
FormResponse getForm(
@PathVariable("formId") Long formId
);
@Operation(summary = "동아리 지원 폼지 상세조회 API")
@ApiResponse(responseCode = "200", description = "동아리 지원 폼지 상세조회 성공",
content = @Content(schema = @Schema(implementation = FormResponse.class)))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/my/forms/{formId}")
FormResponse getForm(@PathVariable("formId") Long formId);

@Operation(summary = "동아리 지원 폼지 통계 전체조회 API")
@ApiResponse(responseCode = "200", description = "동아리 지원 폼지 통계 전체조회 성공",
content = @Content(schema = @Schema(implementation = FormStatisticsResponse.class)))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/my/forms/{formId}/statistics")
FormStatisticsResponse getFormStatistics(
@PathVariable("formId") Long formId,
@AuthenticationPrincipal PrincipalDetails principalDetails
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import ddingdong.ddingdongBE.domain.form.controller.dto.request.UpdateFormRequest;
import ddingdong.ddingdongBE.domain.form.controller.dto.response.FormListResponse;
import ddingdong.ddingdongBE.domain.form.controller.dto.response.FormResponse;
import ddingdong.ddingdongBE.domain.form.controller.dto.response.FormStatisticsResponse;
import ddingdong.ddingdongBE.domain.form.service.FacadeCentralFormService;
import ddingdong.ddingdongBE.domain.form.service.dto.query.FormListQuery;
import ddingdong.ddingdongBE.domain.form.service.dto.query.FormQuery;
import ddingdong.ddingdongBE.domain.form.service.dto.query.FormStatisticsQuery;
import ddingdong.ddingdongBE.domain.user.entity.User;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,44 +20,54 @@
@RequiredArgsConstructor
public class CentralFormController implements CentralFormApi {

private final FacadeCentralFormService facadeCentralFormService;

@Override
public void createForm(
CreateFormRequest createFormRequest,
PrincipalDetails principalDetails
) {
User user = principalDetails.getUser();
facadeCentralFormService.createForm(createFormRequest.toCommand(user));
}

@Override
public void updateForm(
UpdateFormRequest updateFormRequest,
Long formId,
PrincipalDetails principalDetails
) {
facadeCentralFormService.updateForm(updateFormRequest.toCommand(formId));
}

@Override
public void deleteForm(Long formId, PrincipalDetails principalDetails) {
User user = principalDetails.getUser();
facadeCentralFormService.deleteForm(formId, user);
}

@Override
public List<FormListResponse> getAllMyForm(PrincipalDetails principalDetails) {
User user = principalDetails.getUser();
List<FormListQuery> queries = facadeCentralFormService.getAllMyForm(user);
return queries.stream()
.map(FormListResponse::from)
.toList();
}

@Override
public FormResponse getForm(Long formId) {
FormQuery query = facadeCentralFormService.getForm(formId);
return FormResponse.from(query);
}
private final FacadeCentralFormService facadeCentralFormService;

@Override
public void createForm(
CreateFormRequest createFormRequest,
PrincipalDetails principalDetails
) {
User user = principalDetails.getUser();
facadeCentralFormService.createForm(createFormRequest.toCommand(user));
}

@Override
public void updateForm(
UpdateFormRequest updateFormRequest,
Long formId,
PrincipalDetails principalDetails
) {
facadeCentralFormService.updateForm(updateFormRequest.toCommand(formId));
}

@Override
public void deleteForm(Long formId, PrincipalDetails principalDetails) {
User user = principalDetails.getUser();
facadeCentralFormService.deleteForm(formId, user);
}

@Override
public List<FormListResponse> getAllMyForm(PrincipalDetails principalDetails) {
User user = principalDetails.getUser();
List<FormListQuery> queries = facadeCentralFormService.getAllMyForm(user);
return queries.stream()
.map(FormListResponse::from)
.toList();
}

@Override
public FormResponse getForm(Long formId) {
FormQuery query = facadeCentralFormService.getForm(formId);
return FormResponse.from(query);
}

@Override
public FormStatisticsResponse getFormStatistics(
Long formId,
PrincipalDetails principalDetails
) {
User user = principalDetails.getUser();
FormStatisticsQuery query = facadeCentralFormService.getStatisticsByForm(user, formId);
return FormStatisticsResponse.from(query);
}
}
Loading

0 comments on commit cb52e2e

Please sign in to comment.