#91 -- Add markup page menu item #94

Merged
romanov73 merged 29 commits from 91-markup into master 2023-04-23 23:43:14 +04:00
6 changed files with 50 additions and 5 deletions
Showing only changes of commit 0239b0afd4 - Show all commits

View File

@ -3,10 +3,12 @@ package ru.ulstu.extractor.markup.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; 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.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.MarkupForm;
import ru.ulstu.extractor.markup.model.MarkupRow; 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.model.TimeSeries;
import ru.ulstu.extractor.ts.service.TimeSeriesService; import ru.ulstu.extractor.ts.service.TimeSeriesService;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
@ -18,9 +20,12 @@ import java.util.stream.Collectors;
@ApiIgnore @ApiIgnore
public class TimeSeriesMarkupController { public class TimeSeriesMarkupController {
private final TimeSeriesService timeSeriesService; private final TimeSeriesService timeSeriesService;
private final MarkupService markupService;
public TimeSeriesMarkupController(TimeSeriesService timeSeriesService) { public TimeSeriesMarkupController(TimeSeriesService timeSeriesService,
MarkupService markupService) {
this.timeSeriesService = timeSeriesService; this.timeSeriesService = timeSeriesService;
this.markupService = markupService;
} }
@GetMapping("time-series-markup") @GetMapping("time-series-markup")
@ -30,8 +35,9 @@ public class TimeSeriesMarkupController {
return "markup"; return "markup";
} }
@PostMapping("addMarkups") @PostMapping(Route.ADD_MARKUP)
public String addMarkups(@RequestBody MarkupForm markupForm) { public String addMarkups(@ModelAttribute MarkupForm markupForm) {
markupService.saveMarkup(markupForm);
return "markup"; return "markup";
} }
} }

View File

@ -12,6 +12,14 @@ public class Markup extends BaseEntity {
private TimeSeries timeSeries; private TimeSeries timeSeries;
private String markup; private String markup;
public Markup() {
}
public Markup(MarkupRow markupRow) {
this.timeSeries = markupRow.getTimeSeries();
this.markup = markupRow.getMarkup();
}
public TimeSeries getTimeSeries() { public TimeSeries getTimeSeries() {
return timeSeries; return timeSeries;
} }

View File

@ -12,4 +12,8 @@ public class MarkupForm {
public List<MarkupRow> getMarkupRows() { public List<MarkupRow> getMarkupRows() {
return markupRows; return markupRows;
} }
public void setMarkupRows(List<MarkupRow> markupRows) {
this.markupRows = markupRows;
}
} }

View File

@ -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> {
}

View File

@ -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)));
}
}

View File

@ -7,7 +7,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head> </head>
<div class="container" layout:fragment="content"> <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"> <table class="table table-striped">
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
@ -21,6 +21,7 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<input type="submit" class="btn btn-outline-success w-100" name="next" value="Сохранить"/>
</form> </form>
</div> </div>
</html> </html>