Added Controller + Model placeholders for Modul, Dozent, Klausur

This commit is contained in:
Luedtke 2021-07-09 18:50:08 +02:00
parent 2b49181052
commit 35af40ca0e
7 changed files with 145 additions and 10 deletions

View File

@ -0,0 +1,37 @@
package de.fswiai.klausurenmodul.controller;
import de.fswiai.klausurenmodul.model.Dozent;
import de.fswiai.klausurenmodul.model.Modul;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
public class DozentController {
@GetMapping("/dozent")
public List<Dozent> getDozentList(){
List<Dozent> retList = new ArrayList<>();
//TODO IMPLEMENT
return retList;
}
@GetMapping("/dozent/{id}")
public Dozent getDozentByID(@PathVariable String id){
//TODO Search for dozent in DB and return it
return new Dozent();
}
@PostMapping("/dozent")
public Dozent persistDozent(@RequestParam(name = "dozent") Dozent pDozent){
//TODO IMPLEMENT
return new Dozent();
}
@DeleteMapping("/dozent/{id}")
public void deleteDozentByID(@PathVariable String id){
//TODO IMPLEMENT - SEARCH; IF EXISTS DELETE
// -> Should the modules be deleted as well? I'd argue: No.
}
}

View File

@ -0,0 +1,34 @@
package de.fswiai.klausurenmodul.controller;
import de.fswiai.klausurenmodul.model.Klausur;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
public class KlausurController {
@GetMapping("/klausur")
public List<Klausur> getKlausurList(){
List<Klausur> retList = new ArrayList<>();
//TODO IMPLEMENT
return retList;
}
@GetMapping("/klausur/{id}")
public Klausur getKlausurByID(@PathVariable String id){
//TODO Search for Klausur in DB and return it
return new Klausur();
}
@PostMapping("/klausur")
public Klausur persistDozent(@RequestParam(name = "Klausur") Klausur pKlausur){
//TODO IMPLEMENT
return new Klausur();
}
@DeleteMapping("/Klausur/{id}")
public void deleteKlausurByID(@PathVariable String id){
//TODO IMPLEMENT - SEARCH; IF EXISTS DELETE
}
}

View File

@ -0,0 +1,35 @@
package de.fswiai.klausurenmodul.controller;
import de.fswiai.klausurenmodul.model.Modul;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
public class ModulController {
@GetMapping("/modul")
public List<Modul> getModuleList(){
List<Modul> retList = new ArrayList<>();
//TODO IMPLEMENT
return retList;
}
@GetMapping("/modul/{id}")
public Modul getModuleByID(@PathVariable String id){
//TODO Search for module in DB and return it
return new Modul();
}
@PostMapping("/modul")
public Modul persistModul(@RequestParam(name = "modul") Modul pModul){
//TODO IMPLEMENT
return new Modul();
}
@DeleteMapping("/modul/{id}")
public void deleteModuleByID(@PathVariable String id){
//TODO IMPLEMENT - SEARCH; IF EXISTS DELETE
}
}

View File

@ -0,0 +1,11 @@
package de.fswiai.klausurenmodul.model;
import java.util.List;
public class Dozent {
//ID required, ID Format? -> have to check the db
private long id;
private String firstname;
private String lastname;
private List<Modul> module;
}

View File

@ -0,0 +1,11 @@
package de.fswiai.klausurenmodul.model;
public class Klausur {
//ID required, ID Format? -> have to check the db
private String shortname;
private String longname;
private String filepath; // Should this just be the same as longname?
private String link; // Or should we handle links differently?
//May need a 'semester' field, not sure. Have to check db again.
}

View File

@ -0,0 +1,12 @@
package de.fswiai.klausurenmodul.model;
import java.util.List;
public class Modul {
private long id;
private String shortname;
private String longname;
private List<Klausur> klausuren;
// TODO gibt es eine geeignete nicht-genderndeForm? Wäre dann vorzuziehen.
private Dozent dozent;
}

View File

@ -4,14 +4,9 @@ import de.fswiai.klausurenmodul.model.Email;
import de.fswiai.klausurenmodul.model.MailerConfig; import de.fswiai.klausurenmodul.model.MailerConfig;
import javax.mail.*; import javax.mail.*;
import javax.mail.internet.InternetAddress; import javax.mail.internet.*;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -44,7 +39,7 @@ public class MailService {
//TODO switch boolean to some result class //TODO switch boolean to some result class
//TODO switch to a proper logging framework //TODO switch to a proper logging framework
public boolean sendMail(Email mail) public boolean sendMail(Email mail)
throws javax.mail.internet.AddressException, javax.mail.MessagingException throws AddressException, MessagingException
{ {
System.out.println("- Attempting to send Mail:"); System.out.println("- Attempting to send Mail:");
System.out.println(" From: " + mail.getSourceAddress()); System.out.println(" From: " + mail.getSourceAddress());
@ -63,8 +58,8 @@ public class MailService {
// If the Email Object contains files to append, then append them. // If the Email Object contains files to append, then append them.
if(mail.hasFiles()){ if(mail.hasFiles()){
// Add the files to append // I'd prefer a lambda, but ran into some issues with capturing stuff.
mail.getFileList().forEach(file -> { for (File file: mail.getFileList()) {
try { try {
MimeBodyPart attachmentBodyPart = new MimeBodyPart(); MimeBodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.attachFile(file); attachmentBodyPart.attachFile(file);
@ -76,7 +71,7 @@ public class MailService {
System.err.println("File Attachment Message Exception"); System.err.println("File Attachment Message Exception");
e.printStackTrace(); e.printStackTrace();
} }
}); }
} }
// Set the prepared Mime Multipart as the message content // Set the prepared Mime Multipart as the message content