add rest controller
This commit is contained in:
parent
e8db1102e6
commit
265bf8b275
@ -31,5 +31,6 @@ dependencies {
|
|||||||
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
|
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
|
||||||
implementation group: 'javassist', name: 'javassist', version: '3.12.1.GA'
|
implementation group: 'javassist', name: 'javassist', version: '3.12.1.GA'
|
||||||
implementation group: 'junit', name: 'junit'
|
implementation group: 'junit', name: 'junit'
|
||||||
|
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package email;
|
|||||||
|
|
||||||
import email.model.Email;
|
import email.model.Email;
|
||||||
import email.service.EmailService;
|
import email.service.EmailService;
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@Hidden
|
||||||
@RequestMapping("/ajax")
|
@RequestMapping("/ajax")
|
||||||
public class AjaxController {
|
public class AjaxController {
|
||||||
private final EmailService emailService;
|
private final EmailService emailService;
|
||||||
|
48
src/main/java/email/EmailRestController.java
Normal file
48
src/main/java/email/EmailRestController.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package email;
|
||||||
|
|
||||||
|
import email.model.Email;
|
||||||
|
import email.service.EmailService;
|
||||||
|
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.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/rest")
|
||||||
|
public class EmailRestController {
|
||||||
|
private final EmailService emailService;
|
||||||
|
|
||||||
|
public EmailRestController(EmailService emailService) {
|
||||||
|
this.emailService = emailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@GetMapping("/getEmail/{id}")
|
||||||
|
public Email getEmail(@PathVariable("id") Integer id) {
|
||||||
|
return emailService.getEmailById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@GetMapping("/list")
|
||||||
|
public List<Email> getList() {
|
||||||
|
return emailService.getAllEmails();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@PostMapping("/saveEmail")
|
||||||
|
public Email saveEmail(@RequestBody Email email) {
|
||||||
|
if (email.getTo().isEmpty()) {
|
||||||
|
throw new RuntimeException("Поле 'Кому' не должно быть пустым");
|
||||||
|
}
|
||||||
|
Email previousEmail = emailService.getEmailById(email.getId());
|
||||||
|
previousEmail.setMessage(email.getMessage());
|
||||||
|
previousEmail.setSubject(email.getSubject());
|
||||||
|
previousEmail.setTo(email.getTo());
|
||||||
|
return emailService.save(previousEmail);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user