-
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 #3 from Hansehart/develop
update main
- Loading branch information
Showing
201 changed files
with
8,293 additions
and
1,248 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
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 |
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
53 changes: 43 additions & 10 deletions
53
backend/artifact/src/main/java/group/artifact/SecurityConfig.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 |
---|---|---|
@@ -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; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
backend/artifact/src/main/java/group/artifact/controller/ContactController.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,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); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
backend/artifact/src/main/java/group/artifact/controller/FiredepartmentController.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,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); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
backend/artifact/src/main/java/group/artifact/controller/MaterialController.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,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); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
backend/artifact/src/main/java/group/artifact/controller/PreviewController.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,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); | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
backend/artifact/src/main/java/group/artifact/controller/QuizController.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,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); | ||
} | ||
} | ||
} |
Oops, something went wrong.