-
Notifications
You must be signed in to change notification settings - Fork 6
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 #269 from kssumin/main
[BE/FEAT] 팀빌딩 상태를 검증한다.
- Loading branch information
Showing
14 changed files
with
271 additions
and
8 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...java/com/blackcompany/eeos/teamBuilding/application/dto/ValidateTeamBuildingResponse.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,15 @@ | ||
package com.blackcompany.eeos.teamBuilding.application.dto; | ||
|
||
import com.blackcompany.eeos.common.support.dto.AbstractResponseDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder(toBuilder = true) | ||
public class ValidateTeamBuildingResponse implements AbstractResponseDto { | ||
private String status; | ||
} |
11 changes: 11 additions & 0 deletions
11
...ny/eeos/teamBuilding/application/dto/converter/ValidateTeamBuildingResponseConverter.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,11 @@ | ||
package com.blackcompany.eeos.teamBuilding.application.dto.converter; | ||
|
||
import com.blackcompany.eeos.teamBuilding.application.dto.ValidateTeamBuildingResponse; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ValidateTeamBuildingResponseConverter { | ||
public ValidateTeamBuildingResponse from(String status) { | ||
return ValidateTeamBuildingResponse.builder().status(status).build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...eos/src/main/java/com/blackcompany/eeos/teamBuilding/application/model/Accessibility.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 com.blackcompany.eeos.teamBuilding.application.model; | ||
|
||
public enum Accessibility { | ||
CREATABLE("creatable"), | ||
NONCREATABLE("noncreatable"), | ||
JOINABLE("joinable"), | ||
NONJOINABLE("nonjoinable"); | ||
|
||
private final String status; | ||
|
||
Accessibility(String status) { | ||
this.status = status; | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...main/java/com/blackcompany/eeos/teamBuilding/application/model/AccessibilityStandard.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,32 @@ | ||
package com.blackcompany.eeos.teamBuilding.application.model; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public enum AccessibilityStandard { | ||
CREATABILITY("creatability", List.of(Accessibility.CREATABLE, Accessibility.NONCREATABLE)), | ||
JOINABILITY("joinability", List.of(Accessibility.JOINABLE, Accessibility.NONJOINABLE)); | ||
|
||
private final String standard; | ||
private final List<Accessibility> accessibilities; | ||
|
||
AccessibilityStandard(String standard, List<Accessibility> accessibilities) { | ||
this.standard = standard; | ||
this.accessibilities = accessibilities; | ||
} | ||
|
||
public String getStandard() { | ||
return standard; | ||
} | ||
|
||
public List<Accessibility> getAccessibilities() { | ||
return accessibilities; | ||
} | ||
|
||
public static AccessibilityStandard find(String source) { | ||
return Arrays.stream(AccessibilityStandard.values()) | ||
.filter(standard -> standard.getStandard().equals(source)) | ||
.findAny() | ||
.orElse(AccessibilityStandard.CREATABILITY); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...java/com/blackcompany/eeos/teamBuilding/application/service/CreatableValidateService.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,27 @@ | ||
package com.blackcompany.eeos.teamBuilding.application.service; | ||
|
||
import com.blackcompany.eeos.teamBuilding.application.model.Accessibility; | ||
import com.blackcompany.eeos.teamBuilding.application.model.AccessibilityStandard; | ||
import com.blackcompany.eeos.teamBuilding.application.model.RestrictTeamBuildingModel; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class CreatableValidateService implements ValidateService { | ||
private final QueryRestrictTeamBuildingService queryRestrictTeamBuildingService; | ||
|
||
@Override | ||
public AccessibilityStandard support() { | ||
return AccessibilityStandard.CREATABILITY; | ||
} | ||
|
||
@Override | ||
public Accessibility getAccessibility(Long memberId) { | ||
RestrictTeamBuildingModel model = queryRestrictTeamBuildingService.getRestrict(); | ||
|
||
return model.getCreatableAccessibility(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../java/com/blackcompany/eeos/teamBuilding/application/service/JoinableValidateService.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,35 @@ | ||
package com.blackcompany.eeos.teamBuilding.application.service; | ||
|
||
import com.blackcompany.eeos.target.application.exception.NotFoundTargetTeamBuildingException; | ||
import com.blackcompany.eeos.target.application.service.QueryTeamBuildingTargetService; | ||
import com.blackcompany.eeos.teamBuilding.application.model.Accessibility; | ||
import com.blackcompany.eeos.teamBuilding.application.model.AccessibilityStandard; | ||
import com.blackcompany.eeos.teamBuilding.persistence.TeamBuildingEntity; | ||
import com.blackcompany.eeos.teamBuilding.persistence.TeamBuildingStatus; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class JoinableValidateService implements ValidateService { | ||
private final QueryTeamBuildingService queryTeamBuildingService; | ||
private final QueryTeamBuildingTargetService queryTeamBuildingTargetService; | ||
|
||
@Override | ||
public AccessibilityStandard support() { | ||
return AccessibilityStandard.JOINABILITY; | ||
} | ||
|
||
@Override | ||
public Accessibility getAccessibility(Long memberId) { | ||
TeamBuildingEntity entity = queryTeamBuildingService.getByStatus(TeamBuildingStatus.PROGRESS); | ||
try { | ||
queryTeamBuildingTargetService.getTarget(memberId, entity.getId()); | ||
return Accessibility.JOINABLE; | ||
} catch (NotFoundTargetTeamBuildingException ex) { | ||
return Accessibility.NONCREATABLE; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../blackcompany/eeos/teamBuilding/application/service/QueryRestrictTeamBuildingService.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 com.blackcompany.eeos.teamBuilding.application.service; | ||
|
||
import com.blackcompany.eeos.teamBuilding.application.exception.NotFoundTeamBuildingStatusException; | ||
import com.blackcompany.eeos.teamBuilding.application.model.RestrictTeamBuildingModel; | ||
import com.blackcompany.eeos.teamBuilding.application.model.converter.RestrictTeamBuildingConverter; | ||
import com.blackcompany.eeos.teamBuilding.persistence.RestrictTeamBuildingRepository; | ||
import com.blackcompany.eeos.teamBuilding.persistence.TeamBuildingStatus; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class QueryRestrictTeamBuildingService { | ||
private final RestrictTeamBuildingRepository restrictTeamBuildingRepository; | ||
private final RestrictTeamBuildingConverter restrictTeamBuildingConverter; | ||
|
||
public RestrictTeamBuildingModel getRestrict() { | ||
return restrictTeamBuildingRepository | ||
.findTopByOrderByVersion() | ||
.map(restrictTeamBuildingConverter::from) | ||
.orElseThrow( | ||
() -> new NotFoundTeamBuildingStatusException(TeamBuildingStatus.PROGRESS.getStatus())); | ||
} | ||
} |
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
...src/main/java/com/blackcompany/eeos/teamBuilding/application/service/ValidateService.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 com.blackcompany.eeos.teamBuilding.application.service; | ||
|
||
import com.blackcompany.eeos.teamBuilding.application.model.Accessibility; | ||
import com.blackcompany.eeos.teamBuilding.application.model.AccessibilityStandard; | ||
|
||
public interface ValidateService { | ||
AccessibilityStandard support(); | ||
|
||
Accessibility getAccessibility(Long memberId); | ||
} |
28 changes: 28 additions & 0 deletions
28
...a/com/blackcompany/eeos/teamBuilding/application/service/ValidateTeamBuildingService.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,28 @@ | ||
package com.blackcompany.eeos.teamBuilding.application.service; | ||
|
||
import com.blackcompany.eeos.teamBuilding.application.dto.ValidateTeamBuildingResponse; | ||
import com.blackcompany.eeos.teamBuilding.application.dto.converter.ValidateTeamBuildingResponseConverter; | ||
import com.blackcompany.eeos.teamBuilding.application.model.Accessibility; | ||
import com.blackcompany.eeos.teamBuilding.application.model.AccessibilityStandard; | ||
import com.blackcompany.eeos.teamBuilding.application.support.ValidateTeamBuildingServiceComposite; | ||
import com.blackcompany.eeos.teamBuilding.application.usecase.ValidateTeamBuildingUsecase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ValidateTeamBuildingService implements ValidateTeamBuildingUsecase { | ||
private final ValidateTeamBuildingServiceComposite validateTeamBuildingServiceComposite; | ||
private final ValidateTeamBuildingResponseConverter responseConverter; | ||
|
||
@Override | ||
public ValidateTeamBuildingResponse validate(Long memberId, String status) { | ||
Accessibility accessibility = | ||
validateTeamBuildingServiceComposite.getAccessibility( | ||
AccessibilityStandard.find(status), memberId); | ||
|
||
return responseConverter.from(accessibility.getStatus()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ckcompany/eeos/teamBuilding/application/support/ValidateTeamBuildingServiceComposite.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,31 @@ | ||
package com.blackcompany.eeos.teamBuilding.application.support; | ||
|
||
import com.blackcompany.eeos.teamBuilding.application.model.Accessibility; | ||
import com.blackcompany.eeos.teamBuilding.application.model.AccessibilityStandard; | ||
import com.blackcompany.eeos.teamBuilding.application.service.ValidateService; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ValidateTeamBuildingServiceComposite { | ||
private final Map<AccessibilityStandard, ValidateService> services; | ||
|
||
public ValidateTeamBuildingServiceComposite(Set<ValidateService> validateServices) { | ||
this.services = | ||
validateServices.stream() | ||
.collect(Collectors.toMap(ValidateService::support, Function.identity())); | ||
} | ||
|
||
public Accessibility getAccessibility(AccessibilityStandard standard, Long memberId) { | ||
ValidateService validateService = getValidateService(standard); | ||
|
||
return validateService.getAccessibility(memberId); | ||
} | ||
|
||
private ValidateService getValidateService(AccessibilityStandard standard) { | ||
return services.get(standard); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...a/com/blackcompany/eeos/teamBuilding/application/usecase/ValidateTeamBuildingUsecase.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 com.blackcompany.eeos.teamBuilding.application.usecase; | ||
|
||
import com.blackcompany.eeos.teamBuilding.application.dto.ValidateTeamBuildingResponse; | ||
|
||
public interface ValidateTeamBuildingUsecase { | ||
/** | ||
* 팀빌딩이 요청한 정보가 가능한 상태인지 검증한다. | ||
* | ||
* @param memberId 팀빌딩 작성자 | ||
*/ | ||
ValidateTeamBuildingResponse validate(Long memberId, String status); | ||
} |
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