Skip to content
Snippets Groups Projects
Commit 7861a272 authored by Martin Gargalovič's avatar Martin Gargalovič
Browse files

added validation to mail

parent 956fbf87
No related branches found
No related tags found
3 merge requests!31M2,!28M2 user,!27Draft: M2 user
......@@ -22,6 +22,11 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......
package org.fuseri.modulemail.service;
import jakarta.validation.constraints.NotBlank;
public class EmailDto {
String sender;
@NotBlank
String receiver;
@NotBlank
String content;
public EmailDto(String sender, String receiver, String content) {
this.sender = sender;
public EmailDto(String receiver, String content) {
this.receiver = receiver;
this.content = content;
}
@Override
public String toString() {
return "EmailDto{" +
"sender='" + sender + '\'' +
", receiver='" + receiver + '\'' +
", content='" + content + '\'' +
'}';
}
}
package org.fuseri.modulemail.service;
import jakarta.websocket.server.PathParam;
import jakarta.validation.Valid;
import jakarta.validation.constraints.PositiveOrZero;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -25,19 +25,17 @@ public class MailControler {
@GetMapping("/{id}")
public ResponseEntity getEmail(@PathVariable("id") Long id) {
return ResponseEntity.ok(service.getMail(id).toString());
public String getEmail(@PositiveOrZero @PathVariable("id") Long id) {
return "No mail with that id yet";
}
@DeleteMapping("/delete/{id}")
public ResponseEntity deleteMail(@PathVariable("id") Long id) {
return ResponseEntity.ok(service.DeleteMail(id));
public String deleteMail(@PositiveOrZero @PathVariable("id") Long id) {
return "Nothing to delete Yet";
}
@PostMapping()
public ResponseEntity sendMail(@RequestBody EmailDto emailDto) {
return ResponseEntity.ok(service.send(emailDto));
public String sendMail(@Valid @RequestBody EmailDto emailDto) {
return service.send(emailDto);
}
}
......@@ -12,7 +12,7 @@ public class MailService {
public String send(EmailDto dto) {
var message = new SimpleMailMessage();
message.setFrom(dto.sender);
message.setFrom("sprachul@gmail.com");
message.setTo(dto.receiver);
message.setSubject("Sprachschul");
message.setText(dto.content);
......@@ -24,7 +24,7 @@ public class MailService {
}
public EmailDto getMail(long id) {
return new EmailDto("","",""); // return from database once there is one
return new EmailDto("empty","empty"); // return from database once there is one
}
public String DeleteMail (long id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment