client methods for account info endpoints
This commit is contained in:
@@ -7,7 +7,7 @@ public class AccountRequest : Account
|
|||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
|
|
||||||
[JsonPropertyName("gender_id")]
|
[JsonPropertyName("gender_id")]
|
||||||
public short GenderId { get; set; }
|
public short? GenderId { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -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));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,7 @@ public static class Program
|
|||||||
|
|
||||||
while (!dbContext.Database.CanConnect())
|
while (!dbContext.Database.CanConnect())
|
||||||
{
|
{
|
||||||
|
app.Logger.LogInformation("Waiting for database...");
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,4 +8,7 @@ public class Accounts
|
|||||||
public string AuthenticateRefresh { get; set; }
|
public string AuthenticateRefresh { get; set; }
|
||||||
public string Logout { get; set; }
|
public string Logout { get; set; }
|
||||||
public string GetProfilePicture { get; set; }
|
public string GetProfilePicture { get; set; }
|
||||||
|
public string GetAccountInfoById { get; set; }
|
||||||
|
public string GetAccountInfo { get; set; }
|
||||||
|
public string PutAccountInfo { get; set; }
|
||||||
}
|
}
|
||||||
@@ -80,6 +80,45 @@ public class AccountsWebAPIService(IHttpClientService httpClientService, IConfig
|
|||||||
.ExecuteAction();
|
.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
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,4 +9,7 @@ public interface IAccountsWebAPIService
|
|||||||
Task AuthenticateRefresh(Action<AuthenticateResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
|
Task AuthenticateRefresh(Action<AuthenticateResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
|
||||||
Task Logout(Action? successAction = null);
|
Task Logout(Action? successAction = null);
|
||||||
Task GetAccountProfilePicture(long id, Action<AccountProfilePictureResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = 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);
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,10 @@
|
|||||||
"Authenticate": "/authenticate",
|
"Authenticate": "/authenticate",
|
||||||
"AuthenticateRefresh": "/authenticate-refresh",
|
"AuthenticateRefresh": "/authenticate-refresh",
|
||||||
"Logout": "/logout",
|
"Logout": "/logout",
|
||||||
"GetProfilePicture": "/{0}/profile-picture"
|
"GetProfilePicture": "/{0}/profile-picture",
|
||||||
|
"GetAccountInfoById": "/{0}/info",
|
||||||
|
"GetAccountInfo": "/info",
|
||||||
|
"PutAccountInfo": "/info"
|
||||||
},
|
},
|
||||||
"Genders": {
|
"Genders": {
|
||||||
"Base": "/genders",
|
"Base": "/genders",
|
||||||
|
|||||||
Reference in New Issue
Block a user