Skip to content

Commit

Permalink
Merge pull request #211 from WE-ARE-RACCOONS/RAC-335
Browse files Browse the repository at this point in the history
RAC-335 refactor : ์Šฌ๋ž™ ๋ฉ”์‹œ์ง€ ๋‚ด์šฉ ๋ณ€๊ฒฝ
  • Loading branch information
ywj9811 authored Apr 3, 2024
2 parents 0807b2d + 9cb789f commit 76eee92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.postgraduate.global.slack;

import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.senior.domain.entity.Info;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.wish.domain.entity.Wish;
import com.postgraduate.domain.wish.domain.entity.constant.Status;
import com.slack.api.Slack;
import com.slack.api.model.Attachment;
import com.slack.api.webhook.Payload;
Expand All @@ -15,9 +10,9 @@
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;

import static com.postgraduate.domain.wish.domain.entity.constant.Status.REJECTED;
import static com.postgraduate.global.slack.SlackUtils.generateSlackField;

@Component
Expand All @@ -29,6 +24,7 @@ public class SlackPaymentMessage {
@Value("${slack.pay_url}")
private String paymentUrl;


public void sendPayment(Payment payment) {
try {
slackClient.send(paymentUrl, Payload.builder()
Expand All @@ -42,18 +38,18 @@ public void sendPayment(Payment payment) {
}
}

//attach ์ƒ์„ฑ -> Field๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋‹ด์ž
private Attachment generatePaymentAttachment(Payment payment) {
User user = payment.getUser();
Senior senior = payment.getSenior();
User seniorUser = senior.getUser();
LocalDateTime createdAt = payment.getPaidAt();
return Attachment.builder()
.color("2FC4B2")
.title("๊ฒฐ์ œ์ •๋ณด")
.fields(List.of(
generateSlackField("๊ฒฐ์ œ ๊ธˆ์•ก : ", String.valueOf(payment.getPay())),
generateSlackField("ํ›„๋ฐฐ ๋‹‰๋„ค์ž„ : ", user.getNickName()),
generateSlackField("์„ ๋ฐฐ ๋‹‰๋„ค์ž„ : ", seniorUser.getNickName())
generateSlackField("๊ฒฐ์ œ ์‹œ๊ฐ„ : "
+ createdAt.getMonth().getValue() + "์›” "
+ createdAt.getDayOfMonth() + "์ผ "
+ createdAt.getHour() + "์‹œ "
+ createdAt.getMinute() + "๋ถ„ "
+ createdAt.getSecond() + "์ดˆ", null)
))
.build();
}
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/com/postgraduate/global/slack/SlackSignUpMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;

import static com.postgraduate.domain.wish.domain.entity.constant.Status.REJECTED;
Expand Down Expand Up @@ -56,37 +57,45 @@ public void sendSeniorSignUp(Senior senior) {
}
}

//attach ์ƒ์„ฑ -> Field๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋‹ด์ž
private Attachment generateJuniorSignUpAttachment(User user, Wish wish) {
LocalDateTime createdAt = user.getCreatedAt();
Status status = wish.getStatus();
String wantMatching = status == REJECTED ? "X" : "O";
return Attachment.builder()
.color("2FC4B2")
.title("๊ฐ€์ž…ํ•œ ํ›„๋ฐฐ ์ •๋ณด")
.fields(List.of(
generateSlackField("ํ›„๋ฐฐ ๋‹‰๋„ค์ž„ : ", user.getNickName()),
generateSlackField("ํ›„๋ฐฐ ์ „ํ™”๋ฒˆํ˜ธ", user.getPhoneNumber()),
generateSlackField("ํ›„๋ฐฐ ๋งค์นญํฌ๋ง ์—ฌ๋ถ€", wantMatching),
generateSlackField("ํ›„๋ฐฐ ๋งค์นญํฌ๋ง ์ „๊ณต, ๋ถ„์•ผ", wish.getMajor() + ", " + wish.getField())
generateSlackField("๊ฐ€์ž… ์‹œ๊ฐ„ : "
+ createdAt.getMonth().getValue() + "์›” "
+ createdAt.getDayOfMonth() + "์ผ "
+ createdAt.getHour() + "์‹œ "
+ createdAt.getMinute() + "๋ถ„ "
+ createdAt.getSecond() + "์ดˆ", null),
generateSlackField("ํ›„๋ฐฐ ๋‹‰๋„ค์ž„ : " + user.getNickName(), null),
generateSlackField("ํ›„๋ฐฐ ๋งค์นญํฌ๋ง ์—ฌ๋ถ€ : " + wantMatching, null),
generateSlackField("ํ›„๋ฐฐ ๋งค์นญํฌ๋ง ์ „๊ณต, ๋ถ„์•ผ : " + (wish.getMajor() + " " + wish.getField()), null)
))
.build();
}

private Attachment generateSeniorSignUpAttachment(Senior senior) {
LocalDateTime createdAt = senior.getCreatedAt();
User user = senior.getUser();
Info info = senior.getInfo();
return Attachment.builder()
.color("2FC4B2")
.title("๊ฐ€์ž…ํ•œ ์„ ๋ฐฐ ์ •๋ณด")
.fields(List.of(
generateSlackField("์„ ๋ฐฐ ๋‹‰๋„ค์ž„ : ", user.getNickName()),
generateSlackField("์„ ๋ฐฐ ์ „ํ™”๋ฒˆํ˜ธ", user.getPhoneNumber()),
generateSlackField("์„ ๋ฐฐ ๋Œ€ํ•™์›", info.getPostgradu()),
generateSlackField("์„ ๋ฐฐ ๋žฉ์‹ค", info.getLab()),
generateSlackField("์„ ๋ฐฐ ๊ต์ˆ˜๋‹˜", info.getProfessor()),
generateSlackField("์„ ๋ฐฐ ์ „๊ณต", info.getMajor()),
generateSlackField("์„ ๋ฐฐ ๋ถ„์•ผ", info.getField()),
generateSlackField("์„ ๋ฐฐ ํ‚ค์›Œ๋“œ", info.getKeyword())
generateSlackField("์„ ๋ฐฐ ๋‹‰๋„ค์ž„ : " + user.getNickName(), null),
generateSlackField("๊ฐ€์ž… ์‹œ๊ฐ„ : "
+ createdAt.getMonth().getValue() + "์›” "
+ createdAt.getDayOfMonth() + "์ผ "
+ createdAt.getHour() + "์‹œ "
+ createdAt.getMinute() + "๋ถ„ "
+ createdAt.getSecond() + "์ดˆ", null),
generateSlackField("์„ ๋ฐฐ ๋Œ€ํ•™์› : " + info.getPostgradu(), null),
generateSlackField("์„ ๋ฐฐ ์—ฐ๊ตฌ์‹ค : " + info.getLab(), null),
generateSlackField("์„ ๋ฐฐ ๊ต์ˆ˜๋‹˜ : " + info.getProfessor(), null)
))
.build();
}
Expand Down

0 comments on commit 76eee92

Please sign in to comment.