Skip to content

New Updated UserProducer #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.List;
Expand All @@ -17,10 +22,12 @@
*
* @author Quinten De Swaef
*/
@Component
@RestController
public class UserProducer {
private Log logger = LogFactory.getLog(UserProducer.class);


@Autowired
private UserService userService;

@Autowired
Expand All @@ -32,23 +39,33 @@ public UserProducer(UserService userService) {
public void produceData() {
findUsers();
addOneUser();
findUsers();
}

private void addOneUser() {
logger.info("-> Adding new user now!");
userService.addUser(new User("Quinten", "SecretPassword"));

@RequestMappping(value="/adduser", Method="RequestMethod.POST")
public void addUser(@RequestBody User user){
userService.addUser();

}

private void findUsers() {
// private void addOneUser() {
// logger.info("-> Adding new user now!");
// userService.addUser(new User("Quinten", "SecretPassword"));
// }

@RequestMapping(values="/findbyid/{id}", Method="RequestMethod.GET")
private User findUsers(@PathVariable int id) {
logger.info("Trying to find all users.");
List<User> allUsers = userService.getAllUsers();
if(allUsers.isEmpty()) {
logger.info("--No users found--");
} else {
for (User foundUser : allUsers) {
logger.info(String.format("user with id %d and name %s found :)", foundUser.getId(), foundUser.getName()));
}
}
userService.findUsers(id);




// List<User> allUsers = userService.getAllUsers();
// if(allUsers.isEmpty()) {
// logger.info("--No users found--");
// } else {
// for (User foundUser : allUsers) {
// logger.info(String.format("user with id %d and name %s found :)", foundUser.getId(), foundUser.getName()));
// }
// }
}
}