Commit d0481dcb391a11aa2720ea98c9b367ff71f12499

Authored by Julien Cartigny
1 parent a8656157

Support for user REST controller

src/main/java/fr/plil/sio/web/mvc/UserRestController.java 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +package fr.plil.sio.web.mvc;
  2 +
  3 +import org.springframework.web.bind.annotation.RequestMapping;
  4 +import org.springframework.web.bind.annotation.RequestMethod;
  5 +import org.springframework.web.bind.annotation.RestController;
  6 +
  7 +import javax.annotation.Resource;
  8 +import java.util.List;
  9 +
  10 +@RestController
  11 +public class UserRestController {
  12 +
  13 + @Resource
  14 + private UserService userService;
  15 +
  16 + @RequestMapping(value = "/users/", method = RequestMethod.GET)
  17 + public List<User> listUsers() {
  18 + return userService.findAll();
  19 + }
  20 +}
0 \ No newline at end of file 21 \ No newline at end of file
src/main/java/fr/plil/sio/web/mvc/UserService.java
1 package fr.plil.sio.web.mvc; 1 package fr.plil.sio.web.mvc;
2 2
  3 +import java.util.List;
  4 +
3 public interface UserService { 5 public interface UserService {
4 6
5 User createUser(String username, String password); 7 User createUser(String username, String password);
6 8
7 User findByUsername(String username); 9 User findByUsername(String username);
  10 +
  11 + List<User> findAll();
8 } 12 }
src/main/java/fr/plil/sio/web/mvc/UserServiceImpl.java
@@ -6,6 +6,7 @@ import org.springframework.transaction.annotation.Transactional; @@ -6,6 +6,7 @@ import org.springframework.transaction.annotation.Transactional;
6 6
7 import javax.annotation.Resource; 7 import javax.annotation.Resource;
8 import java.util.HashSet; 8 import java.util.HashSet;
  9 +import java.util.List;
9 import java.util.Set; 10 import java.util.Set;
10 11
11 @Service("userService") 12 @Service("userService")
@@ -37,4 +38,9 @@ public class UserServiceImpl implements UserService { @@ -37,4 +38,9 @@ public class UserServiceImpl implements UserService {
37 public User findByUsername(String username) { 38 public User findByUsername(String username) {
38 return userRepository.findByUsername(username); 39 return userRepository.findByUsername(username);
39 } 40 }
  41 +
  42 + @Override
  43 + public List<User> findAll() {
  44 + return userRepository.findAll();
  45 + }
40 } 46 }