diff --git a/pom.xml b/pom.xml index 6f2a32b..462a721 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,11 @@ spring-boot-starter-data-jpa + + org.springframework.boot + spring-boot-starter-thymeleaf + + org.springframework.security spring-security-oauth2-jose diff --git a/src/main/java/ru/oa2/lti/controller/LoginController.java b/src/main/java/ru/oa2/lti/controller/LoginController.java index 98405c6..82428f0 100644 --- a/src/main/java/ru/oa2/lti/controller/LoginController.java +++ b/src/main/java/ru/oa2/lti/controller/LoginController.java @@ -1,13 +1,15 @@ package ru.oa2.lti.controller; -import jakarta.servlet.ServletRequest; import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; import ru.oa2.lti.ApplicationService; import ru.oa2.lti.model.LtiLogin; @Slf4j -@RestController +@Controller @RequestMapping("/tool/lti") public class LoginController { @@ -18,14 +20,14 @@ public class LoginController { } @PostMapping("/login") - public String login( - @RequestParam("client_id") String clientId, - @RequestParam("iss") String iss, - @RequestParam("login_hint") String loginHint, - @RequestParam("lti_deployment_id") String ltiDeploymentId, - @RequestParam("lti_message_hint") String ltiMessageHint, - @RequestParam("target_link_uri") String targetLinkUri, - ServletRequest servletRequest) { + public String login(@RequestParam("client_id") String clientId, + @RequestParam("iss") String iss, + @RequestParam("login_hint") String loginHint, + @RequestParam("lti_deployment_id") String ltiDeploymentId, + @RequestParam("lti_message_hint") String ltiMessageHint, + @RequestParam("target_link_uri") String targetLinkUri, + RedirectAttributes redirectAttributes) { + var ltiLogin = LtiLogin.builder() .clientId(clientId) .iss(iss) @@ -37,6 +39,51 @@ public class LoginController { log.info("BODY: {}", ltiLogin); - return service.getTask(ltiLogin); + var data = service.getTask(ltiLogin); + redirectAttributes.addFlashAttribute("description", data); + redirectAttributes.addFlashAttribute("codeTitle", "Dockerfile:"); + redirectAttributes.addFlashAttribute("inputCode", "FROM maven:3.9.9-eclipse-temurin-21-jammy AS build\n" + + "\n" + + "COPY . /build\n" + + "WORKDIR /build\n" + + "\n" + + "RUN --mount=type=cache,target=/root/.m2/repository,rw \\\n" + + "\tmvn clean package -DskipTests -B\n" + + "\n" + + "FROM eclipse-temurin:21-jdk AS extract\n" + + "\n" + + "COPY --from=build /build/target/lti-provider-*.jar app.jar\n" + + "RUN java -Djarmode=tools -jar app.jar extract --layers --destination extracted\n" + + "\n" + + "FROM eclipse-temurin:21-jre\n" + + "\n" + + "LABEL org.opencontainers.image.title=\"LTI Provider\"\n" + + "LABEL org.opencontainers.image.description=\"LTI провайдер для лабораторных по Docker и Kubernetes\"\n" + + "LABEL org.opencontainers.image.url=\"TODO\"\n" + + "LABEL org.opencontainers.image.source=\"TODO\"\n" + + "LABEL org.opencontainers.image.documentation=\"#TODO\"\n" + + "\n" + + "WORKDIR /opt\n" + + "\n" + + "COPY --from=extract extracted/dependencies/ ./\n" + + "COPY --from=extract extracted/spring-boot-loader/ ./\n" + + "COPY --from=extract extracted/snapshot-dependencies/ ./\n" + + "COPY --from=extract extracted/application/ ./\n" + + "\n" + + "ENV TZ=\"Europe/Moscow\"\n" + + "ENV JAVA_TOOL_OPTIONS=\"-Xmx1g -Xms1g\"\n" + + "\n" + + "ENTRYPOINT [\"java\", \"-jar\", \"/opt/app.jar\"]"); + + return "redirect:/tool/lti/docker-task"; + } + + @GetMapping("/docker-task") + public String showDockerTas(Model model) { + + if (!model.containsAttribute("description")) { + return "redirect:/error"; + } + return "docker-task"; } } diff --git a/src/main/java/ru/oa2/lti/controller/ResultController.java b/src/main/java/ru/oa2/lti/controller/ResultController.java new file mode 100644 index 0000000..da3f7cc --- /dev/null +++ b/src/main/java/ru/oa2/lti/controller/ResultController.java @@ -0,0 +1,32 @@ +package ru.oa2.lti.controller; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +@RequestMapping("/tool/result") +public class ResultController { + + @PostMapping("/docker") + public String result(@RequestBody String body) { + + log.info("RESULT: {}", body); + + //TODO + return "{\n" + + " \"success\": true,\n" + + " \"message\": \"Результат успешно получен и обработан\",\n" + + " \"data\": {\n" + + " \"contextId\": \"ctx-12345\",\n" + + " \"participantId\": \"usr-67890\",\n" + + " \"submittedText\": \"console.log('Hello');\",\n" + + " \"timestamp\": \"2025-12-14T17:55:30Z\",\n" + + " \"status\": \"processed\"\n" + + " }\n" + + "}"; + } +} diff --git a/src/main/resources/templates/docker-task.html b/src/main/resources/templates/docker-task.html new file mode 100644 index 0000000..0f03096 --- /dev/null +++ b/src/main/resources/templates/docker-task.html @@ -0,0 +1,188 @@ + + + + + + + + + +
+
+ + +
+

Условие задачи

+
+
+
+ + +
+ +
+

Введите решение

+
+
+ +
+ +
+
+ + +
+

Результат выполнения

+
+
Вывод программы:
+
+ + Результат выполнения появится здесь... +
+
+ +
+
+
+
+
+
+ + + + + + + \ No newline at end of file