-
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.
Showing
18 changed files
with
260 additions
and
26 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
10 changes: 10 additions & 0 deletions
10
...pp/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeReader.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,10 @@ | ||
package org.haedal.zzansuni.domain.challengegroup.challenge; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ChallengeReader { | ||
|
||
Challenge getById(Long id); | ||
|
||
Optional<Challenge> findById(Long id); | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...p/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeService.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,17 @@ | ||
package org.haedal.zzansuni.domain.challengegroup.challenge; | ||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.user.UserReader; | ||
import org.haedal.zzansuni.domain.user.UserStore; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class ChallengeService { | ||
|
||
private final ChallengeReader challengeReader; | ||
private final ChallengeStore challengeStore; | ||
|
||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...app/src/main/java/org/haedal/zzansuni/domain/challengegroup/challenge/ChallengeStore.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,5 @@ | ||
package org.haedal.zzansuni.domain.challengegroup.challenge; | ||
|
||
public interface ChallengeStore { | ||
|
||
} |
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
23 changes: 23 additions & 0 deletions
23
...in/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeCommand.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,23 @@ | ||
package org.haedal.zzansuni.domain.challengegroup.userchallenge; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.haedal.zzansuni.core.utils.SelfValidating; | ||
|
||
public class UserChallengeCommand { | ||
|
||
@Getter | ||
@Builder | ||
public static class Participate extends SelfValidating<Participate> { | ||
|
||
private Long challengeId; | ||
private Long userId; | ||
|
||
public Participate(Long challengeId, Long userId) { | ||
this.challengeId = challengeId; | ||
this.userId = userId; | ||
this.validateSelf(); | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ain/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.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,10 @@ | ||
package org.haedal.zzansuni.domain.challengegroup.userchallenge; | ||
|
||
import java.util.Optional; | ||
|
||
public interface UserChallengeReader { | ||
|
||
UserChallenge getById(Long id); | ||
|
||
Optional<UserChallenge> findById(Long id); | ||
} |
30 changes: 30 additions & 0 deletions
30
...in/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.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,30 @@ | ||
package org.haedal.zzansuni.domain.challengegroup.userchallenge; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; | ||
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeReader; | ||
import org.haedal.zzansuni.domain.user.User; | ||
import org.haedal.zzansuni.domain.user.UserReader; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserChallengeService { | ||
|
||
private final UserChallengeStore userChallengeStore; | ||
private final UserChallengeReader userChallengeReader; | ||
private final UserReader userReader; | ||
private final ChallengeReader challengeReader; | ||
|
||
/** | ||
* 챌린지 참여하기 1. 유저와 챌린지 정보를 받아서 UserChallenge 테이블에 데이터 추가 | ||
*/ | ||
public void participateChallenge(Long userId, | ||
UserChallengeCommand.Participate participateInfo) { | ||
User user = userReader.getById(userId); | ||
Challenge challenge = challengeReader.getById(participateInfo.getChallengeId()); | ||
UserChallenge userChallenge = UserChallenge.from(challenge, user); | ||
userChallengeStore.store(userChallenge); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeStore.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,6 @@ | ||
package org.haedal.zzansuni.domain.challengegroup.userchallenge; | ||
|
||
public interface UserChallengeStore { | ||
|
||
UserChallenge store(UserChallenge userChallenge); | ||
} |
12 changes: 12 additions & 0 deletions
12
...api-server/app/src/main/java/org/haedal/zzansuni/exception/ResourceNotFoundException.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,12 @@ | ||
package org.haedal.zzansuni.exception; | ||
|
||
public class ResourceNotFoundException extends RuntimeException { | ||
|
||
public ResourceNotFoundException(String datasource, long id) { | ||
super(datasource + "에서 ID " + id + "를 찾을 수 없습니다."); | ||
} | ||
|
||
public ResourceNotFoundException(String datasource, String id) { | ||
super(datasource + "에서 ID " + id + "를 찾을 수 없습니다."); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeReaderImpl.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,30 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup.challenge; | ||
|
||
import java.util.NoSuchElementException; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; | ||
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; | ||
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeReader; | ||
import org.haedal.zzansuni.exception.ResourceNotFoundException; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChallengeReaderImpl implements ChallengeReader { | ||
|
||
private final ChallengeRepository challengeRepository; | ||
|
||
@Override | ||
public Challenge getById(Long id) { | ||
return findById(id).orElseThrow( | ||
() -> new ResourceNotFoundException("Challenge", id)); | ||
} | ||
|
||
@Override | ||
public Optional<Challenge> findById(Long id) { | ||
return challengeRepository.findById(id); | ||
} | ||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeRepository.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,8 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup.challenge; | ||
|
||
import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ChallengeRepository extends JpaRepository<Challenge, Long> { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
.../java/org/haedal/zzansuni/infrastructure/challengegroup/challenge/ChallengeStoreImpl.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,13 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup.challenge; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeStore; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChallengeStoreImpl implements ChallengeStore { | ||
|
||
private final ChallengeRepository challengeRepository; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
.../haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.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,26 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup.userchallenge; | ||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; | ||
import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeReader; | ||
import org.haedal.zzansuni.exception.ResourceNotFoundException; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UserChallengeReaderImpl implements UserChallengeReader { | ||
|
||
private final UserChallengeRepository userChallengeRepository; | ||
|
||
@Override | ||
public UserChallenge getById(Long id) { | ||
return findById(id).orElseThrow( | ||
() -> new ResourceNotFoundException("UserChallenge", id)); | ||
} | ||
|
||
@Override | ||
public Optional<UserChallenge> findById(Long id) { | ||
return userChallengeRepository.findById(id); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
.../haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.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,8 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup.userchallenge; | ||
|
||
import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserChallengeRepository extends JpaRepository<UserChallenge, Long> { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...g/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeStoreImpl.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,18 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup.userchallenge; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallenge; | ||
import org.haedal.zzansuni.domain.challengegroup.userchallenge.UserChallengeStore; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UserChallengeStoreImpl implements UserChallengeStore { | ||
|
||
private final UserChallengeRepository userChallengeRepository; | ||
|
||
@Override | ||
public UserChallenge store(UserChallenge userChallenge) { | ||
return userChallengeRepository.save(userChallenge); | ||
} | ||
} |