Skip to content

Commit

Permalink
Merge pull request #3 from Hansehart/develop
Browse files Browse the repository at this point in the history
update main
  • Loading branch information
Hansehart authored Sep 29, 2024
2 parents 705d881 + 80d9a26 commit 0fd3293
Show file tree
Hide file tree
Showing 201 changed files with 8,293 additions and 1,248 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend/fflernapp
working-directory: ./frontend/artifact
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: 18.12
cache: 'npm'
cache-dependency-path: frontend/fflernapp/package-lock.json
cache-dependency-path: frontend/artifact/package-lock.json

- run: npm ci
- run: npm run build --if-present
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# FFLernApp
# Feuerwehr App

Diese Applikation unterstützt Feuerwehr-Angehörige. Dabei werden Funktionalitäten angeboten wie:

- Lerninhalte und Vorschriften
- Überprüfugung der Einsatzbereitschaft
- Lehrgangsübersicht
- Fahrzeugplege

Das Repository ist in vier Bereiche aufgeteilt:

- Frontend
- Backend
- Deployment
- Documents
6 changes: 6 additions & 0 deletions backend/artifact/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.1</version>
</dependency>

</dependencies>

<build>
Expand Down
53 changes: 43 additions & 10 deletions backend/artifact/src/main/java/group/artifact/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
package group.artifact;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/postman/*").permitAll()
.anyRequest().authenticated())
.csrf(req -> req
.disable())
.build();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests((requests) -> requests
.requestMatchers("/api/service/**").permitAll()
.anyRequest().authenticated())

.cors(httpSecurityCorsConfigurer -> httpSecurityCorsConfigurer
.configurationSource(corsConfigurationSource()))

.csrf(req -> req.disable())

.build();
}

@Value("${FRONTEND_ADDRESS}")
private String allowedOrigins;

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowedOrigins(List.of(allowedOrigins));
corsConfiguration.setAllowedMethods(List.of("GET", "POST"));
corsConfiguration.setAllowedHeaders(List.of("*"));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setMaxAge(3600L);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/api/service/**", corsConfiguration);
return source;
}

@Bean
public AuthenticationManager noDefaultPassword() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package group.artifact.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import group.artifact.models.Message;
import group.artifact.services.ContactService;

@RestController
@RequestMapping("/api/service")
public class ContactController {
@Autowired
ContactService contactService;

@PostMapping("/save/message")
public ResponseEntity<String> saveMessage(@RequestBody Message m) {
try {
contactService.save(m);
return ResponseEntity.ok(
"message successfully received");
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package group.artifact.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import group.artifact.dtos.ContainerDTO;
import group.artifact.models.Firedepartment;
import group.artifact.services.FiredepartmentService;

@RestController
@RequestMapping("/api/service")
public class FiredepartmentController {

@Autowired
FiredepartmentService firedepartmentService;

@GetMapping("/receive/firedepartments")
public ResponseEntity<List<Firedepartment>> receiveFiredepartments() {
try {
List<Firedepartment> fd = firedepartmentService.receiveAll();
return ResponseEntity.ok(fd);
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@GetMapping("/receive/firedepartment")
public ResponseEntity<ContainerDTO<String>> receiveFiredepartmentInformation(@CookieValue(value = "sid") String sid, @RequestParam(required = true) String attr) { // attribute
try {
ContainerDTO<String> msg = firedepartmentService.receiveAttribute(sid, attr);
if (msg == null) { // user unknown
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
}
if (msg.getContent() == null) { // user is known but not a member of a firedepartment
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(null);
}
return ResponseEntity.ok(msg);
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@PostMapping("/save/firedepartment")
public ResponseEntity<String> saveFiredepartment(@RequestBody Firedepartment fd) {
try {
firedepartmentService.save(fd);
return ResponseEntity.ok("firedepartment successfully created");
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package group.artifact.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import group.artifact.dtos.StorageWithMaterialsDTO;
import group.artifact.services.MaterialService;

@RestController
@RequestMapping("/api/service")
public class MaterialController {
@Autowired
MaterialService materialService;

@PostMapping("/save/material")
public ResponseEntity<String> saveMaterial(@RequestBody StorageWithMaterialsDTO m) {
try {
materialService.save(m);
return ResponseEntity.ok(
"material successfully assigned to its corresponding storage");
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package group.artifact.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import group.artifact.models.Preview;
import group.artifact.services.PreviewService;

@RestController
@RequestMapping("/api/service")
public class PreviewController {

@Autowired
PreviewService previewService;

@GetMapping("/receive/previews")
public ResponseEntity<List<Preview>> receiveContentpage(@RequestParam(required = true) String type) {
try {
List<Preview> cp = previewService.receive(type);
return ResponseEntity.ok(cp);
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@PostMapping("/save/preview")
public ResponseEntity<String> saveContentpage(@RequestBody Preview cp) {
try {
previewService.save(cp);
return ResponseEntity.ok("preview successfully created");
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package group.artifact.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import group.artifact.dtos.ContainerDTO;
import group.artifact.dtos.QuizDTO;
import group.artifact.services.QuizService;
import group.artifact.services.UserService;

@RestController
@RequestMapping("/api/service")
public class QuizController {

@Autowired
UserService userService;

@Autowired
QuizService quizService;

@GetMapping("/receive/quiz")
public ResponseEntity<QuizDTO> receiveQuiz(@RequestParam(required = true) String category) { // question id
try {
if (category == null) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
QuizDTO q = quizService.receive(category);
return ResponseEntity.ok(q);
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@PostMapping("/save/quiz")
public ResponseEntity<String> saveQuiz(@RequestBody QuizDTO quiz) {
try {
quizService.save(quiz);
return ResponseEntity.ok("quiz successfully created");
} catch (Exception e) {
System.out.println("ERROR: " + e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@GetMapping("/receive/quiz-categories")
public ResponseEntity<ContainerDTO<List<String>>> receiveCategories() {
try {
ContainerDTO<List<String>> container = new ContainerDTO<List<String>>();
List<String> categories = quizService.receiveCategories();
container.setContent(categories);
return ResponseEntity.ok(container);
} catch (Exception e) {
System.out.println(e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@GetMapping("/receive/quiz-progress")
public ResponseEntity<ContainerDTO<Integer>> receiveProgress(
@CookieValue(name = "sid", required = true) String sid) {
try {
ContainerDTO<Boolean> msg = userService.authUser(sid);
if (msg.getContent()) { // user is authenticated
Integer progress = quizService.receiveProgress(sid);
return ResponseEntity.ok(new ContainerDTO<Integer>(progress));
}
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
} catch (Exception e) {
System.out.println(e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@PostMapping("/save/quiz-progress")
public ResponseEntity<String> saveProgress(@RequestBody ContainerDTO<Integer> container,
@CookieValue(name = "sid", required = true) String sid) { // question id
try {
ContainerDTO<Boolean> msg = userService.authUser(sid);
if (msg.getContent()) { // user is authenticated
Integer qid = container.getContent();
Boolean success = quizService.saveProgress(qid, sid);
if (success) {
return ResponseEntity.ok("progress successfully saved");
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
} catch (Exception e) {
System.out.println(e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
}
Loading

0 comments on commit 0fd3293

Please sign in to comment.