Skip to content

Commit

Permalink
[DEV-74] ActivityReport 리팩토링 (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoSeonJe authored Sep 25, 2024
1 parent c569c85 commit 012062b
Show file tree
Hide file tree
Showing 27 changed files with 830 additions and 468 deletions.
29 changes: 29 additions & 0 deletions src/main/java/ddingdong/ddingdongBE/common/utils/TimeParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ddingdong.ddingdongBE.common.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TimeParser {

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

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

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

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

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

return parseToLocalDateTime(dateString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.request.CreateActivityTermInfoRequest;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportListResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
Expand All @@ -18,15 +21,17 @@
public interface AdminActivityReportApi {

@Operation(summary = "활동 보고서 전체 조회")
@GetMapping
@ApiResponse(responseCode = "200", description = "활동 보고서 전체 조회 성공",
content = @Content(schema = @Schema(implementation = ActivityReportListResponse.class)))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping
List<ActivityReportListResponse> getActivityReports();

@Operation(summary = "활동 보고서 회차별 기간 설정 API")
@PostMapping("/term")
@ApiResponse(responseCode = "201", description = "활동 보고서 회차 생성 성공")
@ResponseStatus(HttpStatus.CREATED)
@SecurityRequirement(name = "AccessToken")
@PostMapping("/term")
void createActivityTermInfo(@RequestBody CreateActivityTermInfoRequest request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportTermInfoResponse;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.CurrentTermResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
Expand All @@ -29,32 +32,39 @@
public interface ClubActivityReportApi {

@Operation(summary = "현재 활동보고서 회차 조회")
@GetMapping("/activity-reports/current-term")
@ApiResponse(responseCode = "200", description = "현재 활동보고서 회차 조회 성공",
content = @Content(schema = @Schema(implementation = CurrentTermResponse.class)))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/activity-reports/current-term")
CurrentTermResponse getCurrentTerm();

@Operation(summary = "본인 동아리 활동보고서 전체 조회")
@GetMapping("/my/activity-reports")
@ApiResponse(responseCode = "200", description = "본인 동아리 활동보고서 전체 조회 성공",
content = @Content(schema = @Schema(implementation = ActivityReportListResponse.class)))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/my/activity-reports")
List<ActivityReportListResponse> getMyActivityReports(
@AuthenticationPrincipal PrincipalDetails principalDetails
);

@Operation(summary = "활동보고서 상세 조회")
@GetMapping("/activity-reports")
@ApiResponse(responseCode = "200", description = "활동보고서 상세 조회 성공",
content = @Content(schema = @Schema(implementation = ActivityReportResponse.class)))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/activity-reports")
List<ActivityReportResponse> getActivityReport(
@RequestParam("term") String term,
@RequestParam("club_name") String clubName
);

@Operation(summary = "활동보고서 등록")
@PostMapping(value = "/my/activity-reports", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiResponse(responseCode = "201", description = "활동보고서 등록 성공")
@ResponseStatus(HttpStatus.CREATED)
@SecurityRequirement(name = "AccessToken")
@PostMapping(value = "/my/activity-reports", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
void createActivityReport(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestPart(value = "reportData") List<CreateActivityReportRequest> requests,
Expand All @@ -63,9 +73,10 @@ void createActivityReport(
);

@Operation(summary = "활동보고서 수정")
@PatchMapping(value = "/my/activity-reports", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiResponse(responseCode = "200", description = "활동보고서 수정 성공")
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@PatchMapping(value = "/my/activity-reports", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
void updateActivityReport(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestParam(value = "term") String term,
Expand All @@ -75,18 +86,21 @@ void updateActivityReport(
);

@Operation(summary = "활동보고서 삭제")
@DeleteMapping("/my/activity-reports")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiResponse(responseCode = "200", description = "활동보고서 삭제 성공")
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@DeleteMapping("/my/activity-reports")
void deleteActivityReport(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestParam(value = "term") String term
);

@Operation(summary = "활동 보고서 회차별 기간 조회 API")
@GetMapping("/activity-reports/term")
@ApiResponse(responseCode = "200", description = "활동 보고서 회차별 기간 조회 성공",
content = @Content(schema = @Schema(implementation = ActivityReportTermInfoResponse.class)))
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
@GetMapping("/activity-reports/term")
List<ActivityReportTermInfoResponse> getActivityTermInfos();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
import ddingdong.ddingdongBE.domain.activityreport.api.AdminActivityReportApi;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.request.CreateActivityTermInfoRequest;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportListResponse;
import ddingdong.ddingdongBE.domain.activityreport.service.ActivityReportService;
import ddingdong.ddingdongBE.domain.activityreport.service.ActivityReportTermInfoService;
import ddingdong.ddingdongBE.domain.activityreport.service.FacadeActivityReportService;
import ddingdong.ddingdongBE.domain.activityreport.service.dto.query.ActivityReportListQuery;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class AdminActivityReportApiController implements AdminActivityReportApi {

private final ActivityReportService activityReportService;
private final ActivityReportTermInfoService activityReportTermInfoService;
private final FacadeActivityReportService facadeActivityReportService;

@GetMapping
@Override
public List<ActivityReportListResponse> getActivityReports() {
return activityReportService.getAll();
List<ActivityReportListQuery> queries = facadeActivityReportService.getActivityReports();
return queries.stream()
.map(ActivityReportListResponse::from)
.toList();
}

@Override
public void createActivityTermInfo(CreateActivityTermInfoRequest request) {
activityReportTermInfoService.create(request.startDate(), request.totalTermCount());
facadeActivityReportService.createActivityTermInfo(request.toCommand());
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package ddingdong.ddingdongBE.domain.activityreport.controller;

import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileDomainCategory.ACTIVITY_REPORT;
import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileTypeCategory.IMAGE;

import ddingdong.ddingdongBE.auth.PrincipalDetails;
import ddingdong.ddingdongBE.domain.activityreport.api.ClubActivityReportApi;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.request.CreateActivityReportRequest;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.request.UpdateActivityReportRequest;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportDto;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportListResponse;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportResponse;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportTermInfoResponse;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.CurrentTermResponse;
import ddingdong.ddingdongBE.domain.activityreport.service.ActivityReportService;
import ddingdong.ddingdongBE.domain.activityreport.service.ActivityReportTermInfoService;
import ddingdong.ddingdongBE.domain.activityreport.service.FacadeActivityReportService;
import ddingdong.ddingdongBE.domain.activityreport.service.dto.command.CreateActivityReportCommand;
import ddingdong.ddingdongBE.domain.activityreport.service.dto.command.UpdateActivityReportCommand;
import ddingdong.ddingdongBE.domain.activityreport.service.dto.query.ActivityReportInfo;
import ddingdong.ddingdongBE.domain.activityreport.service.dto.query.ActivityReportListQuery;
import ddingdong.ddingdongBE.domain.activityreport.service.dto.query.ActivityReportQuery;
import ddingdong.ddingdongBE.domain.activityreport.service.dto.query.ActivityReportTermInfoQuery;
import ddingdong.ddingdongBE.domain.user.entity.User;
import ddingdong.ddingdongBE.file.service.FileService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -28,55 +25,55 @@
@RequiredArgsConstructor
public class ClubActivityReportApiController implements ClubActivityReportApi {

private final ActivityReportService activityReportService;
private final ActivityReportTermInfoService activityReportTermInfoService;
private final FileService fileService;
private final FacadeActivityReportService facadeActivityReportService;

@Override
public CurrentTermResponse getCurrentTerm() {
return activityReportService.getCurrentTerm();
String currentTerm = facadeActivityReportService.getCurrentTerm();
return CurrentTermResponse.from(currentTerm);
}

@Override
public List<ActivityReportListResponse> getMyActivityReports(PrincipalDetails principalDetails) {
User user = principalDetails.getUser();
return activityReportService.getMyActivityReports(user);
List<ActivityReportListQuery> queries = facadeActivityReportService.getMyActivityReports(
user);
return queries.stream()
.map(ActivityReportListResponse::from)
.toList();
}

@Override
public List<ActivityReportResponse> getActivityReport(
String term,
String clubName
) {
return activityReportService.getActivityReport(term, clubName);
List<ActivityReportQuery> queries = facadeActivityReportService.getActivityReport(term,
clubName);
return queries.stream()
.map(ActivityReportResponse::from)
.toList();
}

@Override
public void createActivityReport(
PrincipalDetails principalDetails,
List<CreateActivityReportRequest> requests,
MultipartFile firstImage,
MultipartFile secondImage
) {
User user = principalDetails.getUser();

List<MultipartFile> images = new ArrayList<>();
images.add(firstImage);
images.add(secondImage);

IntStream.range(0, requests.size())
.forEach(index -> {
CreateActivityReportRequest request = requests.get(index);
Long registeredActivityReportId = activityReportService.create(user, request);

if (index < images.size() && images.get(index) != null && !images.get(index).isEmpty()) {
fileService.uploadFile(
registeredActivityReportId,
Collections.singletonList(images.get(index)),
IMAGE,
ACTIVITY_REPORT
);
}
});

List<CreateActivityReportCommand> commands = requests.stream()
.map(CreateActivityReportRequest::toCommand)
.toList();
facadeActivityReportService.create(user, commands);

String term = facadeActivityReportService.getRequestTerm(commands);
List<ActivityReportInfo> activityReportInfos = facadeActivityReportService.getActivityReportInfos(user, term);
facadeActivityReportService.uploadImages(activityReportInfos, firstImage, secondImage);
}

@Override
public void updateActivityReport(
PrincipalDetails principalDetails,
String term,
Expand All @@ -85,45 +82,32 @@ public void updateActivityReport(
MultipartFile secondImage
) {
User user = principalDetails.getUser();

List<ActivityReportDto> activityReportDtos = activityReportService.update(user, term, requests);

List<MultipartFile> images = new ArrayList<>();
images.add(firstImage);
images.add(secondImage);

IntStream.range(0, Math.min(activityReportDtos.size(), images.size()))
.filter(index -> images.get(index) != null && !images.get(index).isEmpty())
.forEach(index -> {
fileService.deleteFile(
activityReportDtos.get(index).getId(),
IMAGE,
ACTIVITY_REPORT
);

fileService.uploadFile(
activityReportDtos.get(index).getId(),
Collections.singletonList(images.get(index)),
IMAGE,
ACTIVITY_REPORT
);
}
);
List<UpdateActivityReportCommand> commands = requests.stream()
.map(UpdateActivityReportRequest::toCommand)
.toList();
facadeActivityReportService.update(user, term, commands);
List<ActivityReportInfo> activityReportInfos = facadeActivityReportService.getActivityReportInfos(
user, term);
facadeActivityReportService.updateImages(activityReportInfos, firstImage, secondImage);
}

@Override
public void deleteActivityReport(
PrincipalDetails principalDetails,
String term
) {
User user = principalDetails.getUser();

activityReportService.delete(user, term)
.forEach(it -> fileService.deleteFile(it.getId(), IMAGE, ACTIVITY_REPORT));
List<ActivityReportInfo> activityReportInfos = facadeActivityReportService.getActivityReportInfos(
user, term);
facadeActivityReportService.deleteImages(activityReportInfos);
facadeActivityReportService.delete(user, term);
}

@Override
public List<ActivityReportTermInfoResponse> getActivityTermInfos() {
return activityReportTermInfoService.getAll();
List<ActivityReportTermInfoQuery> queries = facadeActivityReportService.getActivityReportTermInfos();
return queries.stream()
.map(ActivityReportTermInfoResponse::from)
.toList();
}

}
Loading

0 comments on commit 012062b

Please sign in to comment.