From 8ef1540ff533cbb3b0b41712eaaf8073ae190b60 Mon Sep 17 00:00:00 2001 From: AlexE030 Date: Tue, 16 May 2023 00:32:55 +0200 Subject: [PATCH] added Module Prototype --- .../example/backend/anwprj/Module/Module.java | 25 ++++++++ .../anwprj/controller/ModuleController.java | 62 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 backend/src/main/java/com/example/backend/anwprj/Module/Module.java create mode 100644 backend/src/main/java/com/example/backend/anwprj/controller/ModuleController.java diff --git a/backend/src/main/java/com/example/backend/anwprj/Module/Module.java b/backend/src/main/java/com/example/backend/anwprj/Module/Module.java new file mode 100644 index 0000000..83388a9 --- /dev/null +++ b/backend/src/main/java/com/example/backend/anwprj/Module/Module.java @@ -0,0 +1,25 @@ +package com.example.backend.anwprj.Module; + +//module data class +public class Module { + private final int id; + private final int lecturerId; + private final int semesterId; + private final String name; + + public Module(int id, int userId, int semesterId, String name){ + this.id = id; + this.lecturerId = userId; + this.semesterId = semesterId; + this.name = name; + } + + public int getId() { return id; } + + public int getLecturerId() { return lecturerId; } + + public int getSemesterId() { return semesterId; } + + public String getName() { return name; } + +} diff --git a/backend/src/main/java/com/example/backend/anwprj/controller/ModuleController.java b/backend/src/main/java/com/example/backend/anwprj/controller/ModuleController.java new file mode 100644 index 0000000..1a6f4e0 --- /dev/null +++ b/backend/src/main/java/com/example/backend/anwprj/controller/ModuleController.java @@ -0,0 +1,62 @@ +package com.example.backend.anwprj.controller; + +import com.example.backend.anwprj.DataBaseHandler; +import com.example.backend.anwprj.Module.Module; +import com.example.backend.anwprj.Users.User; +import com.example.backend.anwprj.Users.UserSessionIDHandler; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ModuleController { + private final DataBaseHandler db; + + { + db = DataBaseHandler.getInstance(); + } + + @CrossOrigin + @GetMapping("placeholder") + public ResponseEntity getModule( + @RequestParam(name="id") int id, + @RequestParam(name="sessionid") String sessionID) { + + User user = UserSessionIDHandler.getUserBySessionID(sessionID); + + if (user != null){ + Module module = db.getModule(id); + if(module != null) { + return new ResponseEntity<>(module, HttpStatus.OK); + } + + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + return new ResponseEntity<>(HttpStatus.FORBIDDEN); + } + + @CrossOrigin + @GetMapping("placeholder") + public ResponseEntity getModule( + @RequestParam(name="name") String name, + @RequestParam(name="sessionid") String sessionID) { + + User user = UserSessionIDHandler.getUserBySessionID(sessionID); + + if(user != null) + { + Module module = db.getModule(name); + if (module != null) { + return new ResponseEntity<>(module, HttpStatus.OK); + } + + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + return new ResponseEntity<>(HttpStatus.FORBIDDEN); + } +}