-
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.
π :: Api-v0.1.0
- Loading branch information
Showing
171 changed files
with
2,511 additions
and
553 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
16 changes: 16 additions & 0 deletions
16
DuDoong-Api/src/main/java/band/gosrock/api/common/aop/hostRole/FindHostFrom.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,16 @@ | ||
package band.gosrock.api.common.aop.hostRole; | ||
|
||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum FindHostFrom { | ||
HOST_ID("hostId"), | ||
EVENT_ID("eventId"); | ||
|
||
private final String identifier; | ||
|
||
FindHostFrom(String identifier) { | ||
this.identifier = identifier; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ng-Api/src/main/java/band/gosrock/api/common/aop/hostRole/HostCallTransactionFactory.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 band.gosrock.api.common.aop.hostRole; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class HostCallTransactionFactory { | ||
|
||
private final HostRoleEventTransaction hostRoleEventTransaction; | ||
private final HostRoleHostTransaction hostRoleHostTransaction; | ||
|
||
public HostRoleCallTransaction getCallTransaction(FindHostFrom findHostFrom) { | ||
if (findHostFrom == FindHostFrom.HOST_ID) { | ||
return hostRoleHostTransaction; | ||
} | ||
return hostRoleEventTransaction; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
DuDoong-Api/src/main/java/band/gosrock/api/common/aop/hostRole/HostQualification.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 band.gosrock.api.common.aop.hostRole; | ||
|
||
|
||
import band.gosrock.domain.domains.host.domain.Host; | ||
import java.util.function.BiConsumer; | ||
|
||
/** κ° κΆνμ λ§μΆ°μ host λλ©μΈμ κ²μ¦λ©μλλ₯Ό μ€νμν΅λλ€. κ²μ¦ λ©μλμ΄λ―λ‘ biConsumer λ₯Ό ν΅ν΄ μ€ν μν¬ ν¨μλ₯Ό 미리 μμ±ν΄ λ‘λλ€. -μ΄μ°¬μ§ */ | ||
public enum HostQualification { | ||
MASTER((userId, host) -> host.validateMasterHostUser(userId)), | ||
MANAGER((userId, host) -> host.validateManagerHostUser(userId)), | ||
GUEST((userId, host) -> host.validateActiveHostUser(userId)); | ||
private final BiConsumer<Long, Host> consumer; | ||
|
||
HostQualification(BiConsumer<Long, Host> consumer) { | ||
this.consumer = consumer; | ||
} | ||
|
||
/** | ||
* νΈμ€νΈμ κ²μ¦μ μννλ λ©μλ | ||
* | ||
* @param userId | ||
* @param host | ||
*/ | ||
public void validQualification(Long userId, Host host) { | ||
consumer.accept(userId, host); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
DuDoong-Api/src/main/java/band/gosrock/api/common/aop/hostRole/HostRoleAop.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,60 @@ | ||
package band.gosrock.api.common.aop.hostRole; | ||
|
||
|
||
import java.lang.reflect.Method; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* νΈμ€νΈ κ΄λ¦¬μ μΈκ°λ₯Ό μν aop μ λλ€ λ©μλ λ 벨μμ μλνλ©° κΆν μ 보λ₯Ό μ΄λ Έν μ΄μ μΌλ‘ λ°κ³ eventIdλ₯Ό μΈμμμ μ°Ύμμ νΈμ€νΈ μ 보λ₯Ό λΆλ¬μ¨λ€ κΆν κ²μ¦μ ν©λλ€. | ||
*/ | ||
@Aspect | ||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@ConditionalOnExpression("${ableHostRoleAop:true}") | ||
public class HostRoleAop { | ||
private final HostCallTransactionFactory hostCallTransactionFactory; | ||
|
||
/** | ||
* master νΈμ€νΈμ λ§μ€ν° manager νΈμ€νΈμ μμ ,μ‘°ν ( νΈμ€νΈμ μ λλ©μΈμ μνΌ νΈμ€νΈ ) guest νΈμ€νΈμ μ‘°νκΆν (νΈμ€νΈμ μ λλ©μΈμ νΈμ€νΈ ) | ||
* | ||
* @see band.gosrock.domain.domains.host.domain.HostRole | ||
*/ | ||
@Around("@annotation(band.gosrock.api.common.aop.hostRole.HostRolesAllowed)") | ||
public Object aop(final ProceedingJoinPoint joinPoint) throws Throwable { | ||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
Method method = signature.getMethod(); | ||
HostRolesAllowed annotation = method.getAnnotation(HostRolesAllowed.class); | ||
HostQualification hostQualification = annotation.role(); | ||
// μ 곡λ νΈμ€νΈμ role μ΄ μ μλ μΈκ°μ λ‘€κ³Ό κ°μμ§ νμΈνλ€. | ||
// μμΌλ©΄ IllegalArgumentException λ°μ | ||
FindHostFrom findHostFrom = annotation.findHostFrom(); | ||
String identifier = findHostFrom.getIdentifier(); | ||
|
||
String[] parameterNames = signature.getParameterNames(); | ||
Object[] args = joinPoint.getArgs(); | ||
|
||
Long id = getId(parameterNames, args, identifier); | ||
|
||
return hostCallTransactionFactory | ||
.getCallTransaction(findHostFrom) | ||
.proceed(id, hostQualification, joinPoint); | ||
} | ||
|
||
public Long getId(String[] parameterNames, Object[] args, String paramName) { | ||
for (int i = 0; i < parameterNames.length; i++) { | ||
if (parameterNames[i].equals(paramName)) { | ||
// λ‘±νμ μ΄λΌ κ°μ . μλλ©΄ classCastException ν°νΈλ¦Ό | ||
return (Long) args[i]; | ||
} | ||
} | ||
throw new IllegalArgumentException(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
DuDoong-Api/src/main/java/band/gosrock/api/common/aop/hostRole/HostRoleCallTransaction.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,9 @@ | ||
package band.gosrock.api.common.aop.hostRole; | ||
|
||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
|
||
public interface HostRoleCallTransaction { | ||
Object proceed(Long id, HostQualification role, final ProceedingJoinPoint joinPoint) | ||
throws Throwable; | ||
} |
34 changes: 34 additions & 0 deletions
34
DuDoong-Api/src/main/java/band/gosrock/api/common/aop/hostRole/HostRoleEventTransaction.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,34 @@ | ||
package band.gosrock.api.common.aop.hostRole; | ||
|
||
|
||
import band.gosrock.api.common.UserUtils; | ||
import band.gosrock.domain.domains.event.adaptor.EventAdaptor; | ||
import band.gosrock.domain.domains.event.domain.Event; | ||
import band.gosrock.domain.domains.host.adaptor.HostAdaptor; | ||
import band.gosrock.domain.domains.host.domain.Host; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** νΈμ€νΈ μ 보λ₯Ό νΈλμμ μμμ μ‘°ννκΈ° μν΄μ λ§λ ν΄λμ€μ λλ€. νΈλμμ λ΄μμ μΊμ ν μ μμΌλ©΄ μ’μΌλ μ΄λ κ² λ§λ€μμ΅λλ€. - μ΄μ°¬μ§ */ | ||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class HostRoleEventTransaction implements HostRoleCallTransaction { | ||
|
||
private final UserUtils userUtils; | ||
private final EventAdaptor eventAdaptor; | ||
private final HostAdaptor hostAdaptor; | ||
|
||
@Transactional(readOnly = true) | ||
public Object proceed(Long eventId, HostQualification role, final ProceedingJoinPoint joinPoint) | ||
throws Throwable { | ||
Long currentUserId = userUtils.getCurrentUserId(); | ||
Event event = eventAdaptor.findById(eventId); | ||
Host host = hostAdaptor.findById(event.getHostId()); | ||
role.validQualification(currentUserId, host); | ||
return joinPoint.proceed(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
DuDoong-Api/src/main/java/band/gosrock/api/common/aop/hostRole/HostRoleHostTransaction.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 band.gosrock.api.common.aop.hostRole; | ||
|
||
|
||
import band.gosrock.api.common.UserUtils; | ||
import band.gosrock.domain.domains.host.adaptor.HostAdaptor; | ||
import band.gosrock.domain.domains.host.domain.Host; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** νΈμ€νΈ μ 보λ₯Ό νΈλμμ μμμ μ‘°ννκΈ° μν΄μ λ§λ ν΄λμ€μ λλ€. νΈλμμ λ΄μμ μΊμ ν μ μμΌλ©΄ μ’μΌλ μ΄λ κ² λ§λ€μμ΅λλ€. - μ΄μ°¬μ§ */ | ||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class HostRoleHostTransaction implements HostRoleCallTransaction { | ||
|
||
private final UserUtils userUtils; | ||
private final HostAdaptor hostAdaptor; | ||
|
||
@Transactional(readOnly = true) | ||
public Object proceed(Long hostId, HostQualification role, final ProceedingJoinPoint joinPoint) | ||
throws Throwable { | ||
Long currentUserId = userUtils.getCurrentUserId(); | ||
Host host = hostAdaptor.findById(hostId); | ||
role.validQualification(currentUserId, host); | ||
return joinPoint.proceed(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
DuDoong-Api/src/main/java/band/gosrock/api/common/aop/hostRole/HostRolesAllowed.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 band.gosrock.api.common.aop.hostRole; | ||
|
||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** HostRoles aop λ₯Ό μ μ©νκΈ° μν΄ λ€λ μ΄λ Έν μ΄μ - μ΄μ°¬μ§ */ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface HostRolesAllowed { | ||
/** | ||
* μΈκ°μ§ κ°μ κ°μ§ "MASTER","MANAGER","GUEST" κΆν μ 보λ | ||
* | ||
* @see HostRoleAop | ||
*/ | ||
HostQualification role(); | ||
|
||
FindHostFrom findHostFrom(); | ||
} |
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.