fix create paper

pull/149/head
Anton Romanov 6 years ago
parent 67f440ac8a
commit 54bf5735e5

@ -0,0 +1,58 @@
package ru.ulstu.paper.controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.Response;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.service.PaperService;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import static ru.ulstu.paper.controller.PaperRestController.URL;
@RestController
@RequestMapping(URL)
public class PaperRestController {
public static final String URL = Constants.API_1_0 + "papers";
private final PaperService paperService;
public PaperRestController(PaperService paperService) {
this.paperService = paperService;
}
@GetMapping
public Response<List<PaperDto>> getPapers() {
return new Response<>(paperService.findAllDto());
}
@GetMapping("/{paper-id}")
public Response<PaperDto> getPaper(@PathVariable("paper-id") Integer paperId){
return new Response(paperService.findById(paperId));
}
@PostMapping
public Response<Integer> createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
return new Response<>(paperService.create(paperDto));
}
@PutMapping
public Response<Integer> updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
return new Response<>(paperService.update(paperDto));
}
@DeleteMapping("/{paper-id}")
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) throws IOException {
paperService.delete(paperId);
return new Response<>(true);
}
}

@ -42,15 +42,6 @@ public class Paper extends BaseEntity implements UserContainer {
} }
} }
/*public enum PaperStatus {
ATTENTION,
ON_PREPARATION,
ON_REVIEW,
DRAFT,
COMPLETED,
FAILED;
}*/
@NotBlank @NotBlank
private String title; private String title;

@ -158,4 +158,8 @@ public class PaperService {
update(paperDto); update(paperDto);
} }
} }
public PaperDto findById(Integer paperId) {
return new PaperDto(paperRepository.findOne(paperId));
}
} }

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default" xmlns:form="http://www.w3.org/1999/xhtml" xmlns:th="http://www.w3.org/1999/xhtml"> layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml">
<head> <head>
</head> </head>
@ -26,23 +26,27 @@
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<form method="post" th:action="@{'/papers/paper?id='+*{id}}" th:object="${paperDto}"> <form method="post" th:action="@{'/papers/paper?id='+ *{id == null ? '' : id} + ''}"
th:object="${paperDto}">
<div class="row"> <div class="row">
<div class="col-md-6 col-sm-12"> <div class="col-md-6 col-sm-12">
<input type="hidden" name="id" th:field="*{id}"/>
<div class="form-group"> <div class="form-group">
<label for="title">Название:</label> <label for="title">Название:</label>
<input type="hidden" name="id" th:field="*{id}"/>
<input class="form-control" id="title" type="text" <input class="form-control" id="title" type="text"
placeholder="Название статьи" placeholder="Название статьи"
th:field="*{title}"/> th:field="*{title}"/>
<p th:if="${#fields.hasErrors('title')}" th:errors="*{title}" class="alert alert-danger">Incorrect title</p> <p th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
class="alert alert-danger">Incorrect title</p>
<p class="help-block text-danger"></p> <p class="help-block text-danger"></p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="status">Статус:</label> <label for="status">Статус:</label>
<select class="form-control" th:field="*{status}" id="status"> <select class="form-control" th:field="*{status}" id="status">
<option th:each="status : ${allStatuses}" th:value="${status}" th:text="${status.statusName}">Status</option> <option th:each="status : ${allStatuses}" th:value="${status}"
th:text="${status.statusName}">Status
</option>
</select> </select>
</div> </div>
@ -55,7 +59,8 @@
<div class="form-group"> <div class="form-group">
<label>Дедлайн:</label> <label>Дедлайн:</label>
<input type="date" class="form-control" name="deadline" th:field="*{deadlineDate}"/> <input type="date" class="form-control" name="deadline" th:field="*{deadlineDate}"/>
<p th:if="${#fields.hasErrors('deadlineDate')}" th:errors="*{deadlineDate}" class="alert alert-danger">Incorrect title</p> <p th:if="${#fields.hasErrors('deadlineDate')}" th:errors="*{deadlineDate}"
class="alert alert-danger">Incorrect title</p>
</div> </div>
<div class="form-check"> <div class="form-check">
@ -161,9 +166,9 @@
type="submit"> type="submit">
Сохранить Сохранить
</button> </button>
<button id="cancelButton" class="btn btn-default text-uppercase" type="button"> <a id="cancelButton" class="btn btn-default text-uppercase" href="/papers/papers">
Отмена Отмена
</button> </a>
</div> </div>
</div> </div>

Loading…
Cancel
Save