Skip to content

Commit

Permalink
Merge pull request #54 from jmprathab/revert-53-issue41-GET-users-wit…
Browse files Browse the repository at this point in the history
…h-paging

Revert "Implement pagination for GET /users endpoint #41"
  • Loading branch information
jmprathab committed Jul 23, 2020
2 parents fa0970d + 199b3b7 commit 4ad16d3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 137 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/myhome/controllers/UserController.java
Expand Up @@ -29,7 +29,6 @@
import java.util.Set;
import javax.validation.Valid;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -38,19 +37,23 @@
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* Controller for facilitating user actions.
*/
@RestController
@Slf4j
@RequiredArgsConstructor
public class UserController {
private final UserService userService;
private final UserApiMapper userApiMapper;

public UserController(UserService userService,
UserApiMapper userApiMapper) {
this.userService = userService;
this.userApiMapper = userApiMapper;
}

@Operation(description = "Create a new user")
@PostMapping(
path = "/users",
Expand All @@ -68,10 +71,9 @@ public ResponseEntity<CreateUserResponse> signUp(@Valid @RequestBody CreateUserR

@GetMapping(path = "/users",
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
public ResponseEntity<GetUserDetailsResponse> listAllUsers(
@RequestParam(required = false) Integer limit, @RequestParam(required = false) Integer start) {
public ResponseEntity<GetUserDetailsResponse> listAllUsers() {
log.trace("Received request to list all users");
Set<User> userDetails = userService.listAll(limit, start);
Set<User> userDetails = userService.listAll();
Set<GetUserDetailsResponse.User> userDetailsResponse =
userApiMapper.userSetToRestApiResponseUserSet(userDetails);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/myhome/services/UserService.java
Expand Up @@ -27,7 +27,7 @@
public interface UserService {
UserDto createUser(UserDto request);

Set<User> listAll(Integer limit, Integer start);
Set<User> listAll();

Optional<UserDto> getUserDetails(UserDto request);
}
Expand Up @@ -29,9 +29,8 @@
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

Expand All @@ -40,31 +39,33 @@
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class UserSDJpaService implements UserService {

private final UserRepository userRepository;
private final UserMapper userMapper;
private final PasswordEncoder passwordEncoder;
private final CommunityService communityService;

@Autowired
private CommunityService communityService;

public UserSDJpaService(UserRepository userRepository,
UserMapper userMapper,
PasswordEncoder passwordEncoder) {
this.userRepository = userRepository;
this.userMapper = userMapper;
this.passwordEncoder = passwordEncoder;
}

@Override public UserDto createUser(UserDto request) {
generateUniqueUserId(request);
encryptUserPassword(request);
return createUserInRepository(request);
}

@Override public Set<User> listAll(Integer limit, Integer start) {
@Override public Set<User> listAll() {
Set<User> userListSet = new HashSet<>();
userRepository.findAll().forEach(userListSet::add);
Stream<User> userStream = userListSet.stream();
if (start != null) {
userStream = userStream.skip(start);
}
if (limit != null) {
userStream = userStream.limit(limit);
}
return userStream.collect(Collectors.toSet());
return userListSet;
}

@Override public Optional<UserDto> getUserDetails(UserDto request) {
Expand Down
59 changes: 0 additions & 59 deletions src/test/java/com/myhome/controllers/ControllerTestBase.java

This file was deleted.

58 changes: 0 additions & 58 deletions src/test/java/com/myhome/controllers/UserControllerTest.java

This file was deleted.

0 comments on commit 4ad16d3

Please sign in to comment.