-
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 #221 from TeamDilly/develop
v1.4.0
- Loading branch information
Showing
9 changed files
with
115 additions
and
7 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
2 changes: 2 additions & 0 deletions
2
packy-domain/src/main/java/com/dilly/member/MemberRepository.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,8 +1,10 @@ | ||
package com.dilly.member; | ||
|
||
import com.dilly.member.domain.Member; | ||
import com.dilly.member.domain.Status; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
Long countByStatus(Status 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
Submodule packy-submodule
updated
from 076de0 to c93861
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
39 changes: 39 additions & 0 deletions
39
packy-support/src/main/java/com/dilly/logging/LogAspect.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,39 @@ | ||
package com.dilly.logging; | ||
|
||
import com.dilly.member.adaptor.MemberReader; | ||
import com.dilly.member.domain.Status; | ||
import java.util.HashMap; | ||
import lombok.RequiredArgsConstructor; | ||
import org.aspectj.lang.annotation.After; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Aspect | ||
@Profile("prod") | ||
@Component | ||
@RequiredArgsConstructor | ||
public class LogAspect { | ||
|
||
private final SlackService slackService; | ||
private final MemberReader memberReader; | ||
|
||
@Value("${slack.webhook-url.sign-up}") | ||
private String signUpUrl; | ||
|
||
@Pointcut("execution(* com.dilly.auth..AuthController.signUp(..))") | ||
public void signUp() {} | ||
|
||
@After("signUp()") | ||
public void countMember() { | ||
String title = "패키에 유저가 들어왔어요!"; | ||
HashMap<String, String> data = new HashMap<>(); | ||
|
||
Long memberCount = memberReader.countByStatus(Status.REGISTERED); | ||
data.put("현재 유저 수: ", memberCount.toString() + "명"); | ||
|
||
slackService.sendMessage(signUpUrl, title, data); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
packy-support/src/main/java/com/dilly/logging/SlackService.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.dilly.logging; | ||
|
||
import com.slack.api.Slack; | ||
import com.slack.api.model.Attachment; | ||
import com.slack.api.model.Field; | ||
import com.slack.api.webhook.Payload; | ||
import java.awt.Color; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
public class SlackService { | ||
|
||
private final Slack slackClient = Slack.getInstance(); | ||
|
||
public void sendMessage(String url, String title, Map<String, String> data) { | ||
try { | ||
slackClient.send(url, Payload.builder() | ||
.text(title) | ||
.attachments(List.of( | ||
Attachment.builder() | ||
.color(Color.GREEN.toString()) | ||
.fields(data.keySet() | ||
.stream() | ||
.map(key -> generateSlackField(key, data.get(key))) | ||
.toList() | ||
) | ||
.build() | ||
)) | ||
.build() | ||
); | ||
} catch (Exception e) { | ||
log.error("Slack 메시지 전송에 실패했습니다.", e); | ||
} | ||
} | ||
|
||
private Field generateSlackField(String title, String value) { | ||
return Field.builder() | ||
.title(title) | ||
.value(value) | ||
.valueShortEnough(false) | ||
.build(); | ||
} | ||
} |