#91 -- Add save operation
This commit is contained in:
parent
0883c5193b
commit
0239b0afd4
@ -3,10 +3,12 @@ package ru.ulstu.extractor.markup.controller;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import ru.ulstu.extractor.core.Route;
|
||||
import ru.ulstu.extractor.markup.model.MarkupForm;
|
||||
import ru.ulstu.extractor.markup.model.MarkupRow;
|
||||
import ru.ulstu.extractor.markup.service.MarkupService;
|
||||
import ru.ulstu.extractor.ts.model.TimeSeries;
|
||||
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
@ -18,9 +20,12 @@ import java.util.stream.Collectors;
|
||||
@ApiIgnore
|
||||
public class TimeSeriesMarkupController {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
private final MarkupService markupService;
|
||||
|
||||
public TimeSeriesMarkupController(TimeSeriesService timeSeriesService) {
|
||||
public TimeSeriesMarkupController(TimeSeriesService timeSeriesService,
|
||||
MarkupService markupService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.markupService = markupService;
|
||||
}
|
||||
|
||||
@GetMapping("time-series-markup")
|
||||
@ -30,8 +35,9 @@ public class TimeSeriesMarkupController {
|
||||
return "markup";
|
||||
}
|
||||
|
||||
@PostMapping("addMarkups")
|
||||
public String addMarkups(@RequestBody MarkupForm markupForm) {
|
||||
@PostMapping(Route.ADD_MARKUP)
|
||||
public String addMarkups(@ModelAttribute MarkupForm markupForm) {
|
||||
markupService.saveMarkup(markupForm);
|
||||
return "markup";
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,14 @@ public class Markup extends BaseEntity {
|
||||
private TimeSeries timeSeries;
|
||||
private String markup;
|
||||
|
||||
public Markup() {
|
||||
}
|
||||
|
||||
public Markup(MarkupRow markupRow) {
|
||||
this.timeSeries = markupRow.getTimeSeries();
|
||||
this.markup = markupRow.getMarkup();
|
||||
}
|
||||
|
||||
public TimeSeries getTimeSeries() {
|
||||
return timeSeries;
|
||||
}
|
||||
|
@ -12,4 +12,8 @@ public class MarkupForm {
|
||||
public List<MarkupRow> getMarkupRows() {
|
||||
return markupRows;
|
||||
}
|
||||
|
||||
public void setMarkupRows(List<MarkupRow> markupRows) {
|
||||
this.markupRows = markupRows;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package ru.ulstu.extractor.markup.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulstu.extractor.markup.model.Markup;
|
||||
|
||||
public interface MarkupRepository extends JpaRepository<Markup, Integer> {
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package ru.ulstu.extractor.markup.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.markup.model.Markup;
|
||||
import ru.ulstu.extractor.markup.model.MarkupForm;
|
||||
import ru.ulstu.extractor.markup.repository.MarkupRepository;
|
||||
|
||||
@Service
|
||||
public class MarkupService {
|
||||
private final MarkupRepository markupRepository;
|
||||
|
||||
public MarkupService(MarkupRepository markupRepository) {
|
||||
this.markupRepository = markupRepository;
|
||||
}
|
||||
|
||||
public void saveMarkup(MarkupForm markupForm) {
|
||||
markupForm.getMarkupRows().forEach(markupRow -> markupRepository.save(new Markup(markupRow)));
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
</head>
|
||||
<div class="container" layout:fragment="content">
|
||||
<form th:action="${@route.ADD_MARKUP}">
|
||||
<form th:action="${@route.ADD_MARKUP}" method="post">
|
||||
<table class="table table-striped">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
@ -21,6 +21,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="submit" class="btn btn-outline-success w-100" name="next" value="Сохранить"/>
|
||||
</form>
|
||||
</div>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user