Skip to content

Commit

Permalink
restore formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Sep 27, 2024
1 parent 8ea8ae1 commit ea8bc1e
Show file tree
Hide file tree
Showing 31 changed files with 214 additions and 12,085 deletions.
3 changes: 1 addition & 2 deletions src/main/java/ch/puzzle/eft/ExamFeedbackToolApplication.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ch.puzzle.eft;

import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect;

@SpringBootApplication
public class ExamFeedbackToolApplication {

Expand Down
19 changes: 13 additions & 6 deletions src/main/java/ch/puzzle/eft/controller/ExamController.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package ch.puzzle.eft.controller;

import java.io.ByteArrayOutputStream;
import java.io.File;

import ch.puzzle.eft.service.ExamService;

import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.io.ByteArrayOutputStream;
import java.io.File;

@RestController
@RequestMapping("/exams")
public class ExamController {

//Todo mit richtiger Matrikelnummer ersetzen
private final String userMatriculationNumber = "11112222";

ExamService examFileService;

public ExamController(ExamService examFileService) {
this.examFileService = examFileService;
}


@GetMapping("/download-zip/{examNumber}")
public ResponseEntity<byte[]> downloadSubject(@PathVariable("examNumber") String examNumber) {
HttpHeaders responseHeaders = new HttpHeaders();
Expand All @@ -30,9 +36,10 @@ public ResponseEntity<byte[]> downloadSubject(@PathVariable("examNumber") String
.body(byteArrayOutputStream.toByteArray());
}

@GetMapping(value = "/download/{subject}/{fileName}", produces = MediaType.APPLICATION_PDF_VALUE)
@GetMapping(value = "/download/{subject}/{examNumber}", produces = MediaType.APPLICATION_PDF_VALUE)
@ResponseBody
public ResponseEntity<FileSystemResource> downloadFile(@PathVariable("subject") String subject, @PathVariable("fileName") String fileName) {
public ResponseEntity<FileSystemResource> downloadFile(@PathVariable("subject") String subject, @PathVariable("examNumber") String examNumber) {
String fileName = examNumber + "_" + userMatriculationNumber + ".pdf";
File examFile = examFileService.getFileToDownload(subject, fileName);
HttpHeaders responseHeaders = new HttpHeaders();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@


import ch.puzzle.eft.model.ErrorModel;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.resource.NoResourceFoundException;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

@ControllerAdvice
@Controller
public class ExceptionController implements ErrorController {

private static final Logger logger = LoggerFactory.getLogger(ExceptionController.class);
private static final String ERROR_MODEL = "errorModel";

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/ch/puzzle/eft/controller/SiteController.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package ch.puzzle.eft.controller;

import java.util.Objects;

import ch.puzzle.eft.model.ExamNumberForm;
import ch.puzzle.eft.service.ExamService;

import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.server.ResponseStatusException;

import jakarta.validation.Valid;
import java.util.Objects;

@Controller
public class SiteController {

private final ExamService examFileService;
private static final String SEARCH_TEMPLATE = "search";
private final ExamService examFileService;

public SiteController(ExamService examFileService) {
this.examFileService = examFileService;
Expand All @@ -29,6 +27,7 @@ public String viewIndexPage(Model model) {
return "index";
}


@GetMapping("/search")
public String viewSearchPage(Model model) {
model.addAttribute("examNumberForm", new ExamNumberForm(null));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/puzzle/eft/model/ExamModel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ch.puzzle.eft.model;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

import java.io.File;

public class ExamModel {
private final File file;
private static final Logger logger = LoggerFactory.getLogger(ExamModel.class);
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/ch/puzzle/eft/service/ExamService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package ch.puzzle.eft.service;

import ch.puzzle.eft.model.ExamModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -9,15 +17,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import ch.puzzle.eft.model.ExamModel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

@Service
public class ExamService {
private static final Logger logger = LoggerFactory.getLogger(ExamService.class);
Expand Down Expand Up @@ -83,9 +82,9 @@ public File getFileToDownload(String subjectName, String filename) {
List<String> pathParts = List.of(getBasePath(), subjectName, filename);
File examToDownload = new File(String.join(File.separator, pathParts));
if (!examToDownload.exists()) {
logger.info("No file found for subject {} and filename {}", subjectName, filename);
logger.info("No file found for subject {} with filename {}", subjectName, filename);
throw new ResponseStatusException(HttpStatus.NOT_FOUND,
String.format("Kein File für Fach %s und Filename %s",
String.format("Kein File für das Fach %s mit dem Dateinamen %s",
subjectName,
filename));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/puzzle/eft/service/ValidationService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ch.puzzle.eft.service;

import org.springframework.stereotype.Service;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.stereotype.Service;

@Service
public class ValidationService {
private static final Pattern EXAM_NUMBER_PATTERN = Pattern.compile("^\\d{5}$");
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
spring.application.name=exam-feedback-tool
server.servlet.session.cookie.same-site=strict
server.error.path=redirect:/error

spring.application.version[email protected]@
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ea8bc1e

Please sign in to comment.