-
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.
Merge pull request #270 from WE-ARE-RACCOONS/develop
Develop
- Loading branch information
Showing
25 changed files
with
180 additions
and
115 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
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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/postgraduate/global/aop/lock/DistributeLockAspect.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,47 @@ | ||
package com.postgraduate.global.aop.lock; | ||
|
||
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.redisson.api.RLock; | ||
import org.redisson.api.RedissonClient; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
@Aspect | ||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class DistributeLockAspect { | ||
private final RedissonClient redissonClient; | ||
private static final String PREFIX = "mentoring"; | ||
|
||
@Around("com.postgraduate.global.aop.lock.DistributeLockPointCut.allMentoringService()") | ||
public Object startDistributeLock(ProceedingJoinPoint joinPoint) throws Throwable { | ||
String lockKey = null; | ||
Object[] args = joinPoint.getArgs(); | ||
for (Object arg : args) { | ||
if (arg instanceof Long) { | ||
lockKey = PREFIX + arg; | ||
} | ||
} | ||
RLock lock = redissonClient.getLock(lockKey); | ||
|
||
try { | ||
boolean available = lock.tryLock(5, 5, SECONDS); | ||
if (!available) | ||
throw new LockException(); | ||
log.info("lock ํ๋ {}", lockKey); | ||
return joinPoint.proceed(); | ||
} catch (Exception e) { | ||
log.error("์์ธ ๋ฐ์ {}", e.getMessage()); | ||
throw e; | ||
} finally { | ||
lock.unlock(); | ||
log.info("lock ๋ฐ๋ฉ {}", lockKey); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/postgraduate/global/aop/lock/DistributeLockPointCut.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.postgraduate.global.aop.lock; | ||
|
||
import org.aspectj.lang.annotation.Pointcut; | ||
|
||
public class DistributeLockPointCut { | ||
@Pointcut("execution(* com.postgraduate.domain.mentoring.application.usecase.MentoringManageUseCase.*(..)) " + | ||
"&& !execution(* com.postgraduate.domain.mentoring.application.usecase.MentoringManageUseCase.sendFinishMessage(..)) " + | ||
"&& !execution(* com.postgraduate.domain.mentoring.application.usecase.MentoringManageUseCase.applyMentoring(..))" | ||
) | ||
public void allMentoringService() {} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/postgraduate/global/aop/lock/LockException.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 com.postgraduate.global.aop.lock; | ||
|
||
import com.postgraduate.global.exception.ApplicationException; | ||
|
||
public class LockException extends ApplicationException { | ||
protected LockException() { | ||
super("Lock ํ๋์ค ์์ธ ๋ฐ์" , "EX_LOCK"); | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
...raduate/global/logging/aop/PointCuts.java โ ...uate/global/aop/logging/LogPointCuts.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
5 changes: 3 additions & 2 deletions
5
...graduate/global/logging/aop/LogTrace.java โ ...graduate/global/aop/logging/LogTrace.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
2 changes: 1 addition & 1 deletion
2
...aduate/global/logging/dto/LogRequest.java โ ...te/global/aop/logging/dto/LogRequest.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
2 changes: 1 addition & 1 deletion
2
...duate/global/logging/aop/TraceStatus.java โ ...e/global/aop/logging/dto/TraceStatus.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package com.postgraduate.global.logging.aop; | ||
package com.postgraduate.global.aop.logging.dto; | ||
|
||
public record TraceStatus(String threadId, Long startTime, String methodName) {} |
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
2 changes: 1 addition & 1 deletion
2
...graduate/global/logging/aop/LogUtils.java โ ...te/global/aop/logging/utils/LogUtils.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
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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/postgraduate/global/slack/SlackCertificationMessage.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,53 @@ | ||
package com.postgraduate.global.slack; | ||
|
||
import com.postgraduate.domain.senior.domain.entity.Senior; | ||
import com.postgraduate.domain.user.domain.entity.User; | ||
import com.slack.api.Slack; | ||
import com.slack.api.model.Attachment; | ||
import com.slack.api.webhook.Payload; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static com.postgraduate.global.slack.SlackUtils.generateSlackField; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Component | ||
public class SlackCertificationMessage { | ||
private final Slack slackClient = Slack.getInstance(); | ||
|
||
@Value("${slack.certification_url}") | ||
private String certificationUrl; | ||
|
||
public void sendCertification(Senior senior) { | ||
try { | ||
slackClient.send(certificationUrl, Payload.builder() | ||
.text("์ ๋ฐฐ ์ธ์ฆ ์์ฒญ์ด ๋ค์ด์์ต๋๋ค!") | ||
.attachments( | ||
List.of(generateCertificationAttachment(senior)) | ||
) | ||
.build()); | ||
} catch (IOException e) { | ||
log.error("slack ์ ์ก ์ค๋ฅ"); | ||
} | ||
} | ||
|
||
private Attachment generateCertificationAttachment(Senior senior) { | ||
User user = senior.getUser(); | ||
return Attachment.builder() | ||
.color("2FC4B2") | ||
.title("์ ๋ฐฐ ์ธ์ฆ ์์ฒญ") | ||
.fields(List.of( | ||
generateSlackField("์ ๋ฐฐ ๋๋ค์ : ", user.getNickName()), | ||
generateSlackField("์ ๋ฐฐ ๋ํ์ : ", senior.getInfo().getPostgradu()), | ||
generateSlackField("์ ๋ฐฐ ์ฐ๊ตฌ์ค : ", senior.getInfo().getLab()), | ||
generateSlackField("์ ๋ฐฐ ๊ต์ : " , senior.getInfo().getProfessor()) | ||
)) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.