-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
212 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/main/java/ddingdong/ddingdongBE/common/handler/RestAuthenticationEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/ddingdong/ddingdongBE/domain/activityreport/api/AdminActivityReportApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ddingdong.ddingdongBE.domain.activityreport.api; | ||
|
||
import ddingdong.ddingdongBE.auth.PrincipalDetails; | ||
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.request.CreateActivityTermInfoRequest; | ||
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportTermInfoResponse; | ||
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.AllActivityReportResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.List; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@Tag(name = "Activity Report - Admin", description = "Activity Report Admin API") | ||
@RequestMapping("/server/admin/activity-reports") | ||
public interface AdminActivityReportApi { | ||
|
||
@Operation(summary = "활동 보고서 전체 조회") | ||
@GetMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
List<AllActivityReportResponse> getActivityReports(); | ||
|
||
@Operation(summary = "활동 보고서 회차별 기간 조회 API") | ||
@GetMapping("/term") | ||
@ResponseStatus(HttpStatus.OK) | ||
@SecurityRequirement(name = "AccessToken") | ||
List<ActivityReportTermInfoResponse> getActivityTermInfos( | ||
@AuthenticationPrincipal PrincipalDetails principalDetails); | ||
|
||
@Operation(summary = "활동 보고서 회차별 기간 설정 API") | ||
@PostMapping("/term") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
@SecurityRequirement(name = "AccessToken") | ||
void createActivityTermInfo( | ||
@AuthenticationPrincipal PrincipalDetails principalDetails, | ||
@RequestBody CreateActivityTermInfoRequest request | ||
); | ||
|
||
} |
28 changes: 23 additions & 5 deletions
28
...ngdong/ddingdongBE/domain/activityreport/controller/AdminActivityReportApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,42 @@ | ||
package ddingdong.ddingdongBE.domain.activityreport.controller; | ||
|
||
import ddingdong.ddingdongBE.auth.PrincipalDetails; | ||
import ddingdong.ddingdongBE.domain.activityreport.api.AdminActivityReportApi; | ||
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.request.CreateActivityTermInfoRequest; | ||
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportTermInfoResponse; | ||
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.AllActivityReportResponse; | ||
import ddingdong.ddingdongBE.domain.activityreport.service.ActivityReportService; | ||
import ddingdong.ddingdongBE.domain.activityreport.service.ActivityReportTermInfoService; | ||
import java.util.List; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/server/admin/activity-reports") | ||
public class AdminActivityReportApiController { | ||
public class AdminActivityReportApiController implements AdminActivityReportApi { | ||
|
||
private final ActivityReportService activityReportService; | ||
private final ActivityReportTermInfoService activityReportTermInfoService; | ||
|
||
@GetMapping | ||
public List<AllActivityReportResponse> getActivityReports() { | ||
return activityReportService.getAll(); | ||
} | ||
|
||
@Override | ||
public List<ActivityReportTermInfoResponse> getActivityTermInfos( | ||
@AuthenticationPrincipal PrincipalDetails principalDetails) { | ||
return activityReportTermInfoService.getAll(); | ||
} | ||
|
||
@Override | ||
public void createActivityTermInfo( | ||
@AuthenticationPrincipal PrincipalDetails principalDetails, | ||
CreateActivityTermInfoRequest request | ||
) { | ||
activityReportTermInfoService.create(request.startDate(), request.totalTermCount()); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...ingdongBE/domain/activityreport/controller/dto/request/CreateActivityTermInfoRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ddingdong.ddingdongBE.domain.activityreport.controller.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDate; | ||
import javax.validation.constraints.Pattern; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
@Schema( | ||
name = "CreateActivityTermInfoRequest", | ||
description = "활동 보고서 회차 시작 기준일 설정 요청" | ||
) | ||
public record CreateActivityTermInfoRequest( | ||
@Schema(description = "활동 보고서 시작 일자", example = "2024-07-22") | ||
@DateTimeFormat(pattern = "yyyy-MM-dd") | ||
@Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "날짜는 yyyy-MM-dd 형식이어야 합니다.") | ||
LocalDate startDate, | ||
@Schema(description = "설정할 총 회차 수", example = "10 (=총 10회 설정)") | ||
int totalTermCount | ||
) { | ||
} |
18 changes: 18 additions & 0 deletions
18
...gdongBE/domain/activityreport/controller/dto/response/ActivityReportTermInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ddingdong.ddingdongBE.domain.activityreport.controller.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDate; | ||
|
||
@Schema( | ||
name = "ActivityReportTermInfoResponse", | ||
description = "활동 보고서 회차 전체 조회 응답" | ||
) | ||
public record ActivityReportTermInfoResponse( | ||
@Schema(description = "회차") | ||
int term, | ||
@Schema(description = "시작 일자", example = "2024-07-22") | ||
LocalDate startDate, | ||
@Schema(description = "마감 일자", example = "2024-08-04") | ||
LocalDate endDate | ||
) { | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/ddingdong/ddingdongBE/domain/activityreport/domain/ActivityReportTermInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ddingdong.ddingdongBE.domain.activityreport.domain; | ||
|
||
import java.time.LocalDate; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ActivityReportTermInfo { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private int term; | ||
|
||
@Column(nullable = false, columnDefinition = "DATE") | ||
private LocalDate startDate; | ||
|
||
@Column(nullable = false, columnDefinition = "DATE") | ||
private LocalDate endDate; | ||
|
||
@Builder | ||
public ActivityReportTermInfo(int term, LocalDate startDate, LocalDate endDate) { | ||
this.term = term; | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...ngdong/ddingdongBE/domain/activityreport/repository/ActivityReportTermInfoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ddingdong.ddingdongBE.domain.activityreport.repository; | ||
|
||
import ddingdong.ddingdongBE.domain.activityreport.domain.ActivityReportTermInfo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ActivityReportTermInfoRepository extends JpaRepository<ActivityReportTermInfo, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...va/ddingdong/ddingdongBE/domain/activityreport/service/ActivityReportTermInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ddingdong.ddingdongBE.domain.activityreport.service; | ||
|
||
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportTermInfoResponse; | ||
import ddingdong.ddingdongBE.domain.activityreport.domain.ActivityReportTermInfo; | ||
import ddingdong.ddingdongBE.domain.activityreport.repository.ActivityReportTermInfoRepository; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ActivityReportTermInfoService { | ||
|
||
private final ActivityReportTermInfoRepository activityReportTermInfoRepository; | ||
|
||
public List<ActivityReportTermInfoResponse> getAll() { | ||
List<ActivityReportTermInfo> termInfos = activityReportTermInfoRepository.findAll(); | ||
|
||
return termInfos.stream() | ||
.map(termInfo -> new ActivityReportTermInfoResponse( | ||
termInfo.getTerm(), | ||
termInfo.getStartDate(), | ||
termInfo.getEndDate() | ||
)) | ||
.toList(); | ||
} | ||
|
||
public void create(LocalDate startDate, int totalTermCount) { | ||
activityReportTermInfoRepository.saveAll( | ||
IntStream.range(0, totalTermCount) | ||
.mapToObj(i -> { | ||
LocalDate termStartDate = startDate.plusDays(i * 14L); | ||
LocalDate termEndDate = termStartDate.plusDays(13L); | ||
return ActivityReportTermInfo.builder() | ||
.term(i + 1) | ||
.startDate(termStartDate) | ||
.endDate(termEndDate) | ||
.build(); | ||
}) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
|
||
} |