Skip to content

Commit

Permalink
[feat] #145 ErrorStatus 및 Discord 관련 파일 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeoongu committed Dec 8, 2024
1 parent d1ca0b3 commit 86d1849
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ public enum ErrorStatus implements BaseErrorCode {


//Body 에러
INVALID_BODY(HttpStatus.BAD_REQUEST, "BODY_ERROR", "Body가 올바르지 않습니다.");

INVALID_BODY(HttpStatus.BAD_REQUEST, "BODY_ERROR", "Body가 올바르지 않습니다."),

//DiscordError
INVALID_DISCORD_MESSAGE(HttpStatus.BAD_REQUEST, "DISCORD_001", "디스코드 메시지가 올바르지 않습니다.");


private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ussum.homepage.global.external.discord;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import ussum.homepage.global.external.discord.dto.DiscordMessage;

@FeignClient(name = "${discord.name}", url = "${discord.webhook-url}")
public interface DiscordFeignClient {
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
void sendMessage(@RequestBody DiscordMessage discordMessage);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ussum.homepage.global.external.discord;

import static ussum.homepage.global.external.discord.dto.DiscordMessage.createDiscordMessage;

import feign.FeignException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import ussum.homepage.global.error.exception.GeneralException;

import ussum.homepage.global.error.status.ErrorStatus;
import ussum.homepage.global.external.discord.dto.DiscordMessage;
import ussum.homepage.global.external.discord.dto.EventMessage;

@RequiredArgsConstructor
@Component
public class DiscordUtil {
private final DiscordFeignClient discordFeignClient;

public void sendMessage(EventMessage eventMessage, String message) {
DiscordMessage discordMessage = createDiscordMessage(eventMessage.getMessage() + message);
sendMessageToDiscord(discordMessage);
}

private void sendMessageToDiscord(DiscordMessage discordMessage) {
try {
discordFeignClient.sendMessage(discordMessage);
} catch (FeignException e) {
throw new GeneralException(ErrorStatus.INVALID_DISCORD_MESSAGE);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ussum.homepage.global.external.discord.dto;

public record DiscordMessage(
String content
) {
public static DiscordMessage createDiscordMessage(String message) {
return new DiscordMessage(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ussum.homepage.global.external.discord.dto;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum EventMessage {
// Error
SIGN_UP_FAIL("회원가입을 실패한 사용자가 있습니다. ");

// Success
// TO DO : 성공 메시지 추가

private final String message;
}

0 comments on commit 86d1849

Please sign in to comment.