-
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 #207 from WE-ARE-RACCOONS/develop
Develop
- Loading branch information
Showing
13 changed files
with
179 additions
and
13 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
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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/postgraduate/global/slack/SlackPaymentMessage.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 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; | ||
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.domain.wish.domain.entity.constant.Status.REJECTED; | ||
import static com.postgraduate.global.slack.SlackUtils.generateSlackField; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class SlackPaymentMessage { | ||
private final Slack slackClient = Slack.getInstance(); | ||
|
||
@Value("${slack.pay_url}") | ||
private String paymentUrl; | ||
|
||
public void sendPayment(Payment payment) { | ||
try { | ||
slackClient.send(paymentUrl, Payload.builder() | ||
.text("결제가 되었습니다!") | ||
.attachments( | ||
List.of(generatePaymentAttachment(payment)) | ||
) | ||
.build()); | ||
} catch (IOException e) { | ||
log.error("slack 전송 오류"); | ||
} | ||
} | ||
|
||
//attach 생성 -> Field를 리스트로 담자 | ||
private Attachment generatePaymentAttachment(Payment payment) { | ||
User user = payment.getUser(); | ||
Senior senior = payment.getSenior(); | ||
User seniorUser = senior.getUser(); | ||
return Attachment.builder() | ||
.color("2FC4B2") | ||
.title("결제정보") | ||
.fields(List.of( | ||
generateSlackField("결제 금액 : ", String.valueOf(payment.getPay())), | ||
generateSlackField("후배 닉네임 : ", user.getNickName()), | ||
generateSlackField("선배 닉네임 : ", seniorUser.getNickName()) | ||
)) | ||
.build(); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/com/postgraduate/global/slack/SlackSignUpMessage.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,93 @@ | ||
package com.postgraduate.global.slack; | ||
|
||
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; | ||
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.domain.wish.domain.entity.constant.Status.REJECTED; | ||
import static com.postgraduate.global.slack.SlackUtils.generateSlackField; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class SlackSignUpMessage { | ||
private final Slack slackClient = Slack.getInstance(); | ||
|
||
@Value("${slack.junior_url}") | ||
private String juniorUrl; | ||
@Value("${slack.senior_url}") | ||
private String seniorUrl; | ||
|
||
public void sendJuniorSignUp(User user, Wish wish) { | ||
try { | ||
slackClient.send(juniorUrl, Payload.builder() | ||
.text("후배가 가입했습니다!") | ||
.attachments( | ||
List.of(generateJuniorSignUpAttachment(user, wish)) | ||
) | ||
.build()); | ||
} catch (IOException e) { | ||
log.error("slack 전송 오류"); | ||
} | ||
} | ||
|
||
public void sendSeniorSignUp(Senior senior) { | ||
try { | ||
slackClient.send(seniorUrl, Payload.builder() | ||
.text("선배가 가입했습니다!") | ||
.attachments( | ||
List.of(generateSeniorSignUpAttachment(senior)) | ||
) | ||
.build()); | ||
} catch (IOException e) { | ||
log.error("slack 전송 오류"); | ||
} | ||
} | ||
|
||
//attach 생성 -> Field를 리스트로 담자 | ||
private Attachment generateJuniorSignUpAttachment(User user, Wish wish) { | ||
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()) | ||
)) | ||
.build(); | ||
} | ||
|
||
private Attachment generateSeniorSignUpAttachment(Senior senior) { | ||
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()) | ||
)) | ||
.build(); | ||
} | ||
} |
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