This commit is contained in:
unknown 2020-05-08 09:16:30 +02:00
parent 3a861f03c3
commit 6233af8e11
4 changed files with 91 additions and 2 deletions

View File

@ -0,0 +1,42 @@
package com.wmi.lti.controllers;
import com.wmi.lti.model.grade.Grade;
import com.wmi.lti.model.grade.GradeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;
import java.util.Scanner;
@RequestMapping("/grades")
@RestController
public class GradeController {
@Autowired
private GradeRepository gradeRepository;
@PostMapping("")
public String addCourse(@RequestParam(required = false) Map<String, String> args, HttpServletRequest request) throws IOException {
Grade grade = new Grade();
grade.setDescription(extractPostRequestBody(request));
System.out.println(grade.getDescription());
gradeRepository.save(grade);
return "done";
}
static String extractPostRequestBody(HttpServletRequest request) throws IOException {
if ("POST".equalsIgnoreCase(request.getMethod())) {
Scanner s = new Scanner(request.getInputStream(), "UTF-8").useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
return "";
}
}

View File

@ -0,0 +1,41 @@
package com.wmi.lti.model.grade;
import com.wmi.lti.model.course.Course;
import com.wmi.lti.model.user.User;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.*;
@Entity
@AllArgsConstructor
@NoArgsConstructor
public class Grade {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Getter
@Setter
private Long id;
@Getter
@Setter
@ManyToOne
private Course course;
@Getter
@Setter
@ManyToOne
private User user;
@Getter
@Setter
private Double grade;
@Getter
@Setter
private String description;
}

View File

@ -0,0 +1,6 @@
package com.wmi.lti.model.grade;
import org.springframework.data.jpa.repository.JpaRepository;
public interface GradeRepository extends JpaRepository<Grade, Long> {
}

View File

@ -11,11 +11,11 @@
<body>
<tr th:each="course: ${courses}">
<form th:action="${course.url}" method="POST">
<form target = "_blank" th:action="${course.url}" method="POST">
<th:block th:each="parameter : ${course.signedParameters}">
<input type="hidden" th:name="${parameter.key}" th:value="${parameter.value}" />
</th:block>
<input type="submit">Launch Tool</input>
<input th:value="${course.name}" type="submit"/>
</form>
</tr>