-
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.
Browse files
Browse the repository at this point in the history
Issue/#14
- Loading branch information
Showing
11 changed files
with
241 additions
and
5 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
65 changes: 65 additions & 0 deletions
65
zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/admin/AdminReq.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,65 @@ | ||
package org.haedal.zzansuni.controller.admin; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import org.haedal.zzansuni.domain.challengegroup.ChallengeCategory; | ||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupCommand; | ||
import org.haedal.zzansuni.domain.challengegroup.DayType; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public class AdminReq { | ||
public record CreateChallengeGroupRequest( | ||
@NotBlank(message = "title은 필수값입니다.") | ||
String title, | ||
@NotBlank(message = "content는 필수값입니다.") | ||
String content, | ||
@NotBlank(message = "guide는 필수값입니다.") | ||
String guide, | ||
@NotNull(message = "category는 필수값입니다.") | ||
ChallengeCategory category, | ||
@NotNull(message = "challenges는 필수값입니다.") | ||
List<CreateChallengeRequest> challenges | ||
){ | ||
public ChallengeGroupCommand.Create toCommand() { | ||
return ChallengeGroupCommand.Create.builder() | ||
.title(title) | ||
.content(content) | ||
.guide(guide) | ||
.category(category) | ||
.createChallenges(challenges.stream().map(CreateChallengeRequest::toCommand).toList()) | ||
.build(); | ||
} | ||
} | ||
|
||
public record CreateChallengeRequest( | ||
@NotNull(message = "startDate는 필수값입니다.") | ||
LocalDate startDate, | ||
@NotNull(message = "endDate는 필수값입니다.") | ||
LocalDate endDate, | ||
@NotNull(message = "dayType은 필수값입니다.") | ||
DayType dayType, | ||
@NotNull(message = "requiredCount는 필수값입니다.") | ||
Integer requiredCount, | ||
@NotNull(message = "onceExp는 필수값입니다.") | ||
Integer onceExp, | ||
@NotNull(message = "successExp는 필수값입니다.") | ||
Integer successExp, | ||
@NotNull(message = "difficulty는 필수값입니다.") | ||
Integer difficulty | ||
){ | ||
public ChallengeGroupCommand.CreateChallenge toCommand() { | ||
return ChallengeGroupCommand.CreateChallenge.builder() | ||
.startDate(startDate) | ||
.endDate(endDate) | ||
.dayType(dayType) | ||
.requiredCount(requiredCount) | ||
.onceExp(onceExp) | ||
.successExp(successExp) | ||
.difficulty(difficulty) | ||
.build(); | ||
} | ||
} | ||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
...er/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupCommand.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,46 @@ | ||
package org.haedal.zzansuni.domain.challengegroup; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public class ChallengeGroupCommand { | ||
@Builder | ||
@Getter | ||
public static class Create { | ||
@NotBlank(message = "title은 필수값입니다.") | ||
private final String title; | ||
@NotBlank(message = "content는 필수값입니다.") | ||
private final String content; | ||
@NotBlank(message = "guide는 필수값입니다.") | ||
private final String guide; | ||
@NotNull(message = "category는 필수값입니다.") | ||
private final ChallengeCategory category; | ||
@NotNull(message = "challenges는 필수값입니다.") | ||
private final List<CreateChallenge> createChallenges; | ||
|
||
} | ||
|
||
@Builder | ||
@Getter | ||
public static class CreateChallenge { | ||
@NotNull(message = "startDate는 필수값입니다.") | ||
private final LocalDate startDate; | ||
@NotNull(message = "endDate는 필수값입니다.") | ||
private final LocalDate endDate; | ||
@NotNull(message = "dayType은 필수값입니다.") | ||
private final DayType dayType; | ||
@NotNull(message = "requiredCount는 필수값입니다.") | ||
private final Integer requiredCount; | ||
@NotNull(message = "onceExp는 필수값입니다.") | ||
private final Integer onceExp; | ||
@NotNull(message = "successExp는 필수값입니다.") | ||
private final Integer successExp; | ||
@NotNull(message = "difficulty는 필수값입니다.") | ||
private final Integer difficulty; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ver/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupReader.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; | ||
|
||
public interface ChallengeGroupReader { | ||
ChallengeGroup getById(Long challengeGroupId); | ||
} |
24 changes: 24 additions & 0 deletions
24
...er/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupService.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,24 @@ | ||
package org.haedal.zzansuni.domain.challengegroup; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChallengeGroupService { | ||
private final ChallengeGroupStore challengeGroupStore; | ||
private final ChallengeGroupReader challengeGroupReader; | ||
|
||
@Transactional | ||
public void createChallengeGroup(ChallengeGroupCommand.Create command) { | ||
ChallengeGroup challengeGroup = ChallengeGroup.create(command); | ||
challengeGroupStore.save(challengeGroup); | ||
} | ||
|
||
@Transactional | ||
public void deleteChallengeGroup(Long challengeGroupId) { | ||
ChallengeGroup challengeGroup = challengeGroupReader.getById(challengeGroupId); | ||
challengeGroupStore.delete(challengeGroup.getId()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...rver/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupStore.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; | ||
|
||
public interface ChallengeGroupStore { | ||
ChallengeGroup save(ChallengeGroup challengeGroup); | ||
void delete(Long challengeGroupId); | ||
} |
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: 20 additions & 0 deletions
20
...main/java/org/haedal/zzansuni/infrastructure/challengegroup/ChallengeGroupReaderImpl.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,20 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; | ||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupReader; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChallengeGroupReaderImpl implements ChallengeGroupReader { | ||
private final ChallengeGroupRepository challengeGroupRepository; | ||
@Override | ||
public ChallengeGroup getById(Long challengeGroupId) { | ||
return challengeGroupRepository | ||
.findById(challengeGroupId) | ||
.orElseThrow(NoSuchElementException::new); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...main/java/org/haedal/zzansuni/infrastructure/challengegroup/ChallengeGroupRepository.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.infrastructure.challengegroup; | ||
|
||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ChallengeGroupRepository extends JpaRepository<ChallengeGroup, Long> { | ||
} |
21 changes: 21 additions & 0 deletions
21
.../main/java/org/haedal/zzansuni/infrastructure/challengegroup/ChallengeGroupStoreImpl.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,21 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup; | ||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupStore; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChallengeGroupStoreImpl implements ChallengeGroupStore { | ||
private final ChallengeGroupRepository challengeGroupRepository; | ||
@Override | ||
public ChallengeGroup save(ChallengeGroup challengeGroup) { | ||
return challengeGroupRepository.save(challengeGroup); | ||
} | ||
|
||
@Override | ||
public void delete(Long challengeGroupId) { | ||
challengeGroupRepository.deleteById(challengeGroupId); | ||
} | ||
} |