added Module Prototype
This commit is contained in:
@@ -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; }
|
||||
|
||||
}
|
||||
@@ -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<Module> 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<Module> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user