Skip to content

Commit

Permalink
Adding UcdlEditorController and UcdlEditorService (#26)
Browse files Browse the repository at this point in the history
* Adding UcdlEditorController and UcdlEditorService

* Changed PostMapping to PutMapping

* Added JavaDoc

* Update server/src/main/java/de/uftos/controller/UcdlEditorController.java

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>

* Update server/src/main/java/de/uftos/entities/ConstraintArgument.java

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>

* Update server/src/main/java/de/uftos/entities/ConstraintInstance.java

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>

* Update server/src/main/java/de/uftos/entities/ConstraintParameter.java

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>

* Update server/src/main/java/de/uftos/entities/ConstraintSignature.java

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>

* Update server/src/main/java/de/uftos/entities/Curriculum.java

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>

* Update server/src/main/java/de/uftos/entities/LessonsCount.java

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>

---------

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>
  • Loading branch information
marcelfloe and danieldietzler authored Jun 20, 2024
1 parent c6c16ad commit e6caa09
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 1 deletion.
55 changes: 55 additions & 0 deletions server/src/main/java/de/uftos/controller/UcdlEditorController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package de.uftos.controller;

import de.uftos.dto.parser.ParsingResponse;
import de.uftos.services.UcdlEditorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
* The REST controller for the UCDL editor.
* This controller handles /editor HTTP requests.
*/
@RestController
@RequestMapping("/editor")
public class UcdlEditorController {
private final UcdlEditorService editorService;

/**
* Creates an editor controller.
*
* @param editorService the service for the UCDL editor.
*/
@Autowired
public UcdlEditorController(UcdlEditorService editorService) {
this.editorService = editorService;
}

/**
* Maps the HTTP POST request, to set the UCDL code, to the
* {@link UcdlEditorService#setUcdl(MultipartFile)} function of the editor service.
*
* @param file the file which contains the new UCDL code.
* @return a response whether the file could be parsed successfully or not.
*/
@PutMapping()
public ParsingResponse set(@RequestBody MultipartFile file) {
return this.editorService.setUcdl(file);
}

/**
* Maps the HTTP GET request for the current UCDL code, to the
* {@link UcdlEditorService#getUcdl()} function of the editor service.
*
* @return a file containing the current UCDL code.
*/
@GetMapping()
public MultipartFile getUcdl() {
return this.editorService.getUcdl();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import jakarta.persistence.ManyToOne;
import lombok.Data;

/**
* The database table for constraint arguments.
* Contains an ID, the name and value of the argument as well as
* the constraint instance using the argument.
*/
@Entity(name = "constraint_argument")
@Data
public class ConstraintArgument {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import java.util.List;
import lombok.Data;

/**
* The database table for constraint instances.
* Contains an ID, the signature of the corresponding constraint definition, a list of constraint
* arguments as well as the information whether the instance gets hard/soft penalized/rewarded.
*/
@Entity(name = "constraint_instance")
@Data
public class ConstraintInstance {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import jakarta.persistence.ManyToOne;
import lombok.Data;

/**
* The database table for constraint parameters.
* Contains an ID, the name and type of the parameter as well as the constraint signature using it.
*/
@Entity(name = "constraint_parameter")
@Data
public class ConstraintParameter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import java.util.List;
import lombok.Data;

/**
* The database table for constraint signatures.
* Contains an ID, the name of the grade as well as the student groups that in the
* grade as well as the tags associated with it.
*/
@Entity(name = "constraint_signature")
@Data
public class ConstraintSignature {
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/de/uftos/entities/Curriculum.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* The database table for curriculums.
* Contains an ID, a grade to which the lessons are applied to and a list of lesson counts.
*/
@Entity(name = "curriculum")
@Data
@NoArgsConstructor
Expand All @@ -25,6 +29,12 @@ public class Curriculum {
@ManyToMany
private List<LessonsCount> lessonsCounts;

/**
* Creates a new curriculum.
*
* @param grade the grade to which the curriculum applies to.
* @param lessonsCounts the lesson counts which apply to the given grade.
*/
public Curriculum(Grade grade, List<LessonsCount> lessonsCounts) {
this.grade = grade;
this.lessonsCounts = lessonsCounts;
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/de/uftos/entities/Grade.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/**
* The database entity for grades.
* Contains an ID, the name of the grade as well as the student groups that in the
* Contains an ID, the name of the grade as well as the student groups that are in the
* grade as well as the tags associated with it.
*/
@Entity(name = "grades")
Expand Down
4 changes: 4 additions & 0 deletions server/src/main/java/de/uftos/entities/LessonsCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* The database table for lesson counts.
* Contains an ID, the subject it applies to and a count for the amount of lessons.
*/
@Entity(name = "lessons_count")
@Data
@NoArgsConstructor
Expand Down
47 changes: 47 additions & 0 deletions server/src/main/java/de/uftos/services/UcdlEditorService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.uftos.services;

import de.uftos.dto.parser.ParsingResponse;
import de.uftos.repositories.ucdl.UcdlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
* The service for editing the UCDL-File.
*/
@Service
public class UcdlEditorService {
private final UcdlRepository ucdlRepository;

/**
* Creates a UCDL editor service.
*
* @param ucdlRepository the repository for accessing the UCDL parser.
*/
@Autowired
public UcdlEditorService(UcdlRepository ucdlRepository) {
this.ucdlRepository = ucdlRepository;
}

/**
* Sets the UCDL code and attempts to parse it.
*
* @param file the file containing the new UCDL code.
* @return a response whether parsing the file was successful or not.
*/
public ParsingResponse setUcdl(MultipartFile file) {
//todo: set String of repository
return ucdlRepository.parseFile();
}

/**
* Gets the current UCDL file.
*
* @return the current UCDL file.
*/
public MultipartFile getUcdl() {
//todo: return actual file
return null;
}

}

0 comments on commit e6caa09

Please sign in to comment.