Skip to content

Commit

Permalink
✨ (userservice) search usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias-Pe committed May 11, 2024
1 parent 15cbf57 commit 8a46a3a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("users")
public class UserAccountController {
Expand All @@ -30,4 +32,9 @@ public UserAccount getUserAccount(@RequestParam(required = false) String usernam
public UserAccount createUserAccount(@RequestBody UserAccountRequest userAccountRequest) {
return userAccountService.createUser(userAccountRequest);
}

@PostMapping("/search")
public Set<UserAccount> createUserAccount(@RequestParam String query) {
return userAccountService.search(query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
import java.util.Set;

public interface UserAccountRepository extends JpaRepository<UserAccount, Integer> {
Optional<UserAccount> findByUsername(String username);

Set<UserAccount> findUserAccountByUsernameLike(String query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class UserAccountService {
UserAccountRepository userAccountRepository;
Expand All @@ -28,4 +30,8 @@ public UserAccount getUserByUsername(String username) {
public UserAccount getUserById(Integer id) {
return userAccountRepository.findById(id).orElseThrow(() -> new UserNotFoundException(String.valueOf(id)));
}

public Set<UserAccount> search(String query) {
return userAccountRepository.findUserAccountByUsernameLike(query);
}
}

0 comments on commit 8a46a3a

Please sign in to comment.