Skip to content

Commit 0b658c2

Browse files
authored
Merge pull request #6 from ls1intum/local
Local
2 parents 2a9ee29 + ea27d95 commit 0b658c2

15 files changed

+127
-45
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ jobs:
8686
echo "ANGELOS_SECRET=${{ secrets.ANGELOS_SECRET }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
8787
echo "ANGELOS_USERNAME=${{ secrets.ANGELOS_USERNAME }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
8888
echo "ANGELOS_PASSWORD=${{ secrets.ANGELOS_PASSWORD }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
89-
echo "EUNOMNIA_URL=${{ secrets.EUNOMNIA_URL }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
90-
echo "EUNOMNIA_SECRET=${{ secrets.EUNOMNIA_SECRET }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
89+
echo "EUNOMIA_URL=${{ secrets.EUNOMNIA_URL }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
90+
echo "EUNOMIA_SECRET=${{ secrets.EUNOMNIA_SECRET }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
9191
9292
# Create .env.postgres file for Postgres on VM
9393
- name: Create .env.postgres on VM

docker-compose.local.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: "3.8"
2+
3+
services:
4+
db:
5+
image: postgres:13
6+
container_name: angelos-db
7+
restart: always
8+
ports:
9+
- "5433:5432"
10+
env_file:
11+
- postgres.env
12+
volumes:
13+
- postgres_db_data:/var/lib/postgresql/data
14+
networks:
15+
- angelos-network
16+
17+
angelos-server:
18+
build:
19+
context: .
20+
dockerfile: Dockerfile
21+
container_name: angelos-server
22+
depends_on:
23+
- db
24+
expose:
25+
- "9007"
26+
ports:
27+
- "9007:9007"
28+
env_file:
29+
- development.env
30+
environment:
31+
SPRING_PROFILES_ACTIVE: dev
32+
networks:
33+
- angelos-network
34+
35+
volumes:
36+
postgres_db_data:
37+
38+
networks:
39+
angelos-network:
40+
external: true

