-
Notifications
You must be signed in to change notification settings - Fork 0
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 #52 from KU-Taverse/fix/quest
[Fix] 10/11 요구사항 반영
- Loading branch information
Showing
12 changed files
with
236 additions
and
99 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
18 changes: 3 additions & 15 deletions
18
src/main/java/ku/user/domain/quest/dao/QuestRepository.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,21 +1,9 @@ | ||
package ku.user.domain.quest.dao; | ||
|
||
import feign.Param; | ||
import ku.user.domain.quest.domain.Quest; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import javax.swing.text.html.Option; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
public interface QuestRepository extends JpaRepository<Quest,Long> { | ||
@Query("SELECT q FROM Quest q WHERE q.userId = :userId AND q.createdAt = :createdAt") | ||
Optional<Quest> findQuestByUserIdAndCompletionDate(@Param("userId") Long userId, @Param("createdAt") LocalDate createdAt); | ||
|
||
Optional<Quest> findByUserId(Long userId); | ||
/*@Query("SELECT q FROM Quest q WHERE q.userId = :userId AND DATE(q.createdAt) = CURRENT_DATE") | ||
Optional<Quest> findQuestByUserIdAndToday(@Param("userId") Long userId);*/ | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface QuestRepository extends JpaRepository<Quest, Long> { | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/ku/user/domain/quest/dao/UserQuestRepository.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,19 @@ | ||
package ku.user.domain.quest.dao; | ||
|
||
import feign.Param; | ||
import ku.user.domain.quest.domain.UserQuest; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
|
||
public interface UserQuestRepository extends JpaRepository<UserQuest,Long> { | ||
@Query("SELECT q FROM UserQuest q WHERE q.userId = :userId AND q.createdAt = :createdAt") | ||
Optional<UserQuest> findQuestByUserIdAndCompletionDate(@Param("userId") Long userId, @Param("createdAt") LocalDate createdAt); | ||
|
||
Optional<UserQuest> findByUserId(Long userId); | ||
/*@Query("SELECT q FROM Quest q WHERE q.userId = :userId AND DATE(q.createdAt) = CURRENT_DATE") | ||
Optional<Quest> findQuestByUserIdAndToday(@Param("userId") Long userId);*/ | ||
|
||
} |
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,55 +1,20 @@ | ||
package ku.user.domain.quest.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.springframework.data.relational.core.sql.In; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.Getter; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder | ||
@Getter | ||
@Table(name = "quests") | ||
@Getter | ||
public class Quest { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private Long userId; | ||
|
||
private Integer quest1; | ||
private LocalDateTime quest1CompletedAt; | ||
|
||
private Integer quest2; | ||
private LocalDateTime quest2CompletedAt; | ||
|
||
private Integer quest3; | ||
private LocalDateTime quest3CompletedAt; | ||
|
||
private LocalDate createdAt; | ||
|
||
public static Quest from(Long userId, List<Integer> randomQuestNumber) { | ||
return Quest.builder() | ||
.userId(userId) | ||
.quest1(randomQuestNumber.get(0)) | ||
.quest2(randomQuestNumber.get(1)) | ||
.quest3(randomQuestNumber.get(2)) | ||
.createdAt(LocalDate.now()) | ||
.build(); | ||
} | ||
private Long id; //id | ||
private String Title; //제목 | ||
private String description; //내용 | ||
private int clearCondition; //성공조건 | ||
private int reward; //보상 | ||
|
||
public void solve(Integer questIndex) { | ||
if (quest1.equals(questIndex)) | ||
quest1CompletedAt = LocalDateTime.now(); | ||
if (quest2.equals(questIndex)) | ||
quest2CompletedAt = LocalDateTime.now(); | ||
if (quest3.equals(questIndex)) | ||
quest3CompletedAt = LocalDateTime.now(); | ||
} | ||
} |
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,70 @@ | ||
package ku.user.domain.quest.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder | ||
@Getter | ||
@Table(name = "users_quests") | ||
public class UserQuest { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private Long userId; | ||
|
||
private Long quest1; | ||
@Builder.Default | ||
private int quest1Progress = 0; | ||
private LocalDateTime quest1CompletedAt; | ||
|
||
|
||
private Long quest2; | ||
@Builder.Default | ||
private int quest2Progress = 0; | ||
private LocalDateTime quest2CompletedAt; | ||
|
||
private Long quest3; | ||
@Builder.Default | ||
private int quest3Progress = 0; | ||
private LocalDateTime quest3CompletedAt; | ||
|
||
private LocalDate createdAt; | ||
|
||
public static UserQuest from(Long userId, List<Long> randomQuestNumber) { | ||
return UserQuest.builder() | ||
.userId(userId) | ||
.quest1(randomQuestNumber.get(0)) | ||
.quest2(randomQuestNumber.get(1)) | ||
.quest3(randomQuestNumber.get(2)) | ||
.createdAt(LocalDate.now()) | ||
.build(); | ||
} | ||
|
||
public void solve(Long questIndex) { | ||
if (quest1.equals(questIndex)) | ||
quest1CompletedAt = LocalDateTime.now(); | ||
if (quest2.equals(questIndex)) | ||
quest2CompletedAt = LocalDateTime.now(); | ||
if (quest3.equals(questIndex)) | ||
quest3CompletedAt = LocalDateTime.now(); | ||
} | ||
|
||
public void updateQuest1(int quest1Progress){ | ||
this.quest1Progress = quest1Progress; | ||
} | ||
public void updateQuest2(int quest2Progress){ | ||
this.quest2Progress = quest2Progress; | ||
} | ||
public void updateQuest3(int quest3Progress){ | ||
this.quest3Progress = quest3Progress; | ||
} | ||
} |
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
20 changes: 12 additions & 8 deletions
20
src/main/java/ku/user/domain/quest/dto/response/GetUserQuestsResponse.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,27 +1,31 @@ | ||
package ku.user.domain.quest.dto.response; | ||
|
||
import ku.user.domain.quest.domain.Quest; | ||
import lombok.AllArgsConstructor; | ||
import ku.user.domain.quest.domain.UserQuest; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
|
||
@Builder | ||
public record GetUserQuestsResponse (int firstQuestIndex, | ||
int secondQuestIndex, | ||
int thirdQuestIndex, | ||
public record GetUserQuestsResponse (Long firstQuestIndex, | ||
Long secondQuestIndex, | ||
Long thirdQuestIndex, | ||
Boolean firstQuestClear, | ||
Boolean secondQuestClear, | ||
Boolean thirdQuestClear){ | ||
Boolean thirdQuestClear, | ||
int firstQuestProgress, | ||
int secondQuestProgress, | ||
int thirdQuestProgress){ | ||
|
||
public static GetUserQuestsResponse toDto(Quest quest){ | ||
public static GetUserQuestsResponse toDto(UserQuest quest){ | ||
return GetUserQuestsResponse.builder() | ||
.firstQuestIndex(quest.getQuest1()) | ||
.secondQuestIndex(quest.getQuest2()) | ||
.thirdQuestIndex(quest.getQuest3()) | ||
.firstQuestClear(quest.getQuest1CompletedAt() != null) | ||
.secondQuestClear(quest.getQuest2CompletedAt() != null) | ||
.thirdQuestClear(quest.getQuest3CompletedAt() != null) | ||
.firstQuestProgress(quest.getQuest1Progress()) | ||
.secondQuestProgress(quest.getQuest2Progress()) | ||
.secondQuestProgress(quest.getQuest3Progress()) | ||
.build(); | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
src/main/java/ku/user/domain/quest/dto/response/PostUserQuestResponse.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
Oops, something went wrong.