Skip to content
Snippets Groups Projects

Allow admins to upload room images

32 files
+ 393
64
Compare changes
  • Side-by-side
  • Inline

Files

@@ -17,6 +17,7 @@
*/
package nl.tudelft.queue.controller;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
@@ -30,10 +31,12 @@ import nl.tudelft.labracore.api.dto.CourseCreateDTO;
import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.queue.cache.EditionCacheManager;
import nl.tudelft.queue.cache.RoomCacheManager;
import nl.tudelft.queue.cache.SessionCacheManager;
import nl.tudelft.queue.dto.create.QueueCourseCreateDTO;
import nl.tudelft.queue.model.labs.Lab;
import nl.tudelft.queue.repository.LabRepository;
import nl.tudelft.queue.service.AdminService;
import nl.tudelft.queue.service.LabService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,6 +48,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
@Controller
@PreAuthorize("@permissionService.isAdmin()")
@@ -73,6 +77,12 @@ public class AdminController {
@Autowired
private SessionCacheManager sCache;
@Autowired
private AdminService adminService;
@Autowired
private RoomCacheManager rCache;
/**
* Adds a model attribute to every template resolution for recognizing the type of page we are in. For
* this controller all pages will be in the "admin"-area.
@@ -179,6 +189,36 @@ public class AdminController {
return "redirect:/admin";
}
/**
* Gets a list of all currently available rooms.
*
* @param model The model to fill out for Thymeleaf template resolution.
* @return The thymeleaf template to resolve.
*/
@GetMapping("/rooms")
public String getAllRooms(Model model) {
model.addAttribute("rooms", rCache.getAll());
return "admin/view/rooms";
}
/**
* Saves a room image for a specific room
*
* @param id The id of the room for which to save the image
* @param map The file to be saved for this rooom
* @return A redirect to the admin page
* @throws IOException
*/
@PostMapping("/room/{id}")
public String saveRoomImage(@PathVariable("id") Long id,
@RequestParam("map") MultipartFile map) throws IOException {
var extension = map.getOriginalFilename().split("\\.")[map.getOriginalFilename().split("\\.").length
- 1];
String fileName = "room-" + id + "." + extension;
adminService.uploadFile(map, fileName);
return "redirect:/admin";
}
/**
* Gets the number of ongoing sessions for the admin user to see.
*
Loading