-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e679f2
commit be203cc
Showing
11 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
api/src/main/java/ru/dragonestia/picker/api/repository/response/SearchUserResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.dragonestia.picker.api.repository.response; | ||
|
||
import ru.dragonestia.picker.api.repository.response.type.RUser; | ||
|
||
import java.util.List; | ||
|
||
public record SearchUserResponse(List<RUser> users) {} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/ru/dragonestia/picker/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ru.dragonestia.picker.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import ru.dragonestia.picker.api.repository.details.UserDetails; | ||
import ru.dragonestia.picker.api.repository.response.SearchUserResponse; | ||
import ru.dragonestia.picker.service.UserService; | ||
import ru.dragonestia.picker.util.NamingValidator; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/users") | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
private final NamingValidator namingValidator; | ||
|
||
@GetMapping("/search") | ||
SearchUserResponse search(@RequestParam(name = "input") String input, | ||
@RequestParam(name = "requiredDetails", required = false, defaultValue = "") String detailsSeq) { | ||
|
||
if (!namingValidator.validateUserId(input) || input.isEmpty()) { | ||
return new SearchUserResponse(List.of()); | ||
} | ||
|
||
var details = new HashSet<UserDetails>(); | ||
for (var detailStr: detailsSeq.split(",")) { | ||
try { | ||
details.add(UserDetails.valueOf(detailStr.toUpperCase())); | ||
} catch (IllegalArgumentException ignore) {} | ||
} | ||
|
||
return new SearchUserResponse(userService.searchUsers(input, details)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
control-panel/src/main/java/ru/dragonestia/picker/cp/page/UserSearchPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ru.dragonestia.picker.cp.page; | ||
|
||
import com.vaadin.flow.component.Unit; | ||
import com.vaadin.flow.component.button.Button; | ||
import com.vaadin.flow.component.button.ButtonVariant; | ||
import com.vaadin.flow.component.grid.ColumnTextAlign; | ||
import com.vaadin.flow.component.grid.Grid; | ||
import com.vaadin.flow.component.html.Span; | ||
import com.vaadin.flow.component.icon.Icon; | ||
import com.vaadin.flow.component.icon.VaadinIcon; | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout; | ||
import com.vaadin.flow.component.textfield.TextField; | ||
import com.vaadin.flow.router.PageTitle; | ||
import com.vaadin.flow.router.Route; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import ru.dragonestia.picker.api.repository.UserRepository; | ||
import ru.dragonestia.picker.api.repository.details.UserDetails; | ||
import ru.dragonestia.picker.api.repository.response.type.RUser; | ||
import ru.dragonestia.picker.cp.component.Notifications; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
@PageTitle("Search users") | ||
@Route(value = "/users", layout = MainLayout.class) | ||
public class UserSearchPage extends VerticalLayout { | ||
|
||
private final UserRepository userRepository; | ||
private final TextField fieldUsername; | ||
private final Grid<RUser> userGrid; | ||
private List<RUser> cachedUsers = new LinkedList<>(); | ||
|
||
@Autowired | ||
public UserSearchPage(UserRepository userRepository) { | ||
this.userRepository = userRepository; | ||
|
||
add(fieldUsername = createUsernameInputField()); | ||
add(userGrid = createUserGrid()); | ||
} | ||
|
||
private TextField createUsernameInputField() { | ||
var field = new TextField(); | ||
field.setLabel("Username"); | ||
field.setPlaceholder("some-user-identifier"); | ||
field.setRequired(true); | ||
field.setMinWidth(30, Unit.PERCENTAGE); | ||
|
||
var button = new Button(new Icon(VaadinIcon.SEARCH)); | ||
button.addThemeVariants(ButtonVariant.LUMO_PRIMARY); | ||
button.getStyle().set("color", "#FFFFFF"); | ||
button.addClickListener(event -> search(fieldUsername.getValue().trim())); | ||
|
||
field.setSuffixComponent(button); | ||
return field; | ||
} | ||
|
||
private Grid<RUser> createUserGrid() { | ||
var grid = new Grid<RUser>(); | ||
|
||
grid.addColumn(RUser::getId).setHeader("Identifier") | ||
.setFooter("Found %s users".formatted(cachedUsers.size())); | ||
|
||
grid.addColumn(user -> user.getDetail(UserDetails.COUNT_ROOMS)).setTextAlign(ColumnTextAlign.CENTER).setHeader("Linked with rooms"); | ||
|
||
grid.addComponentColumn(user -> new Span("buttons")).setHeader("Manage"); // TODO | ||
|
||
return grid; | ||
} | ||
|
||
private void search(String input) { | ||
userGrid.setItems(cachedUsers = userRepository.search(input, UserRepository.ALL_DETAILS)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters