IUsersServiceClient.cs
1,814 bytes
| 1 | using SplitApp.WebApp.Application.UsersService.Dtos; |
|---|---|
| 2 | |
| 3 | namespace SplitApp.WebApp.Application.UsersService; |
| 4 | |
| 5 | public interface IUsersServiceClient |
| 6 | { |
| 7 | Task<UsersServiceResult<JwtResponsePayload>> LoginAsync( |
| 8 | string email, string password, CancellationToken ct = default); |
| 9 | |
| 10 | Task<UsersServiceResult<JwtResponsePayload>> RegisterAsync( |
| 11 | string email, string password, string firstName, string lastName, CancellationToken ct = default); |
| 12 | |
| 13 | Task<UsersServiceResult<JwtResponsePayload>> RefreshAsync( |
| 14 | string jwt, string refreshToken, CancellationToken ct = default); |
| 15 | |
| 16 | Task LogoutAsync(string refreshToken, CancellationToken ct = default); |
| 17 | |
| 18 | // Admin |
| 19 | Task<IReadOnlyList<AdminUserListItem>> ListUsersAsync(CancellationToken ct = default); |
| 20 | Task<AdminUserDetails?> GetUserAsync(Guid id, CancellationToken ct = default); |
| 21 | Task<AdminUserDetails?> UpdateUserAsync(Guid id, string firstName, string lastName, CancellationToken ct = default); |
| 22 | Task<bool> DeleteUserAsync(Guid id, CancellationToken ct = default); |
| 23 | Task<IReadOnlyList<string>> GetUserRolesAsync(Guid id, CancellationToken ct = default); |
| 24 | Task SetUserRolesAsync(Guid id, IReadOnlyCollection<string> roleNames, CancellationToken ct = default); |
| 25 | Task<IReadOnlyList<AdminRoleInfo>> ListRolesAsync(CancellationToken ct = default); |
| 26 | } |
| 27 | |
| 28 | /// <summary>Outcome of a Users-service call where business-level errors (4xx) need to be surfaced to MVC views.</summary> |
| 29 | public class UsersServiceResult<T> |
| 30 | { |
| 31 | public bool Success { get; init; } |
| 32 | public T? Value { get; init; } |
| 33 | public string? Error { get; init; } |
| 34 | |
| 35 | public static UsersServiceResult<T> Ok(T value) => new() { Success = true, Value = value }; |
| 36 | public static UsersServiceResult<T> Fail(string error) => new() { Success = false, Error = error }; |
| 37 | } |
| 38 | |