Ver código fonte

base project

Daniel Garcia Costa 2 anos atrás
pai
commit
70ec1081ac

+ 32 - 0
src/main/java/es/uv/garcosda/controllers/MailerController.java

@@ -0,0 +1,32 @@
+package es.uv.garcosda.controllers;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import es.uv.garcosda.domain.User;
+import es.uv.garcosda.services.UserService;
+
+@RestController
+@RequestMapping("/api/v1")
+public class MailerController {
+
+	@Autowired
+	private UserService us;
+	
+	@GetMapping("users/{email}")
+	public ResponseEntity<?> getUser(@PathVariable("email") String email) {
+		User u = this.us.findByEmail(email);
+		if(u.getEmail() == null) {
+			return new ResponseEntity<String>("No user found with email "+email, HttpStatus.NOT_FOUND);
+		}
+		else {
+			return new ResponseEntity<User>(u, HttpStatus.NOT_FOUND);
+		}
+	}
+	
+}

+ 51 - 0
src/main/java/es/uv/garcosda/domain/Mail.java

@@ -0,0 +1,51 @@
+package es.uv.garcosda.domain;
+
+public class Mail {
+	
+	private User from;
+	private User to;
+	private String subject;
+	private String body;
+	
+	public Mail() {}
+	
+	public Mail(User from, User to, String subject, String body) {
+		this.from = from;
+		this.to = to;
+		this.subject = subject;
+		this.body = body;
+	}
+
+	public User getFrom() {
+		return from;
+	}
+
+	public void setFrom(User from) {
+		this.from = from;
+	}
+
+	public User getTo() {
+		return to;
+	}
+
+	public void setTo(User to) {
+		this.to = to;
+	}
+
+	public String getSubject() {
+		return subject;
+	}
+
+	public void setSubject(String subject) {
+		this.subject = subject;
+	}
+
+	public String getBody() {
+		return body;
+	}
+
+	public void setBody(String body) {
+		this.body = body;
+	}
+	
+}

+ 41 - 0
src/main/java/es/uv/garcosda/domain/User.java

@@ -0,0 +1,41 @@
+package es.uv.garcosda.domain;
+
+public class User {
+
+	private String email;
+	private String firstname;
+	private String lastname;
+	
+	public User() {}
+
+	public User(String email, String firstname, String lastname) {
+		this.email = email;
+		this.firstname = firstname;
+		this.lastname = lastname;
+	}
+
+	public String getEmail() {
+		return email;
+	}
+
+	public void setEmail(String email) {
+		this.email = email;
+	}
+
+	public String getFirstname() {
+		return firstname;
+	}
+
+	public void setFirstname(String firstname) {
+		this.firstname = firstname;
+	}
+
+	public String getLastname() {
+		return lastname;
+	}
+
+	public void setLastname(String lastname) {
+		this.lastname = lastname;
+	}
+	
+}

+ 50 - 0
src/main/java/es/uv/garcosda/services/UserService.java

@@ -0,0 +1,50 @@
+package es.uv.garcosda.services;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.springframework.stereotype.Service;
+
+import es.uv.garcosda.domain.User;
+
+@Service
+public class UserService {
+
+	private List<User> users;
+	
+	public UserService() {
+		users = new ArrayList<User>(
+		        Arrays.asList(new User("Quintina.Ardra@yopmail.com","Quintina","Ardra"),
+		        		new User("Sybille.Land@yopmail.com","Sybille","Land"),
+		        		new User("Kimmy.Elisha@yopmail.com","Kimmy","Elisha"),
+		        		new User("Jeanna.McGrody@yopmail.com","Jeanna","McGrody"),
+		        		new User("Lelah.Haymes@yopmail.com","Lelah","Haymes"),
+		        		new User("Edith.Milson@yopmail.com","Edith","Milson"),
+		        		new User("Minne.Eugenia@yopmail.com","Minne","Eugenia"),
+		        		new User("Abbie.Brittani@yopmail.com","Abbie","Brittani"),
+		        		new User("Brianna.Tacye@yopmail.com","Brianna","Tacye"),
+		        		new User("Gabi.Clarissa@yopmail.com","Gabi","Clarissa"),
+		        		new User("Aili.Evvie@yopmail.com","Aili","Evvie"),
+		        		new User("Jillayne.Plato@yopmail.com","Jillayne","Plato"),
+		        		new User("Allis.Daniele@yopmail.com","Allis","Daniele"),
+		        		new User("Sam.Guildroy@yopmail.com","Sam","Guildroy"),
+		        		new User("Sam.Argus@yopmail.com","Sam","Argus"),
+		        		new User("Lorne.Kirbee@yopmail.com","Lorne","Kirbee"),
+		        		new User("Brianna.Georgy@yopmail.com","Brianna","Georgy"),
+		        		new User("Tarra.Gino@yopmail.com","Tarra","Gino"),
+		        		new User("Elvira.Thornburg@yopmail.com","Elvira","Thornburg"),
+		        		new User("Paola.Alice@yopmail.com","Paola","Alice")
+		       ));
+	}
+	
+	public User findByEmail(String email) {
+		List<User> ps = this.users.stream().filter(x -> x.getEmail().toLowerCase().equals(email.toLowerCase())).collect(Collectors.toList());
+		if(ps.size() > 0) {
+			return ps.get(0);
+		}
+		return new User(); 
+	}
+	
+}