diff options
| author | Bobby <[email protected]> | 2026-03-08 02:27:15 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-08 02:27:15 +0530 |
| commit | cca905d35412f1549400fc3d1aca6dc704d8cae6 (patch) | |
| tree | 0c0231f5c2ebaeb7700e08a2c1f07373d3251658 /services/mail/users.go | |
| parent | 547384c41181c034a5eaf340c5e569d36eb013be (diff) | |
| download | dove-cca905d35412f1549400fc3d1aca6dc704d8cae6.tar.xz dove-cca905d35412f1549400fc3d1aca6dc704d8cae6.zip | |
feat(domains): add new TLD creation page and update sidebar
- Introduced a new HTMX template for creating TLDs.
- Created a new Django template for the new TLD page.
- Updated the sidebar to include a link to the domains section.
refactor(types): remove unused types and consolidate request handling
- Deleted unused type definitions related to authentication, errors, mailboxes, overview, requests, responses, and users.
- Introduced a new collections package for generic data structures.
- Refactored request handling to use a more streamlined approach with RequestInfo and Param types.
fix(meta): improve pagination and sorting functionality
- Updated pagination logic to handle default values and edge cases.
- Introduced a new Sorting type for better sorting management in queries.
chore(urls): refactor URL handling and registry
- Replaced enums with string constants for HTTP methods.
- Consolidated route registration logic and improved type safety with RegisteredRoute.
style(shortcuts): clean up error handling and rendering functions
- Enhanced error handling functions for better readability and maintainability.
- Removed deprecated functions and improved the structure of rendering logic.
Diffstat (limited to 'services/mail/users.go')
| -rw-r--r-- | services/mail/users.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/services/mail/users.go b/services/mail/users.go new file mode 100644 index 0000000..9520219 --- /dev/null +++ b/services/mail/users.go @@ -0,0 +1,52 @@ +package mail + +import ( + "strings" + + "dove/models" + "dove/repositories" + "dove/utils/meta" + "dove/utils/shortcuts" +) + +type CreateUserRequest struct { + Username string `form:"username"` + DisplayName string `form:"display_name"` +} + +func ListUsers(pagination meta.Pagination, sorting meta.Sorting, search string) meta.PaginatedResponse { + users, total := repositories.ListUsers(pagination, sorting, search) + return pagination.Response(users, total) +} + +func CreateUser(request CreateUserRequest) *shortcuts.Error { + username := strings.TrimSpace(request.Username) + displayName := strings.TrimSpace(request.DisplayName) + + if username == "" { + return shortcuts.ServiceError(shortcuts.BadRequest, UsernameRequired) + } + + if displayName == "" { + return shortcuts.ServiceError(shortcuts.BadRequest, DisplayNameRequired) + } + + if repositories.FindUserByUsername(username) != nil { + return shortcuts.ServiceError(shortcuts.Unprocessable, UserAlreadyExists) + } + + newUser := &models.User{ + Username: username, + DisplayName: displayName, + } + + if createError := repositories.CreateUser(newUser); createError != nil { + return shortcuts.ServiceError(shortcuts.Internal, UserCreationFailed) + } + + return nil +} + +func AllUsers() []models.User { + return repositories.AllUsers() +} |