src/main/java/com/ase/angelos_kb_backend/controller/ChatController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public ResponseEntity<AngelosChatResponse> chat(@RequestHeader("ChatAuth") Strin
8585
*/
8686
@PostMapping("/login")
8787
public ResponseEntity<Map<String, String>> postMethodName(@RequestHeader("x-api-key") String apiKey, @RequestBody LoginRequestDTO body) {
88+
89+
System.out.println(body);
8890
if (angelosService.verifyAPIKey(apiKey) && body.getEmail().equals(angelosUsername) && body.getPassword().equals(angelosPassword)) {
8991
String chatToken = jwtUtil.generateChatToken(body.getEmail(), body.getPassword());
9092
return ResponseEntity.ok().body(Map.of("accessToken", chatToken));

src/main/java/com/ase/angelos_kb_backend/controller/MailController.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
import org.springframework.web.server.ResponseStatusException;
1616

1717
import com.ase.angelos_kb_backend.dto.angelos.AngelosChatResponse;
18-
import com.ase.angelos_kb_backend.dto.eunomnia.MailCredentialsDTO;
19-
import com.ase.angelos_kb_backend.dto.eunomnia.MailCredentialsResponseDTO;
20-
import com.ase.angelos_kb_backend.dto.eunomnia.MailResponseRequestDTO;
21-
import com.ase.angelos_kb_backend.dto.eunomnia.MailStatusDTO;
22-
import com.ase.angelos_kb_backend.dto.eunomnia.MailThreadRequestDTO;
18+
import com.ase.angelos_kb_backend.dto.eunomia.MailCredentialsDTO;
19+
import com.ase.angelos_kb_backend.dto.eunomia.MailCredentialsResponseDTO;
20+
import com.ase.angelos_kb_backend.dto.eunomia.MailResponseRequestDTO;
21+
import com.ase.angelos_kb_backend.dto.eunomia.MailStatusDTO;
22+
import com.ase.angelos_kb_backend.dto.eunomia.MailThreadRequestDTO;
2323
import com.ase.angelos_kb_backend.service.AngelosService;
24-
import com.ase.angelos_kb_backend.service.EunomniaService;
24+
import com.ase.angelos_kb_backend.service.EunomiaService;
2525
import com.ase.angelos_kb_backend.service.OrganisationService;
2626
import com.ase.angelos_kb_backend.service.StudyProgramService;
2727
import com.ase.angelos_kb_backend.util.JwtUtil;
@@ -35,17 +35,17 @@ public class MailController {
3535
private final OrganisationService organisationService;
3636
private final StudyProgramService studyProgramService;
3737
private final JwtUtil jwtUtil;
38-
private final EunomniaService eunomniaService;
38+
private final EunomiaService eunomiaService;
3939
private final AngelosService angelosService;
4040

4141
@Value("${app.max-message-length}")
4242
private int maxMessageLength;
4343

44-
public MailController(OrganisationService organisationService, StudyProgramService studyProgramService, JwtUtil jwtUtil, EunomniaService eunomniaService, AngelosService angelosService) {
44+
public MailController(OrganisationService organisationService, StudyProgramService studyProgramService, JwtUtil jwtUtil, EunomiaService eunomiaService, AngelosService angelosService) {
4545
this.jwtUtil = jwtUtil;
4646
this.organisationService = organisationService;
4747
this.studyProgramService = studyProgramService;
48-
this.eunomniaService = eunomniaService;
48+
this.eunomiaService = eunomiaService;
4949
this.angelosService = angelosService;
5050
}
5151

@@ -71,7 +71,7 @@ public ResponseEntity<Void> setCredentials(
7171
List<String> studyPrograms = studyProgramService.getAllStudyProgramsByOrgId(orgId).stream().map(sp -> sp.getName()).toList();
7272
dto.setStudyPrograms(studyPrograms);
7373

74-
success = eunomniaService.startThread(orgId, dto);
74+
success = eunomiaService.startThread(orgId, dto);
7575
}
7676

7777
if (success) {
@@ -103,7 +103,7 @@ public ResponseEntity<MailCredentialsResponseDTO> getCredentials(
103103
@PostMapping("/deactivate")
104104
public ResponseEntity<Void> deactivate(@RequestHeader("Authorization") String token) {
105105
Long orgId = jwtUtil.extractOrgId(token.replace("Bearer ", ""));
106-
boolean success = eunomniaService.stopThread(orgId);
106+
boolean success = eunomiaService.stopThread(orgId);
107107
if (success) {
108108
organisationService.setMailStatus(orgId, MailStatus.INACTIVE);
109109
return ResponseEntity.ok().build();
@@ -121,7 +121,7 @@ public ResponseEntity<MailStatusDTO> getStatus(@RequestHeader("Authorization") S
121121
Long orgId = jwtUtil.extractOrgId(token.replace("Bearer ", ""));
122122

123123
MailStatusDTO statusDto = new MailStatusDTO();
124-
MailStatus status = eunomniaService.getStatus(orgId).getStatus();
124+
MailStatus status = eunomiaService.getStatus(orgId).getStatus();
125125

126126
statusDto.setStatus(status);
127127
organisationService.setMailStatus(orgId, status);
@@ -137,7 +137,7 @@ public ResponseEntity<AngelosChatResponse> ask(
137137
@RequestHeader("x-api-key") String apiKey,
138138
@RequestBody MailResponseRequestDTO request) {
139139

140-
if (eunomniaService.verifyAPIKey(apiKey)) {
140+
if (eunomiaService.verifyAPIKey(apiKey)) {
141141
if (request.getMessage() != null && request.getMessage().length() > maxMessageLength) {
142142
throw new ResponseStatusException(
143143
HttpStatus.BAD_REQUEST,

src/main/java/com/ase/angelos_kb_backend/controller/SampleQuestionController.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
import java.util.UUID;
55

6+
import org.springframework.http.HttpStatus;
67
import org.springframework.http.ResponseEntity;
78
import org.springframework.web.bind.annotation.DeleteMapping;
89
import org.springframework.web.bind.annotation.GetMapping;
@@ -49,10 +50,17 @@ public ResponseEntity<List<SampleQuestionDTO>> getAllSampleQuestions(@RequestHea
4950
public ResponseEntity<SampleQuestionDTO> addSampleQuestion(
5051
@RequestHeader("Authorization") String token,
5152
@Valid @RequestBody SampleQuestionDTO sampleQuestionDTO) {
52-
53-
Long orgId = jwtUtil.extractOrgId(token.replace("Bearer ", ""));
54-
SampleQuestionDTO responseDTO = sampleQuestionService.addSampleQuestion(orgId, sampleQuestionDTO);
55-
return ResponseEntity.ok(responseDTO);
53+
try {
54+
System.out.println("addSampleQuestion");
55+
Long orgId = jwtUtil.extractOrgId(token.replace("Bearer ", ""));
56+
SampleQuestionDTO responseDTO = sampleQuestionService.addSampleQuestion(orgId, sampleQuestionDTO);
57+
System.out.println("added sample question");
58+
return ResponseEntity.ok(responseDTO);
59+
} catch (Exception e) {
60+
System.err.println("Error adding sample question: " + e.getMessage());
61+
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
62+
.body(null); // Adjust response as necessary for your API's design
63+
}
5664
}
5765

5866
/**

src/main/java/com/ase/angelos_kb_backend/dto/eunomnia/MailCredentialsDTO.java renamed to src/main/java/com/ase/angelos_kb_backend/dto/eunomia/MailCredentialsDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ase.angelos_kb_backend.dto.eunomnia;
1+
package com.ase.angelos_kb_backend.dto.eunomia;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44

src/main/java/com/ase/angelos_kb_backend/dto/eunomnia/MailCredentialsResponseDTO.java renamed to src/main/java/com/ase/angelos_kb_backend/dto/eunomia/MailCredentialsResponseDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ase.angelos_kb_backend.dto.eunomnia;
1+
package com.ase.angelos_kb_backend.dto.eunomia;
22

33
import lombok.AllArgsConstructor;
44
import lombok.Builder;

src/main/java/com/ase/angelos_kb_backend/dto/eunomnia/MailResponseRequestDTO.java renamed to src/main/java/com/ase/angelos_kb_backend/dto/eunomia/MailResponseRequestDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ase.angelos_kb_backend.dto.eunomnia;
1+
package com.ase.angelos_kb_backend.dto.eunomia;
22

33
import lombok.AllArgsConstructor;
44
import lombok.Builder;

src/main/java/com/ase/angelos_kb_backend/dto/eunomnia/MailStatusDTO.java renamed to src/main/java/com/ase/angelos_kb_backend/dto/eunomia/MailStatusDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ase.angelos_kb_backend.dto.eunomnia;
1+
package com.ase.angelos_kb_backend.dto.eunomia;
22

33
import com.ase.angelos_kb_backend.util.MailStatus;
44

src/main/java/com/ase/angelos_kb_backend/dto/eunomnia/MailThreadRequestDTO.java renamed to src/main/java/com/ase/angelos_kb_backend/dto/eunomia/MailThreadRequestDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ase.angelos_kb_backend.dto.eunomnia;
1+
package com.ase.angelos_kb_backend.dto.eunomia;
22

33
import java.util.List;
44

src/main/java/com/ase/angelos_kb_backend/service/AngelosService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.ase.angelos_kb_backend.dto.angelos.AngelosEditSampleQuestionRequest;
2323
import com.ase.angelos_kb_backend.dto.angelos.AngelosEditWebsiteRequest;
2424
import com.ase.angelos_kb_backend.dto.angelos.AngelosRefreshContentRequest;
25-
import com.ase.angelos_kb_backend.dto.eunomnia.MailResponseRequestDTO;
25+
import com.ase.angelos_kb_backend.dto.eunomia.MailResponseRequestDTO;
2626

2727
@Component
2828
public class AngelosService {
@@ -262,6 +262,7 @@ private boolean sendPostRequest(String endpoint, Object body) {
262262

263263
return response.getStatusCode().is2xxSuccessful();
264264
} catch (Exception e) {
265+
System.err.println("Error sending request: " + e.getMessage());
265266
return false;
266267
}
267268
}

src/main/java/com/ase/angelos_kb_backend/service/EunomniaService.java renamed to src/main/java/com/ase/angelos_kb_backend/service/EunomiaService.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
import org.springframework.stereotype.Component;
99
import org.springframework.web.client.RestTemplate;
1010

11-
import com.ase.angelos_kb_backend.dto.eunomnia.MailStatusDTO;
12-
import com.ase.angelos_kb_backend.dto.eunomnia.MailThreadRequestDTO;
11+
import com.ase.angelos_kb_backend.dto.eunomia.MailStatusDTO;
12+
import com.ase.angelos_kb_backend.dto.eunomia.MailThreadRequestDTO;
1313
import com.ase.angelos_kb_backend.util.MailStatus;
1414

1515
@Component
16-
public class EunomniaService {
16+
public class EunomiaService {
1717

18-
@Value("${eunomnia.url}")
19-
private String eunomniaUrl;
18+
@Value("${eunomia.url}")
19+
private String eunomiaUrl;
2020

21-
@Value("${eunomnia.secret}")
22-
private String eunomniaApiKey;
21+
@Value("${eunomia.secret}")
22+
private String eunomiaApiKey;
2323

2424
private final RestTemplate restTemplate;
2525

26-
public EunomniaService() {
26+
public EunomiaService() {
2727
this.restTemplate = new RestTemplate();
2828
}
2929

@@ -34,11 +34,11 @@ public EunomniaService() {
3434
* @return MailStatusDTO with the pipeline's status
3535
*/
3636
public MailStatusDTO getStatus(Long orgId) {
37-
String endpoint = eunomniaUrl + "/mail/" + orgId + "/status";
37+
String endpoint = eunomiaUrl + "/mail/" + orgId + "/status";
3838

3939
try {
4040
HttpHeaders headers = new HttpHeaders();
41-
headers.set("x-api-key", eunomniaApiKey);
41+
headers.set("x-api-key", eunomiaApiKey);
4242
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
4343

4444
ResponseEntity<MailStatusDTO> response = restTemplate.exchange(
@@ -66,11 +66,11 @@ public MailStatusDTO getStatus(Long orgId) {
6666
* @return true if the thread starts successfully, false otherwise
6767
*/
6868
public boolean startThread(Long orgId, MailThreadRequestDTO credentials) {
69-
String endpoint = eunomniaUrl + "/mail/" + orgId + "/start";
69+
String endpoint = eunomiaUrl + "/mail/" + orgId + "/start";
7070

7171
try {
7272
HttpHeaders headers = new HttpHeaders();
73-
headers.set("x-api-key", eunomniaApiKey);
73+
headers.set("x-api-key", eunomiaApiKey);
7474
HttpEntity<MailThreadRequestDTO> requestEntity = new HttpEntity<>(credentials, headers);
7575

7676
ResponseEntity<Void> response = restTemplate.postForEntity(endpoint, requestEntity, Void.class);
@@ -88,11 +88,11 @@ public boolean startThread(Long orgId, MailThreadRequestDTO credentials) {
8888
* @return true if the thread stops successfully, false otherwise
8989
*/
9090
public boolean stopThread(Long orgId) {
91-
String endpoint = eunomniaUrl + "/mail/" + orgId + "/stop";
91+
String endpoint = eunomiaUrl + "/mail/" + orgId + "/stop";
9292

9393
try {
9494
HttpHeaders headers = new HttpHeaders();
95-
headers.set("x-api-key", eunomniaApiKey);
95+
headers.set("x-api-key", eunomiaApiKey);
9696
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
9797

9898
ResponseEntity<Void> response = restTemplate.exchange(
@@ -110,12 +110,12 @@ public boolean stopThread(Long orgId) {
110110
}
111111

112112
/**
113-
* Helper method to validate the API key for Eunomnia calls.
113+
* Helper method to validate the API key for Eunomia calls.
114114
*
115115
* @param apiKey The API key to validate
116116
* @return true if valid, false otherwise
117117
*/
118118
public boolean verifyAPIKey(String apiKey) {
119-
return eunomniaApiKey.equals(apiKey);
119+
return eunomiaApiKey.equals(apiKey);
120120
}
121121
}

src/main/java/com/ase/angelos_kb_backend/service/OrganisationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.springframework.stereotype.Service;
88

99
import com.ase.angelos_kb_backend.dto.OrganisationDTO;
10-
import com.ase.angelos_kb_backend.dto.eunomnia.MailCredentialsDTO;
10+
import com.ase.angelos_kb_backend.dto.eunomia.MailCredentialsDTO;
1111
import com.ase.angelos_kb_backend.exception.ResourceNotFoundException;
1212
import com.ase.angelos_kb_backend.model.Organisation;
1313
import com.ase.angelos_kb_backend.repository.OrganisationRepository;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
server.address=0.0.0.0
2+
server.port=9007
3+
spring.jpa.hibernate.ddl-auto=create
4+
spring.application.name=angelos-kb-backend
5+
spring.datasource.url=jdbc:postgresql://db:5432/kbdatabase
6+
spring.mail.host=smtp.gmail.com
7+
spring.mail.port=587
8+
spring.mail.protocol=smtp
9+
spring.mail.properties.mail.smtp.auth=true
10+
spring.mail.properties.mail.smtp.starttls.enable=true
11+
spring.mail.properties.mail.smtp.starttls.required=true
12+
spring.mail.default-encoding=UTF-8
13+
spring.mail.username=${MAIL_USERNAME}
14+
spring.mail.password=${MAIL_PASSWORD}
15+
spring.datasource.username=${DB_USERNAME}
16+
spring.datasource.password=${DB_PASSWORD}
17+
springdoc.swagger-ui.path=/docs
18+
spring.devtools.restart.exclude=src/main/resources/db_init/websites/**
19+
file.upload-dir=${UPLOAD_DIR}
20+
admin.default.email=${ADMIN_MAIL}
21+
admin.default.password=${ADMIN_PASSWORD}
22+
cors.kb-ui=${KB_ORIGIN}
23+
cors.chatbot=${CHATBOT_ORIGIN}
24+
angelos.url=${ANGELOS_URL}
25+
angelos.secret=${ANGELOS_SECRET}
26+
angelos.username=${ANGELOS_USERNAME}
27+
angelos.passsword=${ANGELOS_PASSWORD}
28+
eunomia.url=${EUNOMIA_URL}
29+
eunomia.secret=${EUNOMIA_SECRET}
30+
jwt.secret.key=${JWT_SECRET_KEY}
31+
app.max-message-length=2000

src/main/resources/application.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
server.address=0.0.0.0
12
server.port=9007
23
spring.jpa.hibernate.ddl-auto=update
34
spring.application.name=angelos-kb-backend
@@ -15,7 +16,6 @@ spring.mail.password=${MAIL_PASSWORD}
1516
spring.datasource.username=${DB_USERNAME}
1617
spring.datasource.password=${DB_PASSWORD}
1718
springdoc.swagger-ui.path=/docs
18-
springdoc.swagger-ui.enabled=true
1919
spring.devtools.restart.exclude=src/main/resources/db_init/websites/**
2020
file.upload-dir=${UPLOAD_DIR}
2121
admin.default.email=${ADMIN_MAIL}
@@ -26,7 +26,7 @@ angelos.url=${ANGELOS_URL}
2626
angelos.secret=${ANGELOS_SECRET}
2727
angelos.username=${ANGELOS_USERNAME}
2828
angelos.passsword=${ANGELOS_PASSWORD}
29-
eunomnia.url=${EUNOMNIA_URL}
30-
eunomnia.secret=${EUNOMNIA_SECRET}
29+
eunomia.url=${EUNOMIA_URL}
30+
eunomia.secret=${EUNOMIA_SECRET}
3131
jwt.secret.key=${JWT_SECRET_KEY}
3232
app.max-message-length=2000

0 commit comments

Comments
 (0)