-
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.
Merge pull request #458 from team-yello/develop
�deploy [staging]
- Loading branch information
Showing
29 changed files
with
554 additions
and
28 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
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
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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/yello/server/domain/statistics/controller/StatisticsController.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,45 @@ | ||
package com.yello.server.domain.statistics.controller; | ||
|
||
import static com.yello.server.global.common.SuccessCode.READ_USER_GROUP_SCHOOL_ATTACK_STATISTICS_SUCCESS; | ||
import static com.yello.server.global.common.factory.PaginationFactory.createPageable; | ||
|
||
import com.yello.server.domain.statistics.dto.SchoolAttackStatisticsVO; | ||
import com.yello.server.domain.statistics.dto.response.StatisticsUserGroupSchoolAttackResponse; | ||
import com.yello.server.domain.statistics.service.StatisticsService; | ||
import com.yello.server.global.common.dto.BaseResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.val; | ||
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; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/statistics") | ||
public class StatisticsController { | ||
|
||
private final StatisticsService statisticsService; | ||
|
||
@GetMapping("/user-group/school-attack") | ||
public BaseResponse<StatisticsUserGroupSchoolAttackResponse> getSchoolAttackStatistics( | ||
@RequestParam(value = "page") Integer page) { | ||
val data = statisticsService.getSchoolAttackStatistics(createPageable(page, 10)); | ||
return BaseResponse.success(READ_USER_GROUP_SCHOOL_ATTACK_STATISTICS_SUCCESS, data); | ||
} | ||
|
||
@GetMapping("/user-group/school-attack/{groupName}") | ||
public BaseResponse<SchoolAttackStatisticsVO> getSchoolAttackStatisticsByGroupName( | ||
@PathVariable(value = "groupName") String groupName) { | ||
val data = statisticsService.getSchoolAttackStatisticsByGroupName(groupName); | ||
return BaseResponse.success(READ_USER_GROUP_SCHOOL_ATTACK_STATISTICS_SUCCESS, data); | ||
} | ||
|
||
@GetMapping("/user-group/school-attack/group-name/{groupName}") | ||
public BaseResponse<StatisticsUserGroupSchoolAttackResponse> getSchoolAttackStatisticsLikeGroupName( | ||
@PathVariable(value = "groupName") String groupName, @RequestParam(value = "page") Integer page) { | ||
val data = statisticsService.getSchoolAttackStatisticsLikeGroupName(groupName, createPageable(page, 10)); | ||
return BaseResponse.success(READ_USER_GROUP_SCHOOL_ATTACK_STATISTICS_SUCCESS, data); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/yello/server/domain/statistics/dto/NewStatisticsUserGroupVO.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,10 @@ | ||
package com.yello.server.domain.statistics.dto; | ||
|
||
public record NewStatisticsUserGroupVO( | ||
String userGroupName, | ||
Long userCount, | ||
Long voteCount, | ||
Long rankNumber | ||
) { | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/yello/server/domain/statistics/dto/SchoolAttackStatisticsVO.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,35 @@ | ||
package com.yello.server.domain.statistics.dto; | ||
|
||
import com.yello.server.domain.statistics.entity.StatisticsUserGroup; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record SchoolAttackStatisticsVO( | ||
String userGroupName, | ||
Long userCount, | ||
Long voteCount, | ||
Long score, | ||
Long rankNumber, | ||
Long prevUserCount, | ||
Long prevVoteCount, | ||
Long prevScore, | ||
Long prevRankNumber | ||
) { | ||
|
||
public static SchoolAttackStatisticsVO of(StatisticsUserGroup statisticsUserGroup) { | ||
final Long score = statisticsUserGroup.getUserCount() + 2 * statisticsUserGroup.getVoteCount(); | ||
final Long prevScore = statisticsUserGroup.getPrevUserCount() + 2 * statisticsUserGroup.getPrevVoteCount(); | ||
|
||
return SchoolAttackStatisticsVO.builder() | ||
.userGroupName(statisticsUserGroup.getGroupName()) | ||
.userCount(statisticsUserGroup.getUserCount()) | ||
.voteCount(statisticsUserGroup.getVoteCount()) | ||
.score(score) | ||
.rankNumber(statisticsUserGroup.getRankNumber()) | ||
.prevUserCount(statisticsUserGroup.getPrevUserCount()) | ||
.prevVoteCount(statisticsUserGroup.getVoteCount()) | ||
.prevScore(prevScore) | ||
.prevRankNumber(statisticsUserGroup.getPrevRankNumber()) | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../yello/server/domain/statistics/dto/response/StatisticsUserGroupSchoolAttackResponse.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,16 @@ | ||
package com.yello.server.domain.statistics.dto.response; | ||
|
||
import com.yello.server.domain.statistics.dto.SchoolAttackStatisticsVO; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record StatisticsUserGroupSchoolAttackResponse( | ||
Long pageCount, | ||
Long totalCount, | ||
LocalDateTime updatedAt, | ||
List<SchoolAttackStatisticsVO> statisticsList | ||
) { | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/com/yello/server/domain/statistics/entity/StatisticsUserGroup.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,95 @@ | ||
package com.yello.server.domain.statistics.entity; | ||
|
||
import com.yello.server.global.common.dto.AuditingTimeEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.ConstraintMode; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.ForeignKey; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.UniqueConstraint; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
import org.hibernate.annotations.DynamicInsert; | ||
|
||
@Entity | ||
@Getter | ||
@SuperBuilder | ||
@DynamicInsert | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table( | ||
uniqueConstraints = { | ||
@UniqueConstraint( | ||
name = "statistics_user_group__group_name__unique", | ||
columnNames = {"groupName"} | ||
), | ||
} | ||
) | ||
public class StatisticsUserGroup extends AuditingTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column | ||
@JoinColumn( | ||
name = "groupName", | ||
foreignKey = @ForeignKey( | ||
value = ConstraintMode.NO_CONSTRAINT, | ||
foreignKeyDefinition = "FOREIGN KEY (group_name) REFERENCES user_group (group_name)" | ||
/** | ||
* NOTE ForeignKey Constraint는 직접 설정해주어야한다. | ||
*/ | ||
) | ||
) | ||
private String groupName; | ||
|
||
@Column | ||
private Long voteCount; | ||
|
||
@Column | ||
private Long userCount; | ||
|
||
@Column | ||
private Long alpha; | ||
|
||
@Column | ||
private Long rankNumber; | ||
|
||
@Column | ||
private Long prevVoteCount; | ||
|
||
@Column | ||
private Long prevUserCount; | ||
|
||
@Column | ||
private Long prevAlpha; | ||
|
||
@Column | ||
private Long prevRankNumber; | ||
|
||
public void update(Long voteCount, Long userCount, Long alpha, Long rankNumber, Long prevVoteCount, | ||
Long prevUserCount, | ||
Long prevAlpha, Long prevRankNumber) { | ||
this.voteCount = voteCount; | ||
this.userCount = userCount; | ||
this.alpha = alpha; | ||
this.rankNumber = rankNumber; | ||
this.prevVoteCount = prevVoteCount; | ||
this.prevUserCount = prevUserCount; | ||
this.prevAlpha = prevAlpha; | ||
this.prevRankNumber = prevRankNumber; | ||
} | ||
|
||
public void updateRankNumber(Long rankNumber, Long prevRankNumber) { | ||
this.rankNumber = rankNumber; | ||
this.prevRankNumber = prevRankNumber; | ||
} | ||
} |
Oops, something went wrong.