-
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
15 changed files
with
276 additions
and
95 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
32 changes: 32 additions & 0 deletions
32
src/main/java/ddingdong/ddingdongBE/domain/scorehistory/api/AdminScoreHistoryApi.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,32 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.api; | ||
|
||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.request.RegisterScoreRequest; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.response.ScoreHistoryFilterByClubResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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 = "ScoreHistory - Admin", description = "ScoreHistory Admin API") | ||
@RequestMapping("/server/admin/{clubId}/score") | ||
public interface AdminScoreHistoryApi { | ||
|
||
@Operation(summary = "어드민 점수 등록 API") | ||
@PostMapping | ||
@ResponseStatus(HttpStatus.CREATED) | ||
@SecurityRequirement(name = "AccessToken") | ||
void register(@PathVariable Long clubId, @RequestBody RegisterScoreRequest registerScoreRequest); | ||
|
||
@Operation(summary = "어드민 동아리 점수 내역 목록 조회 API") | ||
@GetMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
@SecurityRequirement(name = "AccessToken") | ||
ScoreHistoryFilterByClubResponse getScoreHistories(@PathVariable Long clubId); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/ddingdong/ddingdongBE/domain/scorehistory/api/ClubScoreHistoryApi.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,28 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.api; | ||
|
||
import ddingdong.ddingdongBE.auth.PrincipalDetails; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.request.RegisterScoreRequest; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.response.ScoreHistoryFilterByClubResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
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.PathVariable; | ||
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 = "ScoreHistory - Club", description = "ScoreHistory Club API") | ||
@RequestMapping("/server/club/my/score") | ||
public interface ClubScoreHistoryApi { | ||
|
||
@Operation(summary = "동아리 내 점수 내역 목록 조회 API") | ||
@GetMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
@SecurityRequirement(name = "AccessToken") | ||
ScoreHistoryFilterByClubResponse getMyScoreHistories(@AuthenticationPrincipal PrincipalDetails principalDetails); | ||
|
||
} |
32 changes: 13 additions & 19 deletions
32
...ava/ddingdong/ddingdongBE/domain/scorehistory/controller/AdminScoreHistoryController.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,38 +1,32 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.controller; | ||
|
||
import ddingdong.ddingdongBE.domain.club.entity.Club; | ||
import ddingdong.ddingdongBE.domain.club.service.ClubService; | ||
import ddingdong.ddingdongBE.domain.scorehistory.api.AdminScoreHistoryApi; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.request.RegisterScoreRequest; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.response.ScoreHistoryFilterByClubResponse; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.response.ScoreHistoryFilterByClubResponse.ScoreHistoryResponse; | ||
import ddingdong.ddingdongBE.domain.scorehistory.service.ScoreHistoryService; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/server/admin/{clubId}/score") | ||
public class AdminScoreHistoryController { | ||
public class AdminScoreHistoryController implements AdminScoreHistoryApi { | ||
|
||
private final ClubService clubService; | ||
private final ScoreHistoryService scoreHistoryService; | ||
|
||
@PostMapping | ||
public void register( | ||
@PathVariable Long clubId, | ||
@RequestBody RegisterScoreRequest registerScoreRequest | ||
) { | ||
public void register(Long clubId, RegisterScoreRequest registerScoreRequest) { | ||
scoreHistoryService.register(clubId, registerScoreRequest); | ||
} | ||
|
||
@GetMapping | ||
public List<ScoreHistoryFilterByClubResponse> getScoreHistories( | ||
@PathVariable Long clubId | ||
) { | ||
return scoreHistoryService.getScoreHistories(clubId); | ||
public ScoreHistoryFilterByClubResponse getScoreHistories(Long clubId) { | ||
Club club = clubService.getByClubId(clubId); | ||
List<ScoreHistoryResponse> scoreHistoryResponses = scoreHistoryService.getScoreHistories(clubId).stream() | ||
.map(ScoreHistoryResponse::from) | ||
.toList(); | ||
return ScoreHistoryFilterByClubResponse.of(club, scoreHistoryResponses); | ||
} | ||
} |
25 changes: 13 additions & 12 deletions
25
...java/ddingdong/ddingdongBE/domain/scorehistory/controller/ClubScoreHistoryController.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,28 +1,29 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.controller; | ||
|
||
import ddingdong.ddingdongBE.auth.PrincipalDetails; | ||
import ddingdong.ddingdongBE.domain.club.entity.Club; | ||
import ddingdong.ddingdongBE.domain.club.service.ClubService; | ||
import ddingdong.ddingdongBE.domain.scorehistory.api.ClubScoreHistoryApi; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.response.ScoreHistoryFilterByClubResponse; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.response.ScoreHistoryFilterByClubResponse.ScoreHistoryResponse; | ||
import ddingdong.ddingdongBE.domain.scorehistory.service.ScoreHistoryService; | ||
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/club/my/score") | ||
public class ClubScoreHistoryController { | ||
public class ClubScoreHistoryController implements ClubScoreHistoryApi { | ||
|
||
private final ClubService clubService; | ||
private final ScoreHistoryService scoreHistoryService; | ||
|
||
@GetMapping | ||
public List<ScoreHistoryFilterByClubResponse> getMyScoreHistories( | ||
@AuthenticationPrincipal PrincipalDetails principalDetails | ||
) { | ||
return scoreHistoryService.getMyScoreHistories(principalDetails.getUser().getId()); | ||
public ScoreHistoryFilterByClubResponse getMyScoreHistories(PrincipalDetails principalDetails) { | ||
Club club = clubService.getByUserId(principalDetails.getUser().getId()); | ||
List<ScoreHistoryResponse> scoreHistoryResponses = scoreHistoryService.getMyScoreHistories(club.getId()) | ||
.stream() | ||
.map(ScoreHistoryResponse::from) | ||
.toList(); | ||
return ScoreHistoryFilterByClubResponse.of(club, scoreHistoryResponses); | ||
} | ||
} |
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
73 changes: 47 additions & 26 deletions
73
...gdongBE/domain/scorehistory/controller/dto/response/ScoreHistoryFilterByClubResponse.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,39 +1,60 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.controller.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import ddingdong.ddingdongBE.domain.club.entity.Club; | ||
import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory; | ||
|
||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ScoreHistoryFilterByClubResponse { | ||
private String scoreCategory; | ||
|
||
private String reason; | ||
|
||
private float amount; | ||
@Schema( | ||
name = "ScoreHistoryFilterByClubResponse", | ||
description = "어드민 - 동아리 점수 변동 내역 목록 응답" | ||
) | ||
@Builder | ||
public record ScoreHistoryFilterByClubResponse( | ||
|
||
private float remainingScore; | ||
@Schema(description = "동아리 총 점수", example = "50") | ||
float totalScore, | ||
@ArraySchema(schema = @Schema(description = "점수내역 목록", implementation = ScoreHistoryResponse.class)) | ||
List<ScoreHistoryResponse> scoreHistories | ||
) { | ||
|
||
private LocalDateTime createdAt; | ||
public static ScoreHistoryFilterByClubResponse of(Club club, List<ScoreHistoryResponse> scoreHistories) { | ||
return ScoreHistoryFilterByClubResponse.builder() | ||
.totalScore(club.getScore().getValue()) | ||
.scoreHistories(scoreHistories) | ||
.build(); | ||
} | ||
|
||
@Schema( | ||
name = "ScoreHistoryResponse", | ||
description = "점수 변동 내역 응답" | ||
) | ||
@Builder | ||
public ScoreHistoryFilterByClubResponse(String scoreCategory, String reason, float amount, float remainingScore, LocalDateTime createdAt) { | ||
this.scoreCategory = scoreCategory; | ||
this.reason = reason; | ||
this.amount = amount; | ||
this.remainingScore = remainingScore; | ||
this.createdAt = createdAt; | ||
} | ||
public record ScoreHistoryResponse( | ||
|
||
@Schema(description = "점수 내역 카테고리", example = "활동보고서") | ||
String scoreCategory, | ||
@Schema(description = "점수 내역 이유", example = "활동보고서 작성") | ||
String reason, | ||
@Schema(description = "변동 점수", example = "10") | ||
float amount, | ||
@Schema(description = "작성일", example = "2024-01-01") | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
LocalDateTime createdAt | ||
) { | ||
|
||
public static ScoreHistoryResponse from(ScoreHistory scoreHistory) { | ||
return ScoreHistoryResponse.builder() | ||
.scoreCategory(scoreHistory.getScoreCategory().getCategory()) | ||
.reason(scoreHistory.getReason()) | ||
.amount(scoreHistory.getAmount()) | ||
.createdAt(scoreHistory.getCreatedAt()) | ||
.build(); | ||
} | ||
|
||
public static ScoreHistoryFilterByClubResponse of(final ScoreHistory scoreHistory) { | ||
return ScoreHistoryFilterByClubResponse.builder() | ||
.scoreCategory(scoreHistory.getScoreCategory().getCategory()) | ||
.reason(scoreHistory.getReason()) | ||
.amount(scoreHistory.getAmount()) | ||
.remainingScore(scoreHistory.getRemainingScore()) | ||
.createdAt(scoreHistory.getCreatedAt()) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.