Skip to content

Commit

Permalink
Merge pull request #458 from team-yello/develop
Browse files Browse the repository at this point in the history
�deploy [staging]
  • Loading branch information
euije authored Feb 19, 2024
2 parents 5d9de3c + 6110304 commit 07826c4
Show file tree
Hide file tree
Showing 29 changed files with 554 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import com.yello.server.infrastructure.firebase.dto.request.NotificationCustomMessage;
import com.yello.server.infrastructure.firebase.service.NotificationService;
import java.util.List;
import javax.annotation.Nullable;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -75,9 +74,9 @@ public BaseResponse<AdminLoginResponse> postAdminLogin(@RequestBody AdminLoginRe

@GetMapping("/user")
public BaseResponse<AdminUserResponse> getUserAdmin(@AccessTokenUser User user,
@RequestParam Integer page,
@Nullable @RequestParam String field,
@Nullable @RequestParam String value) {
@RequestParam(value = "page") Integer page,
@RequestParam(value = "field", required = false) String field,
@RequestParam(value = "value", required = false) String value) {
val data = (field == null && value == null)
? adminService.findUser(user.getId(), createPageableByNameSortDescLimitTen(page))
: adminService.findUserContaining(user.getId(),
Expand All @@ -88,28 +87,28 @@ public BaseResponse<AdminUserResponse> getUserAdmin(@AccessTokenUser User user,

@GetMapping("/user/{id}")
public BaseResponse<AdminUserDetailResponse> getUserDetailAdmin(@AccessTokenUser User user,
@PathVariable Long id) {
@PathVariable(value = "id") Long id) {
val data = adminService.findUserDetail(user.getId(), id);
return BaseResponse.success(READ_USER_DETAIL_ADMIN_SUCCESS, data);
}

@PostMapping("/user/{id}")
public BaseResponse<EmptyObject> postUserDetailAdmin(@AccessTokenUser User user,
@PathVariable Long id, @RequestBody AdminUserDetailRequest request) {
@PathVariable(value = "id") Long id, @RequestBody AdminUserDetailRequest request) {
val data = adminService.updateUserDetail(user.getId(), id, request);
return BaseResponse.success(UPDATE_USER_DETAIL_ADMIN_SUCCESS);
}

@DeleteMapping("/user")
public BaseResponse deleteUser(@AccessTokenUser User user, @RequestParam Long userId) {
public BaseResponse deleteUser(@AccessTokenUser User user, @RequestParam(value = "userId") Long userId) {
adminService.deleteUser(user.getId(), userId);
return BaseResponse.success(DELETE_USER_ADMIN_SUCCESS);
}

@GetMapping("/cooldown")
public BaseResponse<AdminCooldownResponse> getCooldownAdmin(@AccessTokenUser User user,
@RequestParam Integer page,
@Nullable @RequestParam String yelloId) {
@RequestParam(value = "page") Integer page,
@RequestParam(value = "yelloId", required = false) String yelloId) {
val data = yelloId == null
? adminService.findCooldown(user.getId(), createPageableLimitTen(page))
: adminService.findCooldownContaining(user.getId(), createPageableLimitTen(page),
Expand All @@ -118,37 +117,39 @@ public BaseResponse<AdminCooldownResponse> getCooldownAdmin(@AccessTokenUser Use
}

@DeleteMapping("/cooldown")
public BaseResponse deleteCooldown(@AccessTokenUser User user, @RequestParam Long cooldownId) {
public BaseResponse deleteCooldown(@AccessTokenUser User user,
@RequestParam(value = "cooldownId") Long cooldownId) {
adminService.deleteCooldown(user.getId(), cooldownId);
return BaseResponse.success(DELETE_COOLDOWN_ADMIN_SUCCESS);
}

@GetMapping("/question")
public BaseResponse<AdminQuestionResponse> getQuestionAdmin(@AccessTokenUser User user,
@RequestParam Integer page) {
@RequestParam(value = "page") Integer page) {
val data = adminService.findQuestion(user.getId(), createPageable(page, 20));
return BaseResponse.success(READ_QUESTION_ADMIN_SUCCESS, data);
}

@GetMapping("/question/{id}")
public BaseResponse<AdminQuestionDetailResponse> getQuestionDetailAdmin(
@AccessTokenUser User user,
@PathVariable Long id) {
@PathVariable(value = "id") Long id) {
val data = adminService.findQuestionDetail(user.getId(), id);
return BaseResponse.success(READ_QUESTION_DETAIL_ADMIN_SUCCESS, data);
}

@PostMapping("/question/{id}")
public BaseResponse<EmptyObject> postQuestionSendAdmin(@AccessTokenUser User user,
@PathVariable Long id, @RequestBody AdminQuestionVoteRequest request) {
@PathVariable(value = "id") Long id, @RequestBody AdminQuestionVoteRequest request) {
val data = adminService.createVote(user.getId(), id, request);
data.forEach(notificationService::sendYelloNotification);

return BaseResponse.success(CREATE_VOTE_SUCCESS, EmptyObject.builder().build());
}

@DeleteMapping("/question")
public BaseResponse deleteQuestion(@AccessTokenUser User user, @RequestParam Long questionId) {
public BaseResponse deleteQuestion(@AccessTokenUser User user,
@RequestParam(value = "questionId") Long questionId) {
adminService.deleteQuestion(user.getId(), questionId);
return BaseResponse.success(DELETE_QUESTION_ADMIN_SUCCESS);
}
Expand All @@ -162,7 +163,7 @@ public BaseResponse<EmptyObject> postCustomNotificationSendAdmin(@AccessTokenUse
}

@GetMapping("/configuration")
public BaseResponse<AdminConfigurationResponse> getConfigurations(@RequestParam("tag") String tag,
public BaseResponse<AdminConfigurationResponse> getConfigurations(@RequestParam(value = "tag") String tag,
@AccessTokenUser User user) {
final AdminConfigurationType configurationType = AdminConfigurationType.fromCode(tag);
val data = adminService.getConfigurations(user.getId(), configurationType);
Expand Down Expand Up @@ -194,7 +195,7 @@ public BaseResponse<EmptyObject> createNotice(@AccessTokenUser User user,
}

@PostMapping("/notice/{id}")
public BaseResponse<EmptyObject> updateNotice(@AccessTokenUser User user, @PathVariable("id") Long noticeId,
public BaseResponse<EmptyObject> updateNotice(@AccessTokenUser User user, @PathVariable(value = "id") Long noticeId,
@RequestBody AdminNoticeCreateRequest request) {
val data = adminService.updateNotice(user.getId(), noticeId, request);
return BaseResponse.success(NOTICE_UPDATE_DETAIL_ADMIN_SUCCESS, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
public enum AdminConfigurationType {
ACCESS_TOKEN_TIME("ACCESS_TOKEN_TIME"),
REFRESH_TOKEN_TIME("REFRESH_TOKEN_TIME"),
ADMIN_SITE_PASSWORD("ADMIN_SITE_PASSWORD");
ADMIN_SITE_PASSWORD("ADMIN_SITE_PASSWORD"),
STATISTICS_USER_GROUP_START_DATE("STATISTICS_USER_GROUP_START_DATE");

private final String initial;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected void doFilterInternal(
|| requestPath.startsWith("/v2/apple/notifications")
|| requestPath.startsWith("/v2/google/notifications")
|| requestPath.startsWith("/api/v1/admob/verify")
|| requestPath.startsWith("/api/v1/statistics")
|| (requestPath.startsWith("/api/v1/auth")
&& !requestPath.startsWith("/api/v1/auth/token/issue"))) {
filterChain.doFilter(request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
|| requestPath.startsWith("/api/v1/auth")
|| requestPath.startsWith("/v2/apple/notifications")
|| requestPath.startsWith("/v2/google/notifications")
|| requestPath.startsWith("/api/v1/admob/verify")) {
|| requestPath.startsWith("/api/v1/admob/verify")
|| requestPath.startsWith("/api/v1/statistics")) {
filterChain.doFilter(request, response);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.AccessLevel;
Expand All @@ -22,9 +21,6 @@
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(
indexes = {
@Index(name = "idx__group__name", columnList = "groupName")
},
uniqueConstraints = {
@UniqueConstraint(
name = "user_group__sub_group_name__unique",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

public interface UserGroupJpaRepository extends JpaRepository<UserGroup, Long> {

List<UserGroup> findAllByGroupName(String groupName);

@Query("select count (distinct(s.groupName)) from UserGroup s " +
"where s.groupName " +
"like CONCAT('%',:groupName,'%' )" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface UserGroupRepository {

Optional<UserGroup> findById(Long id);

List<UserGroup> findAllByGroupName(String groupName);

Integer countDistinctGroupNameContaining(String groupName, UserGroupType userGroupType);

List<String> findDistinctGroupNameContaining(String groupName, UserGroupType userGroupType, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public Optional<UserGroup> findById(Long id) {
return userGroupJpaRepository.findById(id);
}

@Override
public List<UserGroup> findAllByGroupName(String groupName) {
return userGroupJpaRepository.findAllByGroupName(groupName);
}

@Override
public Integer countDistinctGroupNameContaining(String groupName, UserGroupType userGroupType) {
return userGroupJpaRepository.countDistinctGroupNameContaining(groupName, userGroupType);
Expand Down
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);
}
}
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
) {

}
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();
}
}
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
) {

}
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;
}
}
Loading

0 comments on commit 07826c4

Please sign in to comment.