esoe
3 days ago
37 changed files with 341 additions and 75 deletions
@ -1,9 +1,9 @@ |
|||||||
package gsp.technologies.main.api.account; |
package gsp.technologies.main.core.account; |
||||||
|
|
||||||
import org.hibernate.annotations.OnDelete; |
import org.hibernate.annotations.OnDelete; |
||||||
import org.hibernate.annotations.OnDeleteAction; |
import org.hibernate.annotations.OnDeleteAction; |
||||||
|
|
||||||
import gsp.technologies.main.api.position.PositionEntity; |
import gsp.technologies.main.core.position.PositionEntity; |
||||||
import jakarta.persistence.Entity; |
import jakarta.persistence.Entity; |
||||||
import jakarta.persistence.FetchType; |
import jakarta.persistence.FetchType; |
||||||
import jakarta.persistence.GeneratedValue; |
import jakarta.persistence.GeneratedValue; |
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.account; |
package gsp.technologies.main.core.account; |
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository; |
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
import org.springframework.stereotype.Repository; |
import org.springframework.stereotype.Repository; |
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.account; |
package gsp.technologies.main.core.account; |
||||||
|
|
||||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
||||||
|
|
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.course; |
package gsp.technologies.main.core.course; |
||||||
|
|
||||||
import jakarta.persistence.Entity; |
import jakarta.persistence.Entity; |
||||||
import jakarta.persistence.GeneratedValue; |
import jakarta.persistence.GeneratedValue; |
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.course; |
package gsp.technologies.main.core.course; |
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository; |
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
import org.springframework.stereotype.Repository; |
import org.springframework.stereotype.Repository; |
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.course; |
package gsp.technologies.main.core.course; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
|
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.organization; |
package gsp.technologies.main.core.organization; |
||||||
|
|
||||||
import jakarta.persistence.Column; |
import jakarta.persistence.Column; |
||||||
import jakarta.persistence.Entity; |
import jakarta.persistence.Entity; |
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.organization; |
package gsp.technologies.main.core.organization; |
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository; |
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
import org.springframework.stereotype.Repository; |
import org.springframework.stereotype.Repository; |
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.organization; |
package gsp.technologies.main.core.organization; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
|
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.position; |
package gsp.technologies.main.core.position; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
|
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.position; |
package gsp.technologies.main.core.position; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
|
@ -0,0 +1,35 @@ |
|||||||
|
package gsp.technologies.main.core.question; |
||||||
|
|
||||||
|
import org.hibernate.annotations.OnDelete; |
||||||
|
import org.hibernate.annotations.OnDeleteAction; |
||||||
|
|
||||||
|
import gsp.technologies.main.core.course.CourseEntity; |
||||||
|
import gsp.technologies.main.core.organization.OrganizationEntity; |
||||||
|
import jakarta.persistence.Entity; |
||||||
|
import jakarta.persistence.FetchType; |
||||||
|
import jakarta.persistence.GeneratedValue; |
||||||
|
import jakarta.persistence.GenerationType; |
||||||
|
import jakarta.persistence.Id; |
||||||
|
import jakarta.persistence.JoinColumn; |
||||||
|
import jakarta.persistence.ManyToOne; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
|
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@Builder |
||||||
|
@Entity |
||||||
|
public class QuestionEntity { |
||||||
|
@Id |
||||||
|
@GeneratedValue(strategy=GenerationType.AUTO) |
||||||
|
private Long id; |
||||||
|
private String body; |
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER, optional = false) |
||||||
|
@JoinColumn(name = "course", referencedColumnName = "id") |
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE) |
||||||
|
private CourseEntity course; |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
package gsp.technologies.main.core.question; |
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface QuestionRepository extends JpaRepository<QuestionEntity, Long> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
package gsp.technologies.main.core.question; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class QuestionService { |
||||||
|
private final QuestionRepository repo; |
||||||
|
|
||||||
|
public QuestionService(QuestionRepository repo) { |
||||||
|
this.repo = repo; |
||||||
|
} |
||||||
|
|
||||||
|
public Collection<QuestionEntity> findAll() { |
||||||
|
return repo.findAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public QuestionEntity save(QuestionEntity entity) { |
||||||
|
return repo.save(entity); |
||||||
|
} |
||||||
|
|
||||||
|
public void delete(Long id) { |
||||||
|
repo.deleteById(id); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,10 +1,10 @@ |
|||||||
package gsp.technologies.main.api.target; |
package gsp.technologies.main.core.target; |
||||||
|
|
||||||
import org.hibernate.annotations.OnDelete; |
import org.hibernate.annotations.OnDelete; |
||||||
import org.hibernate.annotations.OnDeleteAction; |
import org.hibernate.annotations.OnDeleteAction; |
||||||
|
|
||||||
import gsp.technologies.main.api.course.CourseEntity; |
import gsp.technologies.main.core.course.CourseEntity; |
||||||
import gsp.technologies.main.api.position.PositionEntity; |
import gsp.technologies.main.core.position.PositionEntity; |
||||||
import jakarta.persistence.Entity; |
import jakarta.persistence.Entity; |
||||||
import jakarta.persistence.FetchType; |
import jakarta.persistence.FetchType; |
||||||
import jakarta.persistence.GeneratedValue; |
import jakarta.persistence.GeneratedValue; |
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.target; |
package gsp.technologies.main.core.target; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
|
@ -1,4 +1,4 @@ |
|||||||
package gsp.technologies.main.api.target; |
package gsp.technologies.main.core.target; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
|
@ -0,0 +1,73 @@ |
|||||||
|
package gsp.technologies.main.face.supplier; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.ui.Model; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
|
||||||
|
import gsp.technologies.main.core.course.CourseService; |
||||||
|
import gsp.technologies.main.core.question.QuestionEntity; |
||||||
|
import gsp.technologies.main.core.question.QuestionService; |
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
|
||||||
|
@Controller |
||||||
|
@RequestMapping(path = "/supplier") |
||||||
|
public class SupQuestionController { |
||||||
|
private static final Logger log = LoggerFactory.getLogger(SupQuestionController.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private QuestionService questionService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private CourseService courseService; |
||||||
|
|
||||||
|
public SupQuestionController(QuestionService questionService, CourseService courseService) { |
||||||
|
this.questionService = questionService; |
||||||
|
this.courseService = courseService; |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/questions") |
||||||
|
public String questions(Model model) { |
||||||
|
log.info("GET /supplier/questions"); |
||||||
|
|
||||||
|
//добавляем в модель перечень курсов
|
||||||
|
model.addAttribute("courses", courseService.findAll()); |
||||||
|
|
||||||
|
//добавляем в модель список вопросов
|
||||||
|
model.addAttribute("questions", questionService.findAll()); |
||||||
|
|
||||||
|
return "pages/supplier/questions"; |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("/questions") |
||||||
|
public String createQuestion( |
||||||
|
@RequestParam(name = "question-body", required = true) String body, |
||||||
|
@RequestParam(name = "courseid", required = true) String courseid |
||||||
|
) { |
||||||
|
log.info("POST /supplier/questions"); |
||||||
|
|
||||||
|
QuestionEntity entity = QuestionEntity.builder() |
||||||
|
.body(body) |
||||||
|
.course(courseService.findById(Long.parseLong(courseid))) |
||||||
|
.build(); |
||||||
|
|
||||||
|
questionService.save(entity); |
||||||
|
|
||||||
|
return "redirect:/supplier/questions"; |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/questions/{id}/delete") |
||||||
|
public String deleteQuestion(@PathVariable Long id) { |
||||||
|
log.info("GET /supplier/questions/{id}/delete"); |
||||||
|
questionService.delete(id); |
||||||
|
return "redirect:/supplier/questions"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,2 +1,4 @@ |
|||||||
# Пояснения для пользователей |
# Учебрый центр ООО "ГСП-Технологии" |
||||||
|
## Допуск на строительную площадку |
||||||
|
|
||||||
- Запомни номер своей учетной записи!!! |
- Запомни номер своей учетной записи!!! |
@ -0,0 +1,27 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" |
||||||
|
xmlns:th="http://www.thymeleaf.org"> |
||||||
|
<head> |
||||||
|
<meta charset="UTF-8"> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||||
|
<title>exam-questions</title> |
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||||
|
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> |
||||||
|
</head> |
||||||
|
<header> |
||||||
|
<!-- Кнопки навигации --> |
||||||
|
<div th:insert="~{shards/navi :: supplier}"></div> |
||||||
|
</header> |
||||||
|
|
||||||
|
<body> |
||||||
|
<h1>Вопросы</h1> |
||||||
|
<!-- Давление нового вопроса --> |
||||||
|
<div th:insert="~{shards/questions :: create(courses=${courses})}"></div> |
||||||
|
<!-- Перечень вопросов --> |
||||||
|
<div th:insert="~{shards/questions :: list(questions=${questions})}"></div> |
||||||
|
</body> |
||||||
|
|
||||||
|
<footer> |
||||||
|
<div th:insert="~{shards/footer :: copy}"></div> |
||||||
|
</footer> |
||||||
|
</html> |
@ -0,0 +1,65 @@ |
|||||||
|
<!-- Коллекция фрагментов для построения страницы организаций --> |
||||||
|
<!DOCTYPE html> |
||||||
|
<html xmlns:th="http://www.thymeleaf.org"> |
||||||
|
|
||||||
|
<body> |
||||||
|
<!-- Перечень организаций --> |
||||||
|
<div th:fragment="list(questions)"> |
||||||
|
<hr> |
||||||
|
<h2>Список вопросов:</h2> |
||||||
|
<table> |
||||||
|
<thead> |
||||||
|
<tr> |
||||||
|
<th>Название курса</th> |
||||||
|
<th>Содержание вопроса</th> |
||||||
|
<th>Действия</th> |
||||||
|
<th>Ответы</th> |
||||||
|
</tr> |
||||||
|
</thead> |
||||||
|
<tbody> |
||||||
|
<tr th:each="question : ${questions}"> |
||||||
|
<td th:text="${question.course.name}"></td> |
||||||
|
<td th:text="${question.body}"></td> |
||||||
|
<td> |
||||||
|
<a th:href="@{/supplier/questions/{id}/delete(id=${question.id})}">Удалить вопрос</a> |
||||||
|
<a th:href="@{/supplier/answers/{id}(id=${question.id})}">Добавить ответ</a> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</tbody> |
||||||
|
</table> |
||||||
|
</div> |
||||||
|
|
||||||
|
<!-- Добавление нового вопроса --> |
||||||
|
<div th:fragment="create(courses)"> |
||||||
|
<hr> |
||||||
|
|
||||||
|
<h2>Добавление нового вопроса:</h2> |
||||||
|
<form th:action="@{/supplier/questions}" th:method="post"> |
||||||
|
<!-- селект курса --> |
||||||
|
<label for="course-select">Выберите курс</label> |
||||||
|
<select id="course-select" name="courseid"> |
||||||
|
<option value="0" disabled selected>курс</option> |
||||||
|
<option th:each="option : ${courses}" th:value="${option.id}" th:text="${option.name}"></option> |
||||||
|
</select> |
||||||
|
<br> |
||||||
|
<label for="questions-body">Содержание вопроса: </label> |
||||||
|
<br> |
||||||
|
<textarea rows="5" cols="33" id="question-body" name="question-body" placeholder="введите вопрос тут..." required></textarea> |
||||||
|
<br> |
||||||
|
<input type="submit" value="Добавить"> |
||||||
|
</form> |
||||||
|
</div> |
||||||
|
|
||||||
|
<!-- Редактирование организации --> |
||||||
|
<!-- <div th:fragment="edit(organization)"> |
||||||
|
<hr> |
||||||
|
<h2>Редактирование организации: <span th:text="${organization.name}"></span></h2> |
||||||
|
<form th:action="@{/supplier/organizations/{id}/edit(id=${organization.id})}" th:method="post"> |
||||||
|
<label for="name" >Название организации: </label> |
||||||
|
<input type="text" th:name="name" th:value="${organization.name}"> |
||||||
|
<br> |
||||||
|
<input type="submit" value="Сохранить"> |
||||||
|
</form> |
||||||
|
</div> --> |
||||||
|
</body> |
||||||
|
</html> |
Loading…
Reference in new issue