client methods for account info endpoints

This commit is contained in:
2024-10-27 20:22:55 +01:00
Unverified
parent ad822c648a
commit 89dc74f767
7 changed files with 72 additions and 2 deletions

View File

@@ -7,7 +7,7 @@ public class AccountRequest : Account
#region PROPERTIES
[JsonPropertyName("gender_id")]
public short GenderId { get; set; }
public short? GenderId { get; set; }
#endregion

View File

@@ -0,0 +1,21 @@
using FluentValidation;
using WatchIt.Common.Model.Accounts;
using WatchIt.Database;
namespace WatchIt.WebAPI.Validators.Accounts;
public class AccountRequestValidator : AbstractValidator<AccountRequest>
{
public AccountRequestValidator(DatabaseContext database)
{
RuleFor(x => x.Username).NotEmpty()
.MaximumLength(50);
RuleFor(x => x.Email).EmailAddress()
.MaximumLength(320);
RuleFor(x => x.Description).MaximumLength(1000);
When(x => x.GenderId.HasValue, () =>
{
RuleFor(x => x.GenderId!.Value).MustBeIn(database.Genders.Select(x => x.Id));
});
}
}

View File

@@ -46,6 +46,7 @@ public static class Program
while (!dbContext.Database.CanConnect())
{
app.Logger.LogInformation("Waiting for database...");
Thread.Sleep(1000);
}

View File

@@ -8,4 +8,7 @@ public class Accounts
public string AuthenticateRefresh { get; set; }
public string Logout { get; set; }
public string GetProfilePicture { get; set; }
public string GetAccountInfoById { get; set; }
public string GetAccountInfo { get; set; }
public string PutAccountInfo { get; set; }
}

View File

@@ -80,6 +80,45 @@ public class AccountsWebAPIService(IHttpClientService httpClientService, IConfig
.ExecuteAction();
}
public async Task GetAccountInfoById(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountInfoById, id);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task GetAccountInfo(Action<AccountResponse>? successAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountInfo);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task PutAccountInfo(AccountRequest data, Action<AccountResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.PutAccountInfo);
HttpRequest request = new HttpRequest(HttpMethodType.Put, url)
{
Body = data,
};
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor400BadRequest(badRequestAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#endregion

View File

@@ -9,4 +9,7 @@ public interface IAccountsWebAPIService
Task AuthenticateRefresh(Action<AuthenticateResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
Task Logout(Action? successAction = null);
Task GetAccountProfilePicture(long id, Action<AccountProfilePictureResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null);
Task GetAccountInfoById(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null);
Task GetAccountInfo(Action<AccountResponse>? successAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null);
Task PutAccountInfo(AccountRequest data, Action<AccountResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null);
}

View File

@@ -21,7 +21,10 @@
"Authenticate": "/authenticate",
"AuthenticateRefresh": "/authenticate-refresh",
"Logout": "/logout",
"GetProfilePicture": "/{0}/profile-picture"
"GetProfilePicture": "/{0}/profile-picture",
"GetAccountInfoById": "/{0}/info",
"GetAccountInfo": "/info",
"PutAccountInfo": "/info"
},
"Genders": {
"Base": "/genders",