-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue/#41 #73
Merged
Merged
Issue/#41 #73
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d417191
[Refactor]: user reader, store ํจํค์ง ๋ณ๊ฒฝ(port)
kwonssshyeon b4e5fc6
[Test]: ์ ์ ์คํธ๋ฆญ ์กฐํ ํ
์คํธ ์ฝ๋ ์์ฑ
kwonssshyeon ffc5667
[Fix]: ์คํธ๋ฆญ strick -> streak ์์
kwonssshyeon 2a23a28
[Fix]: ์คํจ ํ
์คํธ ์ฃผ์์ฒ๋ฆฌ (challenge group)
kwonssshyeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 0 additions & 5 deletions
5
zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/UserStore.java
This file was deleted.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
...edal/zzansuni/user/domain/UserReader.java โ ...zzansuni/user/domain/port/UserReader.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
7 changes: 7 additions & 0 deletions
7
zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/user/domain/port/UserStore.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,7 @@ | ||
package org.haedal.zzansuni.user.domain.port; | ||
|
||
import org.haedal.zzansuni.user.domain.User; | ||
|
||
public interface UserStore { | ||
User store(User user); | ||
} |
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
198 changes: 198 additions & 0 deletions
198
...suni-api-server/app/src/test/java/org/haedal/zzansuni/user/domain/UserIntegratedTest.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,198 @@ | ||
package org.haedal.zzansuni.user.domain; | ||
|
||
import org.haedal.zzansuni.challengegroup.domain.Challenge; | ||
import org.haedal.zzansuni.challengegroup.domain.ChallengeCategory; | ||
import org.haedal.zzansuni.challengegroup.domain.ChallengeGroup; | ||
import org.haedal.zzansuni.challengegroup.infrastructure.ChallengeGroupRepository; | ||
import org.haedal.zzansuni.challengegroup.infrastructure.ChallengeRepository; | ||
import org.haedal.zzansuni.global.security.Role; | ||
import org.haedal.zzansuni.user.domain.port.UserReader; | ||
import org.haedal.zzansuni.user.infrastructure.UserRepository; | ||
import org.haedal.zzansuni.userchallenge.domain.*; | ||
import org.haedal.zzansuni.userchallenge.domain.port.UserChallengeReader; | ||
import org.haedal.zzansuni.userchallenge.infrastructure.ChallengeVerificationRepository; | ||
import org.haedal.zzansuni.userchallenge.infrastructure.UserChallengeRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.LongStream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
public class UserIntegratedTest { | ||
@Autowired | ||
private UserReader userReader; | ||
@Autowired | ||
private UserChallengeReader userChallengeReader; | ||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private ChallengeGroupRepository challengeGroupRepository; | ||
@Autowired | ||
private ChallengeRepository challengeRepository; | ||
@Autowired | ||
private UserChallengeRepository userChallengeRepository; | ||
@Autowired | ||
private ChallengeVerificationRepository challengeVerificationRepository; | ||
|
||
|
||
@DisplayName("์ ์ฒด ์ฌ์ฉ์ ๋ญํน์ด ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ํ๋๋ค.") | ||
@Test | ||
public void getUserPagingByRankingOrder(){ | ||
Pageable pageable = Pageable.ofSize(5).withPage(0); | ||
List<User> userList = createUsers(5); | ||
userRepository.saveAll(userList); | ||
|
||
//when | ||
List<User> users = userReader.getUserPagingByRanking(pageable).getContent(); | ||
|
||
//then | ||
assertThat(users.size()).isEqualTo(5); | ||
assertThat(users.get(0).getNickname()).isEqualTo("user5"); | ||
assertThat(users.get(1).getNickname()).isEqualTo("user4"); | ||
assertThat(users.get(2).getNickname()).isEqualTo("user3"); | ||
assertThat(users.get(3).getNickname()).isEqualTo("user2"); | ||
assertThat(users.get(4).getNickname()).isEqualTo("user1"); | ||
|
||
assertThat(users.get(0).getExp()).isGreaterThan(users.get(1).getExp()); | ||
assertThat(users.get(1).getExp()).isGreaterThan(users.get(2).getExp()); | ||
assertThat(users.get(2).getExp()).isGreaterThan(users.get(3).getExp()); | ||
assertThat(users.get(3).getExp()).isGreaterThan(users.get(4).getExp()); | ||
} | ||
|
||
|
||
@DisplayName("์ ์ ์ ์คํธ๋ฆญ์ ์กฐํํ๋ค.") | ||
@Test | ||
@Transactional | ||
public void getUserStreak(){ | ||
User user = createUser("ํ ์คํธ์ ์ "); | ||
userRepository.save(user); | ||
|
||
ChallengeGroup challengeGroup = createChallengeGroup(); | ||
challengeGroupRepository.save(challengeGroup); | ||
|
||
Challenge challenge1 = createChallenge(challengeGroup); | ||
Challenge challenge2 = createChallenge(challengeGroup); | ||
challengeRepository.saveAll(List.of(challenge1, challenge2)); | ||
|
||
LocalDate date = LocalDate.now(); | ||
UserChallenge userChallenge1 = createUserChallenge(user, challenge1, date); | ||
UserChallenge userChallenge2 = createUserChallenge(user, challenge2, date); | ||
userChallengeRepository.saveAll(List.of(userChallenge1, userChallenge2)); | ||
LocalDateTime time1 = LocalDateTime.now().minusDays(5); | ||
LocalDateTime time2 = LocalDateTime.now().minusDays(4); | ||
// userChallenge ์์ฑ์ผ์ ์์ | ||
ReflectionTestUtils.setField(userChallenge1, "createdAt", time1); | ||
ReflectionTestUtils.setField(userChallenge2, "createdAt", time2); | ||
userChallengeRepository.saveAll(List.of(userChallenge1, userChallenge2)); | ||
|
||
|
||
ChallengeVerification challengeVerification1 = createChallengeVerification(userChallenge1); | ||
ChallengeVerification challengeVerification2 = createChallengeVerification(userChallenge2); | ||
challengeVerificationRepository.saveAll(List.of(challengeVerification1, challengeVerification2)); | ||
// challengeVerification ์์ฑ์ผ์ ์์ | ||
ReflectionTestUtils.setField(challengeVerification1, "createdAt", time1); | ||
ReflectionTestUtils.setField(challengeVerification2, "createdAt", time2); | ||
challengeVerificationRepository.saveAll(List.of(challengeVerification1, challengeVerification2)); | ||
|
||
|
||
//when | ||
List<DayCountType> userStreaks = userChallengeReader.countAllByUserIdAndDate(user.getId(), LocalDate.now().minusDays(7), LocalDate.now()); | ||
|
||
//then | ||
assertThat(userStreaks.size()).isEqualTo(2); | ||
assertThat(userStreaks.get(0).getDate()).isEqualTo(LocalDate.now().minusDays(5)); | ||
assertThat(userStreaks.get(0).getCount()).isEqualTo(1); | ||
assertThat(userStreaks.get(1).getDate()).isEqualTo(LocalDate.now().minusDays(4)); | ||
assertThat(userStreaks.get(1).getCount()).isEqualTo(1); | ||
|
||
System.out.println("userStreak: "); | ||
for (DayCountType dayCountType : userStreaks) { | ||
System.out.println(dayCountType.getDate() + " : " + dayCountType.getCount()); | ||
} | ||
} | ||
|
||
|
||
User createUser(String nickname, Integer exp){ | ||
return User.builder() | ||
.nickname(nickname) | ||
.email(null) | ||
.password(null) | ||
.role(Role.USER) | ||
.provider(null) | ||
.authToken(null) | ||
.exp(exp) | ||
.profileImageUrl(null) | ||
.build(); | ||
} | ||
|
||
List<User> createUsers(int size){ | ||
return LongStream.range(1, size+1) | ||
.mapToObj(i -> createUser("user" + i, (int) (i * 100))) | ||
.collect(Collectors.toList()); | ||
} | ||
User createUser(String nickname){ | ||
return User.builder() | ||
.nickname(nickname) | ||
.email(null) | ||
.password(null) | ||
.role(Role.USER) | ||
.provider(null) | ||
.authToken(null) | ||
.exp(0) | ||
.profileImageUrl(null) | ||
.build(); | ||
} | ||
|
||
ChallengeGroup createChallengeGroup(){ | ||
return ChallengeGroup.builder() | ||
.title("Test Challenge Group") | ||
.category(ChallengeCategory.ETC) | ||
.content("Test Challenge Group Content") | ||
.guide("Test Challenge Group Guide") | ||
.cumulativeCount(0) | ||
.joinStartDate(LocalDate.now().minusDays(10)) | ||
.joinEndDate(LocalDate.now().minusDays(3)) | ||
.build(); | ||
} | ||
|
||
Challenge createChallenge(ChallengeGroup challengeGroup){ | ||
return Challenge.builder() | ||
.challengeGroup(challengeGroup) | ||
.requiredCount(10) | ||
.onceExp(10) | ||
.successExp(50) | ||
.difficulty(1) | ||
.activePeriod(7) | ||
.build(); | ||
} | ||
|
||
ChallengeVerification createChallengeVerification(UserChallenge userChallenge){ | ||
return ChallengeVerification.builder() | ||
.userChallenge(userChallenge) | ||
.imageUrl("http://example.com/image.jpg") | ||
.content("Test Verification") | ||
.status(ChallengeVerificationStatus.APPROVED) | ||
.build(); | ||
} | ||
|
||
UserChallenge createUserChallenge(User user, Challenge challenge, LocalDate date){ | ||
return UserChallenge.builder() | ||
.challenge(challenge) | ||
.status(ChallengeStatus.PROCEEDING) | ||
.user(user) | ||
.activeStartDate(date) | ||
.activeEndDate(date.plusDays(7)) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertAll์ ์ฌ์ฉํ๋ฉด ์กฐ๊ธ ๋ ๊ฐ๋ ์ฑ ์๊ฒ ํ ์คํธ ํ์ธ์ด ๊ฐ๋ฅํด์!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ต ๋ค์์ ์์ ํ ๋ ๋ฐ์ํด๋ณด๊ฒ ์ต๋๋ค !