following added
This commit is contained in:
@@ -22,7 +22,7 @@ public class AccountFollowConfiguration : IEntityTypeConfiguration<AccountFollow
|
||||
.IsRequired();
|
||||
|
||||
builder.HasOne(x => x.AccountFollowed)
|
||||
.WithMany(x => x.AccountFollowedBy)
|
||||
.WithMany(x => x.AccountFollowers)
|
||||
.HasForeignKey(x => x.AccountFollowedId)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.AccountFollowedId)
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Account
|
||||
public virtual IEnumerable<AccountRefreshToken> AccountRefreshTokens { get; set; } = new List<AccountRefreshToken>();
|
||||
|
||||
public virtual IEnumerable<AccountFollow> AccountFollows { get; set; } = new List<AccountFollow>();
|
||||
public virtual IEnumerable<AccountFollow> AccountFollowedBy { get; set; } = new List<AccountFollow>();
|
||||
public virtual IEnumerable<AccountFollow> AccountFollowers { get; set; } = new List<AccountFollow>();
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public class DatabaseContext : DbContext
|
||||
|
||||
// Account
|
||||
public virtual DbSet<Account> Accounts { get; set; }
|
||||
public virtual DbSet<AccountFollow> AccountFollows { get; set; }
|
||||
public virtual DbSet<AccountProfilePicture> AccountProfilePictures { get; set; }
|
||||
public virtual DbSet<AccountRefreshToken> AccountRefreshTokens { get; set; }
|
||||
|
||||
|
||||
1459
WatchIt.Database/WatchIt.Database/Migrations/20241109182449_RelationRename.Designer.cs
generated
Normal file
1459
WatchIt.Database/WatchIt.Database/Migrations/20241109182449_RelationRename.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,136 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace WatchIt.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class RelationRename : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_AccountFollow_Accounts_AccountFollowedId",
|
||||
table: "AccountFollow");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_AccountFollow_Accounts_AccountFollowerId",
|
||||
table: "AccountFollow");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_AccountFollow",
|
||||
table: "AccountFollow");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "AccountFollow",
|
||||
newName: "AccountFollows");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_AccountFollow_Id",
|
||||
table: "AccountFollows",
|
||||
newName: "IX_AccountFollows_Id");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_AccountFollow_AccountFollowerId",
|
||||
table: "AccountFollows",
|
||||
newName: "IX_AccountFollows_AccountFollowerId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_AccountFollow_AccountFollowedId",
|
||||
table: "AccountFollows",
|
||||
newName: "IX_AccountFollows_AccountFollowedId");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_AccountFollows",
|
||||
table: "AccountFollows",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "Accounts",
|
||||
keyColumn: "Id",
|
||||
keyValue: 1L,
|
||||
columns: new[] { "LeftSalt", "Password", "RightSalt" },
|
||||
values: new object[] { "QkJky0:m43g!mRL_-0S'", new byte[] { 104, 21, 33, 198, 192, 7, 229, 80, 195, 46, 190, 26, 125, 243, 113, 195, 194, 9, 145, 142, 56, 34, 125, 141, 133, 113, 14, 172, 29, 90, 194, 60, 98, 40, 121, 132, 218, 157, 80, 128, 70, 136, 201, 208, 36, 37, 124, 215, 144, 242, 212, 68, 209, 27, 248, 191, 212, 84, 250, 35, 230, 51, 218, 15 }, "~-jO$aMa{Q9lAW~>)Z+Z" });
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_AccountFollows_Accounts_AccountFollowedId",
|
||||
table: "AccountFollows",
|
||||
column: "AccountFollowedId",
|
||||
principalTable: "Accounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_AccountFollows_Accounts_AccountFollowerId",
|
||||
table: "AccountFollows",
|
||||
column: "AccountFollowerId",
|
||||
principalTable: "Accounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_AccountFollows_Accounts_AccountFollowedId",
|
||||
table: "AccountFollows");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_AccountFollows_Accounts_AccountFollowerId",
|
||||
table: "AccountFollows");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_AccountFollows",
|
||||
table: "AccountFollows");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "AccountFollows",
|
||||
newName: "AccountFollow");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_AccountFollows_Id",
|
||||
table: "AccountFollow",
|
||||
newName: "IX_AccountFollow_Id");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_AccountFollows_AccountFollowerId",
|
||||
table: "AccountFollow",
|
||||
newName: "IX_AccountFollow_AccountFollowerId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_AccountFollows_AccountFollowedId",
|
||||
table: "AccountFollow",
|
||||
newName: "IX_AccountFollow_AccountFollowedId");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_AccountFollow",
|
||||
table: "AccountFollow",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "Accounts",
|
||||
keyColumn: "Id",
|
||||
keyValue: 1L,
|
||||
columns: new[] { "LeftSalt", "Password", "RightSalt" },
|
||||
values: new object[] { "sfA:fW!3D=GbwXn]X+rm", new byte[] { 95, 134, 48, 126, 85, 131, 129, 152, 252, 161, 69, 133, 62, 112, 45, 111, 3, 163, 80, 99, 167, 66, 169, 121, 140, 69, 242, 14, 89, 126, 184, 43, 62, 87, 22, 1, 88, 246, 34, 181, 231, 110, 14, 54, 120, 114, 37, 67, 240, 82, 112, 125, 84, 155, 194, 90, 14, 189, 90, 68, 30, 146, 204, 105 }, "@$rr>fSvr5Ls|D+Wp;?D" });
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_AccountFollow_Accounts_AccountFollowedId",
|
||||
table: "AccountFollow",
|
||||
column: "AccountFollowedId",
|
||||
principalTable: "Accounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_AccountFollow_Accounts_AccountFollowerId",
|
||||
table: "AccountFollow",
|
||||
column: "AccountFollowerId",
|
||||
principalTable: "Accounts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,9 +108,9 @@ namespace WatchIt.Database.Migrations
|
||||
Email = "root@watch.it",
|
||||
IsAdmin = true,
|
||||
LastActive = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
LeftSalt = "sfA:fW!3D=GbwXn]X+rm",
|
||||
Password = new byte[] { 95, 134, 48, 126, 85, 131, 129, 152, 252, 161, 69, 133, 62, 112, 45, 111, 3, 163, 80, 99, 167, 66, 169, 121, 140, 69, 242, 14, 89, 126, 184, 43, 62, 87, 22, 1, 88, 246, 34, 181, 231, 110, 14, 54, 120, 114, 37, 67, 240, 82, 112, 125, 84, 155, 194, 90, 14, 189, 90, 68, 30, 146, 204, 105 },
|
||||
RightSalt = "@$rr>fSvr5Ls|D+Wp;?D",
|
||||
LeftSalt = "QkJky0:m43g!mRL_-0S'",
|
||||
Password = new byte[] { 104, 21, 33, 198, 192, 7, 229, 80, 195, 46, 190, 26, 125, 243, 113, 195, 194, 9, 145, 142, 56, 34, 125, 141, 133, 113, 14, 172, 29, 90, 194, 60, 98, 40, 121, 132, 218, 157, 80, 128, 70, 136, 201, 208, 36, 37, 124, 215, 144, 242, 212, 68, 209, 27, 248, 191, 212, 84, 250, 35, 230, 51, 218, 15 },
|
||||
RightSalt = "~-jO$aMa{Q9lAW~>)Z+Z",
|
||||
Username = "root"
|
||||
});
|
||||
});
|
||||
@@ -136,7 +136,7 @@ namespace WatchIt.Database.Migrations
|
||||
b.HasIndex("Id")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("AccountFollow");
|
||||
b.ToTable("AccountFollows");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b =>
|
||||
@@ -1020,7 +1020,7 @@ namespace WatchIt.Database.Migrations
|
||||
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountFollow", b =>
|
||||
{
|
||||
b.HasOne("WatchIt.Database.Model.Account.Account", "AccountFollowed")
|
||||
.WithMany("AccountFollowedBy")
|
||||
.WithMany("AccountFollowers")
|
||||
.HasForeignKey("AccountFollowedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
@@ -1348,7 +1348,7 @@ namespace WatchIt.Database.Migrations
|
||||
|
||||
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
|
||||
{
|
||||
b.Navigation("AccountFollowedBy");
|
||||
b.Navigation("AccountFollowers");
|
||||
|
||||
b.Navigation("AccountFollows");
|
||||
|
||||
|
||||
@@ -135,6 +135,8 @@ public class AccountsController(IAccountsControllerService accountsControllerSer
|
||||
|
||||
#endregion
|
||||
|
||||
#region Media
|
||||
|
||||
[HttpGet("{id}/movies")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(IEnumerable<MovieRatedResponse>), StatusCodes.Status200OK)]
|
||||
@@ -152,4 +154,35 @@ public class AccountsController(IAccountsControllerService accountsControllerSer
|
||||
[ProducesResponseType(typeof(IEnumerable<PersonRatedResponse>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> GetAccountRatedPersons([FromRoute]long id, PersonRatedQueryParameters query) => await accountsControllerService.GetAccountRatedPersons(id, query);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Follows
|
||||
|
||||
[HttpGet("{id}/follows")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(IEnumerable<AccountResponse>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> GetAccountFollows([FromRoute]long id, AccountQueryParameters query) => await accountsControllerService.GetAccountFollows(id, query);
|
||||
|
||||
[HttpGet("{id}/followers")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(IEnumerable<AccountResponse>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> GetAccountFollowers([FromRoute]long id, AccountQueryParameters query) => await accountsControllerService.GetAccountFollowers(id, query);
|
||||
|
||||
[HttpPost("follows/{user_id}")]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
||||
public async Task<ActionResult> PostAccountFollow([FromRoute(Name = "user_id")]long userId) => await accountsControllerService.PostAccountFollow(userId);
|
||||
|
||||
[HttpDelete("follows/{user_id}")]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
||||
public async Task<ActionResult> DeleteAccountFollow([FromRoute(Name = "user_id")]long userId) => await accountsControllerService.DeleteAccountFollow(userId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -319,6 +319,8 @@ public class AccountsControllerService(
|
||||
|
||||
#endregion
|
||||
|
||||
#region Media
|
||||
|
||||
public async Task<RequestResult> GetAccountRatedMovies(long id, MovieRatedQueryParameters query)
|
||||
{
|
||||
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id);
|
||||
@@ -365,6 +367,79 @@ public class AccountsControllerService(
|
||||
|
||||
#endregion
|
||||
|
||||
#region Follows
|
||||
|
||||
public async Task<RequestResult> GetAccountFollows(long id, AccountQueryParameters query)
|
||||
{
|
||||
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (account is null)
|
||||
{
|
||||
return RequestResult.NotFound();
|
||||
}
|
||||
|
||||
IEnumerable<AccountResponse> data = account.AccountFollows.Select(x => new AccountResponse(x.AccountFollowed));
|
||||
data = query.PrepareData(data);
|
||||
return RequestResult.Ok(data);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> GetAccountFollowers(long id, AccountQueryParameters query)
|
||||
{
|
||||
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (account is null)
|
||||
{
|
||||
return RequestResult.NotFound();
|
||||
}
|
||||
|
||||
IEnumerable<AccountResponse> data = account.AccountFollowers.Select(x => new AccountResponse(x.AccountFollower));
|
||||
data = query.PrepareData(data);
|
||||
return RequestResult.Ok(data);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> PostAccountFollow(long userId)
|
||||
{
|
||||
long followerId = userService.GetUserId();
|
||||
if (userId == followerId)
|
||||
{
|
||||
return RequestResult.BadRequest().AddValidationError("user_id", "You cannot follow yourself");
|
||||
}
|
||||
if (!database.Accounts.Any(x => x.Id == userId))
|
||||
{
|
||||
return RequestResult.BadRequest().AddValidationError("user_id", "User with this id doesn't exist");
|
||||
}
|
||||
|
||||
Account account = await database.Accounts.FirstAsync(x => x.Id == followerId);
|
||||
if (account.AccountFollows.All(x => x.AccountFollowedId != userId))
|
||||
{
|
||||
AccountFollow follow = new AccountFollow()
|
||||
{
|
||||
AccountFollowerId = followerId,
|
||||
AccountFollowedId = userId,
|
||||
};
|
||||
await database.AccountFollows.AddAsync(follow);
|
||||
await database.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RequestResult.Ok();
|
||||
}
|
||||
|
||||
public async Task<RequestResult> DeleteAccountFollow(long userId)
|
||||
{
|
||||
AccountFollow? accountFollow = await database.AccountFollows.FirstOrDefaultAsync(x => x.AccountFollowerId == userService.GetUserId() && x.AccountFollowedId == userId);
|
||||
|
||||
if (accountFollow is not null)
|
||||
{
|
||||
database.AccountFollows.Attach(accountFollow);
|
||||
database.AccountFollows.Remove(accountFollow);
|
||||
await database.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RequestResult.Ok();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
@@ -28,4 +28,8 @@ public interface IAccountsControllerService
|
||||
Task<RequestResult> GetAccountRatedMovies(long id, MovieRatedQueryParameters query);
|
||||
Task<RequestResult> GetAccountRatedSeries(long id, SeriesRatedQueryParameters query);
|
||||
Task<RequestResult> GetAccountRatedPersons(long id, PersonRatedQueryParameters query);
|
||||
Task<RequestResult> GetAccountFollows(long id, AccountQueryParameters query);
|
||||
Task<RequestResult> GetAccountFollowers(long id, AccountQueryParameters query);
|
||||
Task<RequestResult> PostAccountFollow(long userId);
|
||||
Task<RequestResult> DeleteAccountFollow(long userId);
|
||||
}
|
||||
@@ -13,6 +13,36 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
#region Main
|
||||
|
||||
public async Task GetAccounts(AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccounts);
|
||||
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
|
||||
{
|
||||
Query = query
|
||||
};
|
||||
|
||||
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
||||
response.RegisterActionFor2XXSuccess(successAction)
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
public async Task GetAccount(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccount, id);
|
||||
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
||||
|
||||
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
||||
response.RegisterActionFor2XXSuccess(successAction)
|
||||
.RegisterActionFor404NotFound(notFoundAction)
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Authentication
|
||||
|
||||
public async Task Register(RegisterRequest data, Action<RegisterResponse>? createdAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.Register);
|
||||
@@ -70,6 +100,10 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Profile picture
|
||||
|
||||
public async Task GetAccountProfilePicture(long id, Action<AccountProfilePictureResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountProfilePicture, id);
|
||||
@@ -110,6 +144,10 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Profile background
|
||||
|
||||
public async Task GetAccountProfileBackground(long id, Action<PhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountProfileBackground, id);
|
||||
@@ -150,29 +188,9 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
public async Task GetAccounts(AccountQueryParameters query, Action<IEnumerable<AccountResponse>>? successAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccounts);
|
||||
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
|
||||
{
|
||||
Query = query
|
||||
};
|
||||
#endregion
|
||||
|
||||
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
||||
response.RegisterActionFor2XXSuccess(successAction)
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
public async Task GetAccount(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccount, id);
|
||||
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
||||
|
||||
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
||||
response.RegisterActionFor2XXSuccess(successAction)
|
||||
.RegisterActionFor404NotFound(notFoundAction)
|
||||
.ExecuteAction();
|
||||
}
|
||||
#region Account management
|
||||
|
||||
public async Task PutAccountProfileInfo(AccountProfileInfoRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null)
|
||||
{
|
||||
@@ -234,6 +252,10 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Media
|
||||
|
||||
public async Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountRatedMovies, id);
|
||||
@@ -278,6 +300,63 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
|
||||
|
||||
#endregion
|
||||
|
||||
#region Follows
|
||||
|
||||
public async Task GetAccountFollows(long id, AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null, Action? notFoundAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountFollows, id);
|
||||
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
|
||||
{
|
||||
Query = query
|
||||
};
|
||||
|
||||
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
||||
response.RegisterActionFor2XXSuccess(successAction)
|
||||
.RegisterActionFor404NotFound(notFoundAction)
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
public async Task GetAccountFollowers(long id, AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null, Action? notFoundAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountFollowers, id);
|
||||
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
|
||||
{
|
||||
Query = query
|
||||
};
|
||||
|
||||
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
||||
response.RegisterActionFor2XXSuccess(successAction)
|
||||
.RegisterActionFor404NotFound(notFoundAction)
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
public async Task PostAccountFollow(long userId, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.PostAccountFollow, userId);
|
||||
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
|
||||
|
||||
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
||||
response.RegisterActionFor2XXSuccess(successAction)
|
||||
.RegisterActionFor400BadRequest(badRequestAction)
|
||||
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
public async Task DeleteAccountFollow(long userId, Action? successAction = null, Action? unauthorizedAction = null)
|
||||
{
|
||||
string url = GetUrl(EndpointsConfiguration.Accounts.DeleteAccountFollow, userId);
|
||||
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
|
||||
|
||||
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
||||
response.RegisterActionFor2XXSuccess(successAction)
|
||||
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
||||
.ExecuteAction();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
@@ -18,13 +18,17 @@ public interface IAccountsClientService
|
||||
Task GetAccountProfileBackground(long id, Action<PhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null);
|
||||
Task PutAccountProfileBackground(AccountProfileBackgroundRequest data, Action<PhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
|
||||
Task DeleteAccountProfileBackground(Action? successAction = null, Action? unauthorizedAction = null);
|
||||
Task GetAccounts(AccountQueryParameters query, Action<IEnumerable<AccountResponse>>? successAction = null);
|
||||
Task GetAccounts(AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null);
|
||||
Task GetAccount(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null);
|
||||
Task PutAccountProfileInfo(AccountProfileInfoRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
|
||||
Task PatchAccountUsername(AccountUsernameRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
|
||||
Task PatchAccountEmail(AccountEmailRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
|
||||
Task PatchAccountPassword(AccountPasswordRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
|
||||
Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null);
|
||||
Task GetAccountRatedSeries(long id, SeriesRatedQueryParameters query, Action<IEnumerable<SeriesRatedResponse>>? successAction = null, Action? notFoundAction = null);
|
||||
Task GetAccountRatedPersons(long id, PersonRatedQueryParameters query, Action<IEnumerable<PersonRatedResponse>>? successAction = null, Action? notFoundAction = null);
|
||||
Task GetAccountRatedMovies(long id, MovieRatedQueryParameters? query = null, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null);
|
||||
Task GetAccountRatedSeries(long id, SeriesRatedQueryParameters? query = null, Action<IEnumerable<SeriesRatedResponse>>? successAction = null, Action? notFoundAction = null);
|
||||
Task GetAccountRatedPersons(long id, PersonRatedQueryParameters? query = null, Action<IEnumerable<PersonRatedResponse>>? successAction = null, Action? notFoundAction = null);
|
||||
Task GetAccountFollows(long id, AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null, Action? notFoundAction = null);
|
||||
Task GetAccountFollowers(long id, AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null, Action? notFoundAction = null);
|
||||
Task PostAccountFollow(long userId, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
|
||||
Task DeleteAccountFollow(long userId, Action? successAction = null, Action? unauthorizedAction = null);
|
||||
}
|
||||
@@ -22,4 +22,8 @@ public class Accounts
|
||||
public string GetAccountRatedMovies { get; set; }
|
||||
public string GetAccountRatedSeries { get; set; }
|
||||
public string GetAccountRatedPersons { get; set; }
|
||||
public string GetAccountFollows { get; set; }
|
||||
public string GetAccountFollowers { get; set; }
|
||||
public string PostAccountFollow { get; set; }
|
||||
public string DeleteAccountFollow { get; set; }
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
|
||||
<!-- CSS -->
|
||||
<link rel="stylesheet" href="css/general.css?version=0.3.0.5"/>
|
||||
<link rel="stylesheet" href="css/general.css?version=0.5.0.0"/>
|
||||
<link rel="stylesheet" href="css/panel.css?version=0.3.0.5"/>
|
||||
<link rel="stylesheet" href="css/main_button.css?version=0.3.0.0"/>
|
||||
<link rel="stylesheet" href="css/gaps.css?version=0.3.0.1"/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<a class="text-decoration-none text-reset" href="/user/@(Item.Id)">
|
||||
<div class="d-flex align-items-center gap-4">
|
||||
<AccountPictureComponent Id="@(Item.Id)"
|
||||
Size="90"/>
|
||||
Size="@(PictureSize)"/>
|
||||
<h4 class="fw-bold">@(Item.Username)</h4>
|
||||
</div>
|
||||
</a>
|
||||
@@ -1,13 +1,14 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WatchIt.Common.Model.Accounts;
|
||||
|
||||
namespace WatchIt.Website.Components.Pages.SearchPage.Subcomponents;
|
||||
namespace WatchIt.Website.Components.Common.Subcomponents;
|
||||
|
||||
public partial class UserSearchResultItemComponent : ComponentBase
|
||||
public partial class UserListItemComponent : ComponentBase
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[Parameter] public required AccountResponse Item { get; set; }
|
||||
[Parameter] public int PictureSize { get; set; } = 90;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
@using Blazorise.Extensions
|
||||
@using WatchIt.Website.Components.Pages.SearchPage.Subcomponents
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +28,7 @@
|
||||
@{
|
||||
int iCopy = i;
|
||||
}
|
||||
<UserSearchResultItemComponent Item="@(_items[iCopy])"/>
|
||||
<UserListItemComponent Item="@(_items[iCopy])"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<div class="vstack gap-default">
|
||||
<div class="panel panel-section-header">
|
||||
<h3 class="fw-bold m-0">@(Title)</h3>
|
||||
</div>
|
||||
@if (!_loaded)
|
||||
{
|
||||
<div class="panel">
|
||||
<LoadingComponent Color="LoadingComponent.LoadingComponentColors.Light"/>
|
||||
</div>
|
||||
}
|
||||
else if (!_items.Any())
|
||||
{
|
||||
<div class="panel">
|
||||
<div class="d-flex justify-content-center">
|
||||
No items
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (AccountResponse item in _items)
|
||||
{
|
||||
<div class="panel">
|
||||
<UserListItemComponent Item="item"
|
||||
PictureSize="50"/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WatchIt.Common.Model.Accounts;
|
||||
|
||||
namespace WatchIt.Website.Components.Pages.UserPage.Panels;
|
||||
|
||||
public partial class FollowListPanelComponent : ComponentBase
|
||||
{
|
||||
#region PARAMETERS
|
||||
|
||||
[Parameter] public required string Title { get; set; }
|
||||
[Parameter] public required Func<Action<IEnumerable<AccountResponse>>, Task> DownloadItemsMethod { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
private bool _loaded;
|
||||
|
||||
private List<AccountResponse> _items = [];
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await DownloadItemsMethod.Invoke(data => _items.AddRange(data));
|
||||
|
||||
_loaded = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,29 +1,49 @@
|
||||
<div id="base" class="vstack">
|
||||
<AccountPictureComponent Class="shadow position-absolute z-1 start-50 translate-middle" Id="@(AccountProfileInfoData.Id)" Size="240"/>
|
||||
<AccountPictureComponent Class="shadow position-absolute z-1 start-50 translate-middle" Id="@(Data.Id)" Size="240"/>
|
||||
<div class="panel z-0">
|
||||
<div class="vstack gap-3">
|
||||
<div id="space" class="container-grid"></div>
|
||||
<div class="d-flex justify-content-center">
|
||||
<h3 class="fw-bold m-0">@(AccountProfileInfoData.Username)</h3>
|
||||
<h3 class="fw-bold m-0">@(Data.Username)</h3>
|
||||
</div>
|
||||
@if (!string.IsNullOrWhiteSpace(AccountProfileInfoData.Description))
|
||||
@if (!string.IsNullOrWhiteSpace(Data.Description))
|
||||
{
|
||||
<span class="text-center w-100 mb-2">
|
||||
@(AccountProfileInfoData.Description)
|
||||
@(Data.Description)
|
||||
</span>
|
||||
}
|
||||
<div class="d-flex flex-wrap justify-content-center metadata-pill-container">
|
||||
<div class="metadata-pill"><strong>Email:</strong> @(AccountProfileInfoData.Email)</div>
|
||||
@if (!string.IsNullOrWhiteSpace(AccountProfileInfoData.Gender?.Name))
|
||||
<div class="metadata-pill"><strong>Email:</strong> @(Data.Email)</div>
|
||||
@if (!string.IsNullOrWhiteSpace(Data.Gender?.Name))
|
||||
{
|
||||
<div class="metadata-pill"><strong>Gender:</strong> @(AccountProfileInfoData.Gender?.Name)</div>
|
||||
<div class="metadata-pill"><strong>Gender:</strong> @(Data.Gender?.Name)</div>
|
||||
}
|
||||
<div class="metadata-pill"><strong>Account created:</strong> @(AccountProfileInfoData.CreationDate.ToShortDateString())</div>
|
||||
<div class="metadata-pill"><strong>Last active:</strong> @(AccountProfileInfoData.LastActive.ToShortDateString())</div>
|
||||
@if (AccountProfileInfoData.IsAdmin)
|
||||
<div class="metadata-pill"><strong>Joined:</strong> @(Data.CreationDate.ToShortDateString())</div>
|
||||
<div class="metadata-pill"><strong>Last active:</strong> @(Data.LastActive.ToShortDateString())</div>
|
||||
@if (Data.IsAdmin)
|
||||
{
|
||||
<div class="metadata-pill"><strong>Admin</strong></div>
|
||||
}
|
||||
@if (LoggedUserData is not null && Data.Id != LoggedUserData.Id)
|
||||
{
|
||||
<div role="button" class="metadata-pill @(!_followLoading ? "metadata-pill-hoverable" : string.Empty)" @onclick="@(Follow)">
|
||||
@if (_followLoading)
|
||||
{
|
||||
<div class="spinner-border spinner-border-sm"></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Followers.Any(x => x.Id == LoggedUserData.Id))
|
||||
{
|
||||
<span><i class="fa fa-eye-slash" aria-hidden="true"></i> Unfollow</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span><i class="fa fa-eye" aria-hidden="true"></i> Follow</span>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,6 @@ public partial class UserPageHeaderPanelComponent : ComponentBase
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
[Inject] private IAuthenticationService AuthenticationService { get; set; } = default!;
|
||||
[Inject] private IAccountsClientService AccountsClientService { get; set; } = default!;
|
||||
|
||||
#endregion
|
||||
@@ -18,7 +17,10 @@ public partial class UserPageHeaderPanelComponent : ComponentBase
|
||||
|
||||
#region PARAMETERS
|
||||
|
||||
[Parameter] public required AccountResponse AccountProfileInfoData { get; set; }
|
||||
[Parameter] public required AccountResponse Data { get; set; }
|
||||
[Parameter] public required List<AccountResponse> Followers { get; set; }
|
||||
[Parameter] public AccountResponse? LoggedUserData { get; set; }
|
||||
[Parameter] public Action<bool>? FollowingChanged { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -26,7 +28,7 @@ public partial class UserPageHeaderPanelComponent : ComponentBase
|
||||
|
||||
#region FIELDS
|
||||
|
||||
private AccountProfilePictureResponse? _accountProfilePicture;
|
||||
private bool _followLoading;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -34,22 +36,26 @@ public partial class UserPageHeaderPanelComponent : ComponentBase
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
private async Task Follow()
|
||||
{
|
||||
if (firstRender)
|
||||
_followLoading = true;
|
||||
if (Followers.Any(x => x.Id == LoggedUserData!.Id))
|
||||
{
|
||||
List<Task> endTasks = new List<Task>();
|
||||
|
||||
// STEP 0
|
||||
endTasks.AddRange(
|
||||
[
|
||||
AccountsClientService.GetAccountProfilePicture(AccountProfileInfoData.Id, data => _accountProfilePicture = data),
|
||||
]);
|
||||
|
||||
// END
|
||||
await Task.WhenAll(endTasks);
|
||||
|
||||
StateHasChanged();
|
||||
await AccountsClientService.DeleteAccountFollow(Data.Id, () =>
|
||||
{
|
||||
Followers.RemoveAll(x => x.Id == LoggedUserData!.Id);
|
||||
FollowingChanged?.Invoke(false);
|
||||
_followLoading = false;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await AccountsClientService.PostAccountFollow(Data.Id, () =>
|
||||
{
|
||||
Followers.Add(LoggedUserData);
|
||||
FollowingChanged?.Invoke(true);
|
||||
_followLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,12 @@
|
||||
{
|
||||
<div class="row mt-header">
|
||||
<div class="col">
|
||||
<UserPageHeaderPanelComponent AccountProfileInfoData="@(_accountData)"/>
|
||||
<UserPageHeaderPanelComponent Data="@(_accountData)"
|
||||
Followers="@(_followers)"
|
||||
LoggedUserData="@(_loggedUserData)"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-over-panel-menu">
|
||||
<div class="row mt-default">
|
||||
<div class="col">
|
||||
<Tabs Pills
|
||||
RenderMode="TabsRenderMode.LazyLoad"
|
||||
@@ -62,6 +64,8 @@
|
||||
<Tab Name="movies">Movies</Tab>
|
||||
<Tab Name="series">TV Series</Tab>
|
||||
<Tab Name="people">People</Tab>
|
||||
<Tab Name="follows">Follows</Tab>
|
||||
<Tab Name="followers">Followers</Tab>
|
||||
</Items>
|
||||
<Content>
|
||||
<TabPanel Name="summary">
|
||||
@@ -176,6 +180,18 @@
|
||||
</ListComponent>
|
||||
</div>
|
||||
</TabPanel>
|
||||
<TabPanel Name="follows">
|
||||
<div class="mt-default">
|
||||
<FollowListPanelComponent Title="Follows"
|
||||
DownloadItemsMethod="action => AccountsClientService.GetAccountFollows(_accountData.Id, successAction: action)"/>
|
||||
</div>
|
||||
</TabPanel>
|
||||
<TabPanel Name="followers">
|
||||
<div class="mt-default">
|
||||
<FollowListPanelComponent Title="Followers"
|
||||
DownloadItemsMethod="action => AccountsClientService.GetAccountFollowers(_accountData.Id, successAction: action)"/>
|
||||
</div>
|
||||
</TabPanel>
|
||||
</Content>
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
@@ -38,7 +38,11 @@ public partial class UserPage : ComponentBase
|
||||
private bool _loaded;
|
||||
private bool _redirection;
|
||||
private bool _owner;
|
||||
private User? _user;
|
||||
|
||||
private AccountResponse? _loggedUserData;
|
||||
private AccountResponse? _accountData;
|
||||
private List<AccountResponse> _followers;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -66,8 +70,13 @@ public partial class UserPage : ComponentBase
|
||||
await Task.WhenAll(step1Tasks);
|
||||
endTasks.AddRange(
|
||||
[
|
||||
AccountsClientService.GetAccountProfileBackground(_accountData.Id, data => Layout.BackgroundPhoto = data)
|
||||
AccountsClientService.GetAccountProfileBackground(_accountData.Id, data => Layout.BackgroundPhoto = data),
|
||||
AccountsClientService.GetAccountFollowers(_accountData.Id, successAction: data => _followers = data.ToList())
|
||||
]);
|
||||
if (_user is not null)
|
||||
{
|
||||
endTasks.Add(AccountsClientService.GetAccount(_user.Id, data => _loggedUserData = data));
|
||||
}
|
||||
|
||||
// END
|
||||
await Task.WhenAll(endTasks);
|
||||
@@ -79,20 +88,20 @@ public partial class UserPage : ComponentBase
|
||||
|
||||
private async Task GetUserData()
|
||||
{
|
||||
User? user = await AuthenticationService.GetUserAsync();
|
||||
_user = await AuthenticationService.GetUserAsync();
|
||||
if (!Id.HasValue)
|
||||
{
|
||||
if (user is null)
|
||||
if (_user is null)
|
||||
{
|
||||
NavigationManager.NavigateTo($"/auth?redirect_to={WebUtility.UrlEncode("/user")}");
|
||||
_redirection = true;
|
||||
return;
|
||||
}
|
||||
Id = user.Id;
|
||||
Id = _user.Id;
|
||||
}
|
||||
|
||||
await AccountsClientService.GetAccount(Id.Value, data => _accountData = data);
|
||||
_owner = Id.Value == user?.Id;
|
||||
_owner = Id.Value == _user?.Id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,11 @@
|
||||
"PatchAccountPassword": "/password",
|
||||
"GetAccountRatedMovies": "/{0}/movies",
|
||||
"GetAccountRatedSeries": "/{0}/series",
|
||||
"GetAccountRatedPersons": "/{0}/persons"
|
||||
"GetAccountRatedPersons": "/{0}/persons",
|
||||
"GetAccountFollows": "/{0}/follows",
|
||||
"GetAccountFollowers": "/{0}/followers",
|
||||
"PostAccountFollow": "/follows/{0}",
|
||||
"DeleteAccountFollow": "/follows/{0}"
|
||||
},
|
||||
"Genders": {
|
||||
"Base": "/genders",
|
||||
|
||||
@@ -66,6 +66,11 @@ body, html {
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.metadata-pill-hoverable:hover {
|
||||
background-color: gray;
|
||||
color: black;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user