Skip to content

Commit

Permalink
Merge pull request #79 from Team-UniVoice/fix#/68-slack-token-use
Browse files Browse the repository at this point in the history
Fix#/68 slack token use
  • Loading branch information
softmoca authored Jul 18, 2024
2 parents 3496de5 + 600dd6a commit ea6e9bc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ dependencies {
implementation 'org.json:json:20210307'

// Slack API 라이브러리 버전 일치
implementation 'com.slack.api:slack-app-backend:1.30.0'
implementation 'com.slack.api:slack-api-model:1.30.0'
implementation 'com.slack.api:slack-api-client:1.30.0'


implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5'
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package sopt.univoice.domain.universityData.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.slack.api.Slack;
import com.slack.api.webhook.WebhookResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -9,18 +13,35 @@
import sopt.univoice.infra.common.dto.SuccessMessage;
import sopt.univoice.infra.common.dto.SuccessStatusResponse;

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

@Slf4j
@RestController
@RequestMapping("/api/v1/universityData")
@RequiredArgsConstructor
public class UniversityDataController {

private final UniversityDataService universityDataService;
private final ObjectMapper objectMapper;
final String WEBHOOK_URL = "https://hooks.slack.com/services/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";


@PostMapping("/university")
public ResponseEntity<SuccessStatusResponse<List<String>>> getAllUniversityNames() {
List<String> universityNames = universityDataService.getAllUniversityNames();

Slack slack = Slack.getInstance();
String payload = "{\"text\":\"슬랙 메시지 테스트입니다.\"}";
try {
WebhookResponse response = slack.send(WEBHOOK_URL, payload);
System.out.println(response);
} catch (IOException e) {
log.error("slack 메시지 발송 중 문제가 발생했습니다.", e.toString());
throw new RuntimeException(e);
}


return ResponseEntity.status(HttpStatus.OK)
.body(SuccessStatusResponse.of(SuccessMessage.UNIVERSITY_GET_SUCCESS, universityNames));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public class UniversityDataService {

public List<String> getAllUniversityNames() {
List<University> universities = universityDataRepository.findAll();
final String WEBHOOK_URL = "https://hooks.slack.com/services/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";










return universities.stream()
.map(University::getUniversityName)
.collect(Collectors.toList());
Expand Down

0 comments on commit ea6e9bc

Please sign in to comment.