Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DailyChallenge {

@Column(name = "created_at", updatable = false)
@CreationTimestamp
private LocalDateTime createdAt;
private LocalDate createdAt;

@Enumerated(EnumType.STRING)
private Category category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDate;
import java.util.Optional;

public interface DailyChallengeRepository extends JpaRepository<DailyChallenge, Long> {
Optional<DailyChallenge> findByIsActiveTrue();
Optional<DailyChallenge> findByCreatedAtAndIsActive(LocalDate createdAt, boolean isActive);

@Modifying
@Query("UPDATE DailyChallenge dc SET dc.isActive = false WHERE dc.isActive = true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
Expand All @@ -33,8 +34,10 @@ public ChallengeTodayResponse getTodayChallengeForUser(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new RuntimeException("해당 유저가 존재하지 않습니다."));

LocalDate today = LocalDate.now();

// 오늘의 챌린지 조회 or GPT로 생성
DailyChallenge dailyChallenge = dailyChallengeRepository.findByIsActiveTrue()
DailyChallenge dailyChallenge = dailyChallengeRepository.findByCreatedAtAndIsActive(today, true)
.orElseGet(() -> {
// 이전 챌린지 비활성화
dailyChallengeRepository.deactivateAll();
Expand All @@ -47,6 +50,7 @@ public ChallengeTodayResponse getTodayChallengeForUser(Long userId) {
.rewardMoney(gptResponse.getRewardMoney())
.carbonKeyword(gptResponse.getCarbonKeyword())
.category(gptResponse.getCategory())
.createdAt(today)
.isActive(true)
.build();
return dailyChallengeRepository.save(newChallenge);
Expand Down Expand Up @@ -112,7 +116,7 @@ public List<UserChallengeHistoryDto> getUserChallengeHistory(Long userId) {
return userChallenges.stream()
.map(uc -> UserChallengeHistoryDto.builder()
.title(uc.getDailyChallenge().getTitle())
.createdAt(uc.getDailyChallenge().getCreatedAt().toLocalDate()) // 여기 변환
.createdAt(uc.getDailyChallenge().getCreatedAt()) // 여기 변환
.isCompleted(uc.isCompleted())
.build())
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public AIChallengePromptResult generateChallenge() {
- challengeTitle은 15자 이내의 짧고 명확한 챌린지 제목
- rewardMoney는 너가 판단하기에 챌린지 난이도에 따라 5 ~ 20으로 줘!
- carbonKeyword는 기존 탄소 소비 분석 기능에서 사용하는 실생활 소비 키워드여야 해 (예: 다회용컵, 채식, 대중교통, 전기차, 에너지 절약, 음식물 쓰레기 줄이기 등)
- category는 FOOD, TRANSPORTATION, CLOTHING, HOUSING_ENERGY, RECYCLE_WASTE, LIFESTYLE_CONSUMPTION, ETC 중 하나
- category는 FOOD, TRANSPORTATION, CLOTHING, HOUSING_ENERGY, RECYCLE_WASTE, LIFESTYLE_CONSUMPTION 중 하나
{
"challengeTitle": (챌린지명),
"category": (위 category 중 하나),
"goalCount": (목표횟수),
"rewardMoney": (보상 돈),
"carbonKeyword": (소비 키워드),
"category": (위 category 중 하나),
}
""";

Expand Down