Class FileUploadController

java.lang.Object
com.markvarga21.studentmanager.controller.FileUploadController

@RestController @CrossOrigin @RequestMapping("/api/v1/files") public class FileUploadController extends Object
A controller class which is used to manipulate the student's images in the database.
  • Constructor Details

    • FileUploadController

      public FileUploadController()
  • Method Details

    • getAllImages

      @GetMapping @PreAuthorize("hasRole(\'ROLE_ADMIN\')") public org.springframework.data.domain.Page<StudentImage> getAllImages(@RequestParam(defaultValue="0") Integer page, @RequestParam(defaultValue="10") Integer size)
      Fetches all the images from the database.
      Parameters:
      page - The page number.
      size - The number of elements in a single page.
      Returns:
      A page containing the student's images.
    • deleteImage

      @DeleteMapping("/{studentId}") @PreAuthorize("hasRole(\'ROLE_ADMIN\')") public org.springframework.http.ResponseEntity<String> deleteImage(@PathVariable("studentId") Long studentId)
      Deletes the student's passport- and portrait image from the database using their id's.
      Parameters:
      studentId - The id of the student.
      Returns:
      A message which indicates whether the deletion was successful or not.
    • getImageForType

      @GetMapping("/{studentId}") @PreAuthorize("hasRole(\'ROLE_USER\')") public org.springframework.http.ResponseEntity<byte[]> getImageForType(@PathVariable("studentId") Long studentId, StudentImageType imageType)
      Retrieves a single image of the give type for a student identified by it's id.
      Parameters:
      studentId - The id of the student.
      imageType - The type of the image, portrait or passport.
      Returns:
      The student's image of the specified type.
    • uploadImage

      @PostMapping("/upload/{studentId}") @PreAuthorize("hasRole(\'ROLE_USER\')") public org.springframework.http.ResponseEntity<String> uploadImage(@PathVariable("studentId") Long studentId, @RequestParam("passport") org.springframework.web.multipart.MultipartFile passport, @RequestParam("selfie") org.springframework.web.multipart.MultipartFile selfie)
      Uploads both images for the given student identified by their id.
      Parameters:
      studentId - The id of the student.
      passport - The passport image.
      selfie - The selfie image.
      Returns:
      A response entity.
    • changeImage

      @PostMapping("/changeImage/{studentId}/{imageType}") @PreAuthorize("hasRole(\'ROLE_USER\')") public org.springframework.http.ResponseEntity<String> changeImage(@PathVariable("studentId") Long studentId, @PathVariable("imageType") StudentImageType imageType, @RequestParam("file") org.springframework.web.multipart.MultipartFile file)
      Modifies the given type of image of the student.
      Parameters:
      studentId - The id of the student.
      imageType - The type of image.
      file - The file to be changed.
      Returns:
      A response entity.
    • getImagesForStudentId

      @GetMapping("/combined/{studentId}") @PreAuthorize("hasRole(\'ROLE_USER\')") public org.springframework.http.ResponseEntity<StudentImage> getImagesForStudentId(@PathVariable Long studentId)
      Fetches both the pictures of the student by their id.
      Parameters:
      studentId - The id of the student.
      Returns:
      The images for the specified student id.