Skip to content

Commit

Permalink
Merge pull request #100 from playkuround/develop
Browse files Browse the repository at this point in the history
release (ver 2.0.5)
  • Loading branch information
redcarrot1 authored Apr 1, 2024
2 parents 0e073e1 + 0e149a9 commit 3f3622a
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 74 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = 'com.playkuround'
version = '2.0.4'
version = '2.0.5'

java {
sourceCompatibility = '17'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
import com.playkuround.playkuroundserver.domain.score.domain.ScoreType;
import com.playkuround.playkuroundserver.domain.user.dao.UserRepository;
import com.playkuround.playkuroundserver.domain.user.domain.User;
import com.playkuround.playkuroundserver.global.util.DateTimeUtils;
import com.playkuround.playkuroundserver.global.util.Location;
import com.playkuround.playkuroundserver.global.util.LocationDistanceUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class AdventureService {
Expand Down Expand Up @@ -63,7 +66,8 @@ private void saveAdventure(User user, Landmark landmark, ScoreType scoreType, lo
}

private void updateLandmarkHighestScore(User user, Landmark landmark) {
long sumScore = adventureRepository.getSumScoreByUserAndLandmark(user, landmark);
LocalDateTime monthStartDateTime = DateTimeUtils.getMonthStartDateTime();
long sumScore = adventureRepository.getSumScoreByUserAndLandmark(user, landmark, monthStartDateTime);
landmark.updateFirstUser(user, sumScore);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand All @@ -17,23 +18,29 @@ public interface AdventureRepository extends JpaRepository<Adventure, Long> {
@Query(value =
"SELECT new com.playkuround.playkuroundserver.domain.score.dto.NicknameAndScore(a.user.nickname, cast(SUM(a.score) as integer)) " +
"FROM Adventure a " +
"where a.landmark.id=:landmark " +
"where a.landmark.id=:landmark AND a.createdAt >= :from " +
"GROUP BY a.user.id " +
"ORDER BY SUM(a.score) DESC, a.user.nickname DESC " +
"LIMIT 100")
List<NicknameAndScore> findRankTop100DescByLandmarkId(@Param(value = "landmark") Long landmarkId);
List<NicknameAndScore> findRankTop100DescByLandmarkId(@Param(value = "landmark") Long landmarkId, @Param(value = "from") LocalDateTime from);

@Query(value =
"SELECT new com.playkuround.playkuroundserver.domain.score.dto.RankAndScore(cast(user_rank as integer), cast(score as integer)) FROM " +
"(SELECT a.user.id as user_id, (RANK() over (order by SUM(a.score) desc)) as user_rank, SUM(a.score) as score " +
"FROM Adventure a " +
"where a.landmark.id=:landmark " +
"where a.landmark.id=:landmark AND a.createdAt >= :from " +
"GROUP BY a.user.id) " +
"where user_id=:#{#user.id}")
Optional<RankAndScore> findMyRankByLandmarkId(@Param(value = "user") User user, @Param(value = "landmark") Long landmarkId);
Optional<RankAndScore> findMyRankByLandmarkId(@Param(value = "user") User user,
@Param(value = "landmark") Long landmarkId,
@Param(value = "from") LocalDateTime from);

@Query("SELECT SUM(a.score) FROM Adventure a WHERE a.user.id=:#{#user.id} AND a.landmark.id=:#{#landmark.id}")
long getSumScoreByUserAndLandmark(@Param(value = "user") User user, @Param(value = "landmark") Landmark landmark);
@Query("SELECT SUM(a.score) " +
"FROM Adventure a " +
"WHERE a.user.id=:#{#user.id} AND a.landmark.id=:#{#landmark.id} AND a.createdAt >= :from")
long getSumScoreByUserAndLandmark(@Param(value = "user") User user,
@Param(value = "landmark") Landmark landmark,
@Param(value = "from") LocalDateTime from);

long countByUserAndLandmark(User user, Landmark requestSaveLandmark);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public class AuthEmailApi {
private final AuthEmailVerifyService authEmailVerifyService;

@PostMapping
@Operation(summary = "인증메일 전송", description = "해당 메일로 알파벳 대소문자, 숫자 조합으로 이루어진 6자리의 인증 코드를 전송합니다. " +
@Operation(summary = "인증메일 전송", description = "해당 메일로 숫자 6자리의 인증 코드를 전송합니다. " +
"인증 메일 전송은 자정을 기준으로 최대 5번까지 가능합니다. 또한 인증 유효시간은 5분입니다.")
public ApiResponse<AuthEmailSendResponse> authEmailSend(@RequestBody @Valid AuthEmailSendRequest requestDto) {
AuthEmailInfo authEmailInfo = authEmailSendService.sendAuthEmail(requestDto.getTarget());
AuthEmailInfo authEmailInfo = authEmailSendService.sendAuthEmail(requestDto.getTarget().toLowerCase());
return ApiUtils.success(AuthEmailSendResponse.from(authEmailInfo));
}

@GetMapping
@Operation(summary = "인증 코드 확인", description = "인증 코드를 확인합니다. 인증 코드는 메일 전송 후 5분간 유효합니다.")
public ApiResponse<AuthVerifyEmailResponse> authEmailVerify(@RequestParam("code") String code,
@RequestParam("email") String email) {
AuthVerifyEmailResult authVerifyEmailResult = authEmailVerifyService.verifyAuthEmail(code, email);
AuthVerifyEmailResult authVerifyEmailResult = authEmailVerifyService.verifyAuthEmail(code, email.toLowerCase());
return ApiUtils.success(AuthVerifyEmailResponse.from(authVerifyEmailResult));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.playkuround.playkuroundserver.domain.badge.application.specialday_badge;

import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.global.util.DateUtils;
import com.playkuround.playkuroundserver.global.util.DateTimeUtils;

import java.util.Set;

Expand All @@ -13,7 +13,7 @@ public class ArborDayBadge implements SpecialDayBadge {
@Override
public boolean supports(Set<BadgeType> userBadgeSet) {
BadgeType badgeType = getBadgeType();
return DateUtils.isTodayArborDay() && !userBadgeSet.contains(badgeType);
return DateTimeUtils.isTodayArborDay() && !userBadgeSet.contains(badgeType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.playkuround.playkuroundserver.domain.badge.application.specialday_badge;

import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.global.util.DateUtils;
import com.playkuround.playkuroundserver.global.util.DateTimeUtils;

import java.util.Set;

Expand All @@ -13,7 +13,7 @@ public class ChildrenDayBadge implements SpecialDayBadge {
@Override
public boolean supports(Set<BadgeType> userBadgeSet) {
BadgeType badgeType = getBadgeType();
return DateUtils.isTodayChildrenDay() && !userBadgeSet.contains(badgeType);
return DateTimeUtils.isTodayChildrenDay() && !userBadgeSet.contains(badgeType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.playkuround.playkuroundserver.domain.badge.application.specialday_badge;

import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.global.util.DateUtils;
import com.playkuround.playkuroundserver.global.util.DateTimeUtils;

import java.util.Set;

Expand All @@ -13,7 +13,7 @@ public class DuckDayBadge implements SpecialDayBadge {
@Override
public boolean supports(Set<BadgeType> userBadgeSet) {
BadgeType badgeType = getBadgeType();
return DateUtils.isTodayDuckDay() && !userBadgeSet.contains(badgeType);
return DateTimeUtils.isTodayDuckDay() && !userBadgeSet.contains(badgeType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.playkuround.playkuroundserver.domain.badge.application.specialday_badge;

import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.global.util.DateUtils;
import com.playkuround.playkuroundserver.global.util.DateTimeUtils;

import java.util.Set;

Expand All @@ -13,7 +13,7 @@ public class FoundationDayBadge implements SpecialDayBadge {
@Override
public boolean supports(Set<BadgeType> userBadgeSet) {
BadgeType badgeType = getBadgeType();
return DateUtils.isTodayFoundationDay() && !userBadgeSet.contains(badgeType);
return DateTimeUtils.isTodayFoundationDay() && !userBadgeSet.contains(badgeType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.playkuround.playkuroundserver.domain.badge.application.specialday_badge;

import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.global.util.DateUtils;
import com.playkuround.playkuroundserver.global.util.DateTimeUtils;

import java.util.Set;

Expand All @@ -13,7 +13,7 @@ public class WhiteDayBadge implements SpecialDayBadge {
@Override
public boolean supports(Set<BadgeType> userBadgeSet) {
BadgeType badgeType = getBadgeType();
return DateUtils.isTodayWhiteDay() && !userBadgeSet.contains(badgeType);
return DateTimeUtils.isTodayWhiteDay() && !userBadgeSet.contains(badgeType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
public interface BadgeRepository extends JpaRepository<Badge, Long> {
List<Badge> findByUser(User user);

boolean existsByUserAndBadgeType(User user, BadgeType conqueror);
boolean existsByUserAndBadgeType(User user, BadgeType badgeType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public void updateFirstUser(User user, long score) {
this.highestScore = score;
}
}

public void deleteRank() {
this.firstUser = null;
this.highestScore = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.playkuround.playkuroundserver.domain.score.dto.RankAndScore;
import com.playkuround.playkuroundserver.domain.score.dto.response.ScoreRankingResponse;
import com.playkuround.playkuroundserver.domain.user.domain.User;
import com.playkuround.playkuroundserver.global.util.DateTimeUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
Expand All @@ -20,12 +22,13 @@ public class LandmarkRankService {
@Transactional(readOnly = true)
public ScoreRankingResponse getRankTop100ByLandmark(User user, Long landmarkId) {
ScoreRankingResponse response = ScoreRankingResponse.createEmptyResponse();
LocalDateTime monthStartDateTime = DateTimeUtils.getMonthStartDateTime();

List<NicknameAndScore> nicknameAndScores = adventureRepository.findRankTop100DescByLandmarkId(landmarkId);
List<NicknameAndScore> nicknameAndScores = adventureRepository.findRankTop100DescByLandmarkId(landmarkId, monthStartDateTime);
nicknameAndScores.forEach(nicknameAndScore ->
response.addRank(nicknameAndScore.nickname(), nicknameAndScore.score()));

RankAndScore rankAndScore = adventureRepository.findMyRankByLandmarkId(user, landmarkId)
RankAndScore rankAndScore = adventureRepository.findMyRankByLandmarkId(user, landmarkId, monthStartDateTime)
.orElseGet(() -> new RankAndScore(0, 0));
response.setMyRank(rankAndScore.ranking(), rankAndScore.score());
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.playkuround.playkuroundserver.domain.common.AppVersion;
import com.playkuround.playkuroundserver.domain.common.SystemCheck;
import com.playkuround.playkuroundserver.domain.user.api.request.ManualBadgeSaveRequest;
import com.playkuround.playkuroundserver.domain.user.application.NewMonthUpdateService;
import com.playkuround.playkuroundserver.global.common.response.ApiResponse;
import com.playkuround.playkuroundserver.global.util.ApiUtils;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -22,9 +23,10 @@
public class AdminApi {

private final BadgeService badgeService;
private final NewMonthUpdateService newMonthUpdateService;

@PostMapping("/app-version")
@Operation(summary = "앱 버전 올리기(관리자모드)", description = "앱 버전을 올립니다. 이전버전 사용자에게 공지 메시지를 보냅니다.",
@Operation(summary = "앱 버전 올리기", description = "앱 버전을 올립니다. 이전버전 사용자에게 공지 메시지를 보냅니다.",
parameters = {
@Parameter(name = "version", description = "최신 앱 버전", example = "2.0.2", required = true),
@Parameter(name = "os", description = "모바일 운영체제(android 또는 ios)", example = "android", required = true)
Expand All @@ -37,20 +39,32 @@ public ApiResponse<Void> updateAppVersion(@RequestParam("version") String appVer
}

@PostMapping("/system-available")
@Operation(summary = "시스템 점검 유무 변경하기(관리자모드)", description = "시스템 점검 유무를 변경합니다.")
@Operation(summary = "시스템 점검 유무 변경하기", description = "시스템 점검 유무를 변경합니다.")
public ApiResponse<Void> changeSystemAvailable(@RequestParam("available") boolean appVersion) {
SystemCheck.changeSystemAvailable(appVersion);
return ApiUtils.success(null);
}

@PostMapping("badges/manual")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "수동 뱃지 등록(관리자권한)", description = "수동으로 뱃지를 등록합니다. 이미 획득한 뱃지였다면 false를 반환합니다. " +
@Operation(summary = "수동 뱃지 등록", description = "수동으로 뱃지를 등록합니다. 이미 획득한 뱃지였다면 false를 반환합니다. " +
"설정에 따라 개인 메시지로 등록할 수 있습니다.")
public ApiResponse<Boolean> saveManualBadge(@RequestBody @Valid ManualBadgeSaveRequest request) {
BadgeType badgeType = BadgeType.valueOf(request.getBadge());
boolean response = badgeService.saveManualBadge(request.getUserEmail(), badgeType, request.isRegisterMessage());
return ApiUtils.success(response);
}

@PostMapping("new-month-update")
@Operation(summary = "월(month) 업데이트",
description = "== 해당 API는 아래의 작업을 포함합니다. ==<br>" +
"1. MONTHLY_RANKING_1, MONTHLY_RANKING_2, MONTHLY_RANKING_3 부여(+메시지 부여)<br>" +
"2. 랜드마크별 랭킹 초기화<br>" +
"3. 유저별 최고 랭킹, 스코어 기록<br>" +
"4. 종합 랭킹 초기화")
public ApiResponse<Void> updateNewMonth() {
newMonthUpdateService.updateMonth();
return ApiUtils.success(null);
}

}
Loading

0 comments on commit 3f3622a

Please sign in to comment.