Merge pull request #172 from mateuszskoczek/features/followers

Features/followers
This commit is contained in:
2024-11-10 14:50:15 +01:00
committed by GitHub
Unverified
40 changed files with 5142 additions and 142 deletions

View File

@@ -6,7 +6,4 @@ public class Genre
{ {
[JsonPropertyName("name")] [JsonPropertyName("name")]
public required string Name { get; set; } public required string Name { get; set; }
[JsonPropertyName("description")]
public string? Description { get; set; }
} }

View File

@@ -10,9 +10,6 @@ public class GenreQueryParameters : QueryParameters<GenreResponse>
[FromQuery(Name = "name")] [FromQuery(Name = "name")]
public string? Name { get; set; } public string? Name { get; set; }
[FromQuery(Name = "description")]
public string? Description { get; set; }
#endregion #endregion
@@ -22,8 +19,6 @@ public class GenreQueryParameters : QueryParameters<GenreResponse>
protected override bool IsMeetingConditions(GenreResponse item) => protected override bool IsMeetingConditions(GenreResponse item) =>
( (
TestStringWithRegex(item.Name, Name) TestStringWithRegex(item.Name, Name)
&&
TestStringWithRegex(item.Description, Description)
); );
#endregion #endregion

View File

@@ -7,13 +7,11 @@ public class GenreRequest : Genre
public Database.Model.Common.Genre CreateGenre() => new Database.Model.Common.Genre public Database.Model.Common.Genre CreateGenre() => new Database.Model.Common.Genre
{ {
Name = Name, Name = Name,
Description = Description,
}; };
public void UpdateGenre(Database.Model.Common.Genre genre) public void UpdateGenre(Database.Model.Common.Genre genre)
{ {
genre.Name = Name; genre.Name = Name;
genre.Description = Description;
} }
#endregion #endregion

View File

@@ -12,8 +12,7 @@ public class GenreResponse : Genre, IQueryOrderable<GenreResponse>
public static IDictionary<string, Func<GenreResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<GenreResponse, IComparable>> public static IDictionary<string, Func<GenreResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<GenreResponse, IComparable>>
{ {
{ "id", x => x.Id }, { "id", x => x.Id },
{ "name", x => x.Name }, { "name", x => x.Name }
{ "description", x => x.Description }
}; };
@@ -34,7 +33,6 @@ public class GenreResponse : Genre, IQueryOrderable<GenreResponse>
{ {
Id = genre.Id; Id = genre.Id;
Name = genre.Name; Name = genre.Name;
Description = genre.Description;
} }
#endregion #endregion

View File

@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Account;
namespace WatchIt.Database.Model.Configuration.Account;
public class AccountFollowConfiguration : IEntityTypeConfiguration<AccountFollow>
{
public void Configure(EntityTypeBuilder<AccountFollow> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.HasOne(x => x.AccountFollower)
.WithMany(x => x.AccountFollows)
.HasForeignKey(x => x.AccountFollowerId)
.IsRequired();
builder.Property(x => x.AccountFollowerId)
.IsRequired();
builder.HasOne(x => x.AccountFollowed)
.WithMany(x => x.AccountFollowers)
.HasForeignKey(x => x.AccountFollowedId)
.IsRequired();
builder.Property(x => x.AccountFollowedId)
.IsRequired();
}
}

View File

@@ -20,9 +20,6 @@ public class GenreConfiguration : IEntityTypeConfiguration<Genre>
.HasMaxLength(100) .HasMaxLength(100)
.IsRequired(); .IsRequired();
builder.Property(x => x.Description)
.HasMaxLength(1000);
// Navigation // Navigation
builder.HasMany(x => x.Media) builder.HasMany(x => x.Media)
.WithMany(x => x.Genres) .WithMany(x => x.Genres)

View File

@@ -39,6 +39,9 @@ public class Account
public virtual IEnumerable<RatingMediaSeriesEpisode> RatingMediaSeriesEpisode { get; set; } = new List<RatingMediaSeriesEpisode>(); public virtual IEnumerable<RatingMediaSeriesEpisode> RatingMediaSeriesEpisode { get; set; } = new List<RatingMediaSeriesEpisode>();
public virtual IEnumerable<AccountRefreshToken> AccountRefreshTokens { get; set; } = new List<AccountRefreshToken>(); public virtual IEnumerable<AccountRefreshToken> AccountRefreshTokens { get; set; } = new List<AccountRefreshToken>();
public virtual IEnumerable<AccountFollow> AccountFollows { get; set; } = new List<AccountFollow>();
public virtual IEnumerable<AccountFollow> AccountFollowers { get; set; } = new List<AccountFollow>();
#endregion #endregion
} }

View File

@@ -0,0 +1,21 @@
namespace WatchIt.Database.Model.Account;
public class AccountFollow
{
#region PROPERTIES
public Guid Id { get; set; }
public long AccountFollowerId { get; set; }
public long AccountFollowedId { get; set; }
#endregion
#region NAVIGATION
public virtual Account AccountFollower { get; set; } = null!;
public virtual Account AccountFollowed { get; set; } = null!;
#endregion
}

View File

@@ -8,7 +8,6 @@ public class Genre
public short Id { get; set; } public short Id { get; set; }
public required string Name { get; set; } public required string Name { get; set; }
public string? Description { get; set; }
#endregion #endregion

View File

@@ -40,6 +40,7 @@ public class DatabaseContext : DbContext
// Account // Account
public virtual DbSet<Account> Accounts { get; set; } public virtual DbSet<Account> Accounts { get; set; }
public virtual DbSet<AccountFollow> AccountFollows { get; set; }
public virtual DbSet<AccountProfilePicture> AccountProfilePictures { get; set; } public virtual DbSet<AccountProfilePicture> AccountProfilePictures { get; set; }
public virtual DbSet<AccountRefreshToken> AccountRefreshTokens { get; set; } public virtual DbSet<AccountRefreshToken> AccountRefreshTokens { get; set; }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,78 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WatchIt.Database.Migrations
{
/// <inheritdoc />
public partial class GenreDescriptionRemoved : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Description",
table: "Genres");
migrationBuilder.UpdateData(
table: "Accounts",
keyColumn: "Id",
keyValue: 1L,
columns: new[] { "LeftSalt", "Password", "RightSalt" },
values: new object[] { "HIZYSU/94oe$[jAy\\{7V", new byte[] { 118, 180, 133, 0, 25, 6, 65, 230, 20, 221, 180, 8, 111, 189, 191, 158, 98, 160, 80, 196, 146, 99, 90, 55, 196, 219, 245, 244, 167, 89, 123, 74, 37, 92, 234, 81, 74, 199, 149, 128, 7, 213, 202, 191, 162, 62, 19, 144, 206, 83, 80, 237, 37, 179, 12, 215, 61, 179, 94, 189, 30, 98, 100, 164 }, "#(^8YBkY;<X=LKE_7$2p" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Description",
table: "Genres",
type: "character varying(1000)",
maxLength: 1000,
nullable: true);
migrationBuilder.UpdateData(
table: "Accounts",
keyColumn: "Id",
keyValue: 1L,
columns: new[] { "LeftSalt", "Password", "RightSalt" },
values: new object[] { "YuJiv1\"R'*0odl8${\\|S", new byte[] { 215, 154, 186, 191, 12, 223, 76, 105, 137, 67, 41, 138, 26, 3, 38, 36, 0, 71, 40, 84, 153, 152, 105, 239, 55, 60, 164, 15, 99, 175, 133, 175, 227, 245, 102, 9, 171, 119, 16, 234, 97, 179, 70, 29, 120, 112, 241, 91, 209, 91, 228, 164, 52, 244, 36, 207, 147, 60, 124, 66, 77, 252, 129, 151 }, "oT2N=y7^5,2o'+N>d}~!" });
migrationBuilder.UpdateData(
table: "Genres",
keyColumn: "Id",
keyValue: (short)1,
column: "Description",
value: null);
migrationBuilder.UpdateData(
table: "Genres",
keyColumn: "Id",
keyValue: (short)2,
column: "Description",
value: null);
migrationBuilder.UpdateData(
table: "Genres",
keyColumn: "Id",
keyValue: (short)3,
column: "Description",
value: null);
migrationBuilder.UpdateData(
table: "Genres",
keyColumn: "Id",
keyValue: (short)4,
column: "Description",
value: null);
migrationBuilder.UpdateData(
table: "Genres",
keyColumn: "Id",
keyValue: (short)5,
column: "Description",
value: null);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WatchIt.Database.Migrations
{
/// <inheritdoc />
public partial class AccountFollowAdded : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AccountFollow",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
AccountFollowerId = table.Column<long>(type: "bigint", nullable: false),
AccountFollowedId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AccountFollow", x => x.Id);
table.ForeignKey(
name: "FK_AccountFollow_Accounts_AccountFollowedId",
column: x => x.AccountFollowedId,
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AccountFollow_Accounts_AccountFollowerId",
column: x => x.AccountFollowerId,
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
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.CreateIndex(
name: "IX_AccountFollow_AccountFollowedId",
table: "AccountFollow",
column: "AccountFollowedId");
migrationBuilder.CreateIndex(
name: "IX_AccountFollow_AccountFollowerId",
table: "AccountFollow",
column: "AccountFollowerId");
migrationBuilder.CreateIndex(
name: "IX_AccountFollow_Id",
table: "AccountFollow",
column: "Id",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AccountFollow");
migrationBuilder.UpdateData(
table: "Accounts",
keyColumn: "Id",
keyValue: 1L,
columns: new[] { "LeftSalt", "Password", "RightSalt" },
values: new object[] { "HIZYSU/94oe$[jAy\\{7V", new byte[] { 118, 180, 133, 0, 25, 6, 65, 230, 20, 221, 180, 8, 111, 189, 191, 158, 98, 160, 80, 196, 146, 99, 90, 55, 196, 219, 245, 244, 167, 89, 123, 74, 37, 92, 234, 81, 74, 199, 149, 128, 7, 213, 202, 191, 162, 62, 19, 144, 206, 83, 80, 237, 37, 179, 12, 215, 61, 179, 94, 189, 30, 98, 100, 164 }, "#(^8YBkY;<X=LKE_7$2p" });
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -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);
}
}
}

View File

@@ -108,13 +108,37 @@ namespace WatchIt.Database.Migrations
Email = "root@watch.it", Email = "root@watch.it",
IsAdmin = true, IsAdmin = true,
LastActive = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), LastActive = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
LeftSalt = "YuJiv1\"R'*0odl8${\\|S", LeftSalt = "QkJky0:m43g!mRL_-0S'",
Password = new byte[] { 215, 154, 186, 191, 12, 223, 76, 105, 137, 67, 41, 138, 26, 3, 38, 36, 0, 71, 40, 84, 153, 152, 105, 239, 55, 60, 164, 15, 99, 175, 133, 175, 227, 245, 102, 9, 171, 119, 16, 234, 97, 179, 70, 29, 120, 112, 241, 91, 209, 91, 228, 164, 52, 244, 36, 207, 147, 60, 124, 66, 77, 252, 129, 151 }, 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 = "oT2N=y7^5,2o'+N>d}~!", RightSalt = "~-jO$aMa{Q9lAW~>)Z+Z",
Username = "root" Username = "root"
}); });
}); });
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountFollow", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<long>("AccountFollowedId")
.HasColumnType("bigint");
b.Property<long>("AccountFollowerId")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("AccountFollowedId");
b.HasIndex("AccountFollowerId");
b.HasIndex("Id")
.IsUnique();
b.ToTable("AccountFollows");
});
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b => modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
@@ -249,10 +273,6 @@ namespace WatchIt.Database.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<short>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<short>("Id"));
b.Property<string>("Description")
.HasMaxLength(1000)
.HasColumnType("character varying(1000)");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasMaxLength(100) .HasMaxLength(100)
@@ -997,6 +1017,25 @@ namespace WatchIt.Database.Migrations
b.Navigation("ProfilePicture"); b.Navigation("ProfilePicture");
}); });
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountFollow", b =>
{
b.HasOne("WatchIt.Database.Model.Account.Account", "AccountFollowed")
.WithMany("AccountFollowers")
.HasForeignKey("AccountFollowedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WatchIt.Database.Model.Account.Account", "AccountFollower")
.WithMany("AccountFollows")
.HasForeignKey("AccountFollowerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("AccountFollowed");
b.Navigation("AccountFollower");
});
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountRefreshToken", b => modelBuilder.Entity("WatchIt.Database.Model.Account.AccountRefreshToken", b =>
{ {
b.HasOne("WatchIt.Database.Model.Account.Account", "Account") b.HasOne("WatchIt.Database.Model.Account.Account", "Account")
@@ -1309,6 +1348,10 @@ namespace WatchIt.Database.Migrations
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b => modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
{ {
b.Navigation("AccountFollowers");
b.Navigation("AccountFollows");
b.Navigation("AccountRefreshTokens"); b.Navigation("AccountRefreshTokens");
b.Navigation("RatingMedia"); b.Navigation("RatingMedia");

View File

@@ -135,6 +135,8 @@ public class AccountsController(IAccountsControllerService accountsControllerSer
#endregion #endregion
#region Media
[HttpGet("{id}/movies")] [HttpGet("{id}/movies")]
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(typeof(IEnumerable<MovieRatedResponse>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(IEnumerable<MovieRatedResponse>), StatusCodes.Status200OK)]
@@ -152,4 +154,35 @@ public class AccountsController(IAccountsControllerService accountsControllerSer
[ProducesResponseType(typeof(IEnumerable<PersonRatedResponse>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(IEnumerable<PersonRatedResponse>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult> GetAccountRatedPersons([FromRoute]long id, PersonRatedQueryParameters query) => await accountsControllerService.GetAccountRatedPersons(id, query); 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
} }

View File

@@ -34,14 +34,6 @@ public class GenresController(IGenresControllerService genresControllerService)
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
public async Task<ActionResult> PostGenre([FromBody]GenreRequest body) => await genresControllerService.PostGenre(body); public async Task<ActionResult> PostGenre([FromBody]GenreRequest body) => await genresControllerService.PostGenre(body);
[HttpPut("{id}")]
[Authorize]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult> PutGenre([FromRoute]short id, [FromBody]GenreRequest body) => await genresControllerService.PutGenre(id, body);
[HttpDelete("{id}")] [HttpDelete("{id}")]
[Authorize] [Authorize]
[ProducesResponseType(typeof(GenreResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(GenreResponse), StatusCodes.Status200OK)]

View File

@@ -319,6 +319,8 @@ public class AccountsControllerService(
#endregion #endregion
#region Media
public async Task<RequestResult> GetAccountRatedMovies(long id, MovieRatedQueryParameters query) public async Task<RequestResult> GetAccountRatedMovies(long id, MovieRatedQueryParameters query)
{ {
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id); Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id);
@@ -362,6 +364,79 @@ public class AccountsControllerService(
response = query.PrepareData(response); response = query.PrepareData(response);
return RequestResult.Ok(response); return RequestResult.Ok(response);
} }
#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 #endregion

View File

@@ -28,4 +28,8 @@ public interface IAccountsControllerService
Task<RequestResult> GetAccountRatedMovies(long id, MovieRatedQueryParameters query); Task<RequestResult> GetAccountRatedMovies(long id, MovieRatedQueryParameters query);
Task<RequestResult> GetAccountRatedSeries(long id, SeriesRatedQueryParameters query); Task<RequestResult> GetAccountRatedSeries(long id, SeriesRatedQueryParameters query);
Task<RequestResult> GetAccountRatedPersons(long id, PersonRatedQueryParameters 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);
} }

View File

@@ -49,26 +49,6 @@ public class GenresControllerService(DatabaseContext database, IUserService user
return RequestResult.Created($"genres/{item.Id}", new GenreResponse(item)); return RequestResult.Created($"genres/{item.Id}", new GenreResponse(item));
} }
public async Task<RequestResult> PutGenre(short id, GenreRequest data)
{
UserValidator validator = userService.GetValidator().MustBeAdmin();
if (!validator.IsValid)
{
return RequestResult.Forbidden();
}
Genre? item = await database.Genres.FirstOrDefaultAsync(x => x.Id == id);
if (item is null)
{
return RequestResult.NotFound();
}
data.UpdateGenre(item);
await database.SaveChangesAsync();
return RequestResult.Ok();
}
public async Task<RequestResult> DeleteGenre(short id) public async Task<RequestResult> DeleteGenre(short id)
{ {
UserValidator validator = userService.GetValidator().MustBeAdmin(); UserValidator validator = userService.GetValidator().MustBeAdmin();
@@ -98,14 +78,13 @@ public class GenresControllerService(DatabaseContext database, IUserService user
public async Task<RequestResult> GetGenreMedia(short id, MediaQueryParameters query) public async Task<RequestResult> GetGenreMedia(short id, MediaQueryParameters query)
{ {
if (!database.Genres.Any(x => x.Id == id)) Genre? genre = await database.Genres.FirstOrDefaultAsync(x => x.Id == id);
if (genre is null)
{ {
return RequestResult.NotFound(); return RequestResult.NotFound();
} }
IEnumerable<Database.Model.Media.Media> rawData = await database.Media.Where(x => x.MediaGenres.Any(y => y.GenreId == id)) IEnumerable<MediaResponse> data = genre.Media.Select(x => new MediaResponse(x, database.MediaMovies.Any(y => y.Id == x.Id) ? MediaType.Movie : MediaType.Series));
.ToListAsync();
IEnumerable<MediaResponse> data = rawData.Select(x => new MediaResponse(x, database.MediaMovies.Any(y => y.Id == x.Id) ? MediaType.Movie : MediaType.Series));
data = query.PrepareData(data); data = query.PrepareData(data);
return RequestResult.Ok(data); return RequestResult.Ok(data);
} }

View File

@@ -9,7 +9,6 @@ public interface IGenresControllerService
Task<RequestResult> GetGenres(GenreQueryParameters query); Task<RequestResult> GetGenres(GenreQueryParameters query);
Task<RequestResult> GetGenre(short id); Task<RequestResult> GetGenre(short id);
Task<RequestResult> PostGenre(GenreRequest data); Task<RequestResult> PostGenre(GenreRequest data);
Task<RequestResult> PutGenre(short id, GenreRequest data);
Task<RequestResult> DeleteGenre(short id); Task<RequestResult> DeleteGenre(short id);
Task<RequestResult> GetGenreMedia(short id, MediaQueryParameters query); Task<RequestResult> GetGenreMedia(short id, MediaQueryParameters query);
} }

View File

@@ -9,6 +9,5 @@ public class GenreRequestValidator : AbstractValidator<GenreRequest>
public GenreRequestValidator() public GenreRequestValidator()
{ {
RuleFor(x => x.Name).MaximumLength(100); RuleFor(x => x.Name).MaximumLength(100);
When(x => !string.IsNullOrWhiteSpace(x.Description), () => RuleFor(x => x.Description).MaximumLength(1000));
} }
} }

View File

@@ -13,6 +13,36 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
{ {
#region PUBLIC METHODS #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) public async Task Register(RegisterRequest data, Action<RegisterResponse>? createdAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null)
{ {
string url = GetUrl(EndpointsConfiguration.Accounts.Register); string url = GetUrl(EndpointsConfiguration.Accounts.Register);
@@ -69,7 +99,11 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
response.RegisterActionFor2XXSuccess(successAction) response.RegisterActionFor2XXSuccess(successAction)
.ExecuteAction(); .ExecuteAction();
} }
#endregion
#region Profile picture
public async Task GetAccountProfilePicture(long id, Action<AccountProfilePictureResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null) 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); string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountProfilePicture, id);
@@ -109,7 +143,11 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
.RegisterActionFor401Unauthorized(unauthorizedAction) .RegisterActionFor401Unauthorized(unauthorizedAction)
.ExecuteAction(); .ExecuteAction();
} }
#endregion
#region Profile background
public async Task GetAccountProfileBackground(long id, Action<PhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null) 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); string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountProfileBackground, id);
@@ -150,29 +188,9 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
.ExecuteAction(); .ExecuteAction();
} }
public async Task GetAccounts(AccountQueryParameters query, Action<IEnumerable<AccountResponse>>? successAction = null) #endregion
{
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) #region Account management
{
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();
}
public async Task PutAccountProfileInfo(AccountProfileInfoRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null) 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(); .ExecuteAction();
} }
#endregion
#region Media
public async Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null) public async Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null)
{ {
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountRatedMovies, id); string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountRatedMovies, id);
@@ -275,6 +297,63 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
.RegisterActionFor404NotFound(notFoundAction) .RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction(); .ExecuteAction();
} }
#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 #endregion

View File

@@ -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 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 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 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 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 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 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 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 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 GetAccountRatedMovies(long id, MovieRatedQueryParameters? query = null, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null);
Task GetAccountRatedSeries(long id, SeriesRatedQueryParameters query, Action<IEnumerable<SeriesRatedResponse>>? 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, Action<IEnumerable<PersonRatedResponse>>? 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);
} }

View File

@@ -22,4 +22,8 @@ public class Accounts
public string GetAccountRatedMovies { get; set; } public string GetAccountRatedMovies { get; set; }
public string GetAccountRatedSeries { get; set; } public string GetAccountRatedSeries { get; set; }
public string GetAccountRatedPersons { 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; }
} }

View File

@@ -6,7 +6,6 @@ public class Genres
public string GetGenres { get; set; } public string GetGenres { get; set; }
public string GetGenre { get; set; } public string GetGenre { get; set; }
public string PostGenre { get; set; } public string PostGenre { get; set; }
public string PutGenre { get; set; }
public string DeleteGenre { get; set; } public string DeleteGenre { get; set; }
public string GetGenreMedia { get; set; } public string GetGenreMedia { get; set; }
} }

View File

@@ -9,7 +9,7 @@
<link rel="icon" type="image/png" href="favicon.png"/> <link rel="icon" type="image/png" href="favicon.png"/>
<!-- CSS --> <!-- 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/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/main_button.css?version=0.3.0.0"/>
<link rel="stylesheet" href="css/gaps.css?version=0.3.0.1"/> <link rel="stylesheet" href="css/gaps.css?version=0.3.0.1"/>

View File

@@ -1,7 +1,7 @@
<a class="text-decoration-none text-reset" href="/user/@(Item.Id)"> <a class="text-decoration-none text-reset" href="/user/@(Item.Id)">
<div class="d-flex align-items-center gap-4"> <div class="d-flex align-items-center gap-4">
<AccountPictureComponent Id="@(Item.Id)" <AccountPictureComponent Id="@(Item.Id)"
Size="90"/> Size="@(PictureSize)"/>
<h4 class="fw-bold">@(Item.Username)</h4> <h4 class="fw-bold">@(Item.Username)</h4>
</div> </div>
</a> </a>

View File

@@ -1,13 +1,14 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Accounts; 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 #region PROPERTIES
[Parameter] public required AccountResponse Item { get; set; } [Parameter] public required AccountResponse Item { get; set; }
[Parameter] public int PictureSize { get; set; } = 90;
#endregion #endregion
} }

View File

@@ -1,5 +1,4 @@
@using Blazorise.Extensions @using Blazorise.Extensions
@using WatchIt.Website.Components.Pages.SearchPage.Subcomponents
@@ -29,7 +28,7 @@
@{ @{
int iCopy = i; int iCopy = i;
} }
<UserSearchResultItemComponent Item="@(_items[iCopy])"/> <UserListItemComponent Item="@(_items[iCopy])"/>
</div> </div>
</div> </div>
} }

View File

@@ -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>

View File

@@ -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
}

View File

@@ -1,29 +1,49 @@
<div id="base" class="vstack"> <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="panel z-0">
<div class="vstack gap-3"> <div class="vstack gap-3">
<div id="space" class="container-grid"></div> <div id="space" class="container-grid"></div>
<div class="d-flex justify-content-center"> <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> </div>
@if (!string.IsNullOrWhiteSpace(AccountProfileInfoData.Description)) @if (!string.IsNullOrWhiteSpace(Data.Description))
{ {
<span class="text-center w-100 mb-2"> <span class="text-center w-100 mb-2">
@(AccountProfileInfoData.Description) @(Data.Description)
</span> </span>
} }
<div class="d-flex flex-wrap justify-content-center metadata-pill-container"> <div class="d-flex flex-wrap justify-content-center metadata-pill-container">
<div class="metadata-pill"><strong>Email:</strong> @(AccountProfileInfoData.Email)</div> <div class="metadata-pill"><strong>Email:</strong> @(Data.Email)</div>
@if (!string.IsNullOrWhiteSpace(AccountProfileInfoData.Gender?.Name)) @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>Joined:</strong> @(Data.CreationDate.ToShortDateString())</div>
<div class="metadata-pill"><strong>Last active:</strong> @(AccountProfileInfoData.LastActive.ToShortDateString())</div> <div class="metadata-pill"><strong>Last active:</strong> @(Data.LastActive.ToShortDateString())</div>
@if (AccountProfileInfoData.IsAdmin) @if (Data.IsAdmin)
{ {
<div class="metadata-pill"><strong>Admin</strong></div> <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> </div>
</div> </div>

View File

@@ -9,7 +9,6 @@ public partial class UserPageHeaderPanelComponent : ComponentBase
{ {
#region SERVICES #region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = default!;
[Inject] private IAccountsClientService AccountsClientService { get; set; } = default!; [Inject] private IAccountsClientService AccountsClientService { get; set; } = default!;
#endregion #endregion
@@ -18,38 +17,45 @@ public partial class UserPageHeaderPanelComponent : ComponentBase
#region PARAMETERS #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 #endregion
#region FIELDS #region FIELDS
private bool _followLoading;
private AccountProfilePictureResponse? _accountProfilePicture;
#endregion #endregion
#region PRIVATE METHODS #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>(); await AccountsClientService.DeleteAccountFollow(Data.Id, () =>
{
// STEP 0 Followers.RemoveAll(x => x.Id == LoggedUserData!.Id);
endTasks.AddRange( FollowingChanged?.Invoke(false);
[ _followLoading = false;
AccountsClientService.GetAccountProfilePicture(AccountProfileInfoData.Id, data => _accountProfilePicture = data), });
]); }
else
// END {
await Task.WhenAll(endTasks); await AccountsClientService.PostAccountFollow(Data.Id, () =>
{
StateHasChanged(); Followers.Add(LoggedUserData);
FollowingChanged?.Invoke(true);
_followLoading = false;
});
} }
} }

View File

@@ -48,10 +48,12 @@
{ {
<div class="row mt-header"> <div class="row mt-header">
<div class="col"> <div class="col">
<UserPageHeaderPanelComponent AccountProfileInfoData="@(_accountData)"/> <UserPageHeaderPanelComponent Data="@(_accountData)"
Followers="@(_followers)"
LoggedUserData="@(_loggedUserData)"/>
</div> </div>
</div> </div>
<div class="row mt-over-panel-menu"> <div class="row mt-default">
<div class="col"> <div class="col">
<Tabs Pills <Tabs Pills
RenderMode="TabsRenderMode.LazyLoad" RenderMode="TabsRenderMode.LazyLoad"
@@ -62,6 +64,8 @@
<Tab Name="movies">Movies</Tab> <Tab Name="movies">Movies</Tab>
<Tab Name="series">TV Series</Tab> <Tab Name="series">TV Series</Tab>
<Tab Name="people">People</Tab> <Tab Name="people">People</Tab>
<Tab Name="follows">Follows</Tab>
<Tab Name="followers">Followers</Tab>
</Items> </Items>
<Content> <Content>
<TabPanel Name="summary"> <TabPanel Name="summary">
@@ -160,22 +164,34 @@
PictureDownloadingTask="@((id, action) => PersonsClientService.GetPersonPhoto(id, action))" PictureDownloadingTask="@((id, action) => PersonsClientService.GetPersonPhoto(id, action))"
ItemDownloadingTask="@((query, action) => AccountsClientService.GetAccountRatedPersons(_accountData.Id, query, action))" ItemDownloadingTask="@((query, action) => AccountsClientService.GetAccountRatedPersons(_accountData.Id, query, action))"
SortingOptions="@(new Dictionary<string, string> SortingOptions="@(new Dictionary<string, string>
{ {
{ "user_rating.average", "Average user rating" }, { "user_rating.average", "Average user rating" },
{ "user_rating.count", "Number of user ratings" }, { "user_rating.count", "Number of user ratings" },
{ "user_rating_last_date", "User rating date" }, { "user_rating_last_date", "User rating date" },
{ "rating.average", "Average rating" }, { "rating.average", "Average rating" },
{ "rating.count", "Number of ratings" }, { "rating.count", "Number of ratings" },
{ "name", "Name" }, { "name", "Name" },
{ "birth_date", "Birth date" }, { "birth_date", "Birth date" },
{ "death_date", "Death date" }, { "death_date", "Death date" },
})" })"
PosterPlaceholder="/assets/person_poster.png" PosterPlaceholder="/assets/person_poster.png"
GetGlobalRatingMethod="@((id, action) => PersonsClientService.GetPersonGlobalRating(id, action))"> GetGlobalRatingMethod="@((id, action) => PersonsClientService.GetPersonGlobalRating(id, action))">
<PersonsRatedFilterFormComponent/> <PersonsRatedFilterFormComponent/>
</ListComponent> </ListComponent>
</div> </div>
</TabPanel> </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> </Content>
</Tabs> </Tabs>
</div> </div>

View File

@@ -38,7 +38,11 @@ public partial class UserPage : ComponentBase
private bool _loaded; private bool _loaded;
private bool _redirection; private bool _redirection;
private bool _owner; private bool _owner;
private User? _user;
private AccountResponse? _loggedUserData;
private AccountResponse? _accountData; private AccountResponse? _accountData;
private List<AccountResponse> _followers;
#endregion #endregion
@@ -66,8 +70,13 @@ public partial class UserPage : ComponentBase
await Task.WhenAll(step1Tasks); await Task.WhenAll(step1Tasks);
endTasks.AddRange( 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 // END
await Task.WhenAll(endTasks); await Task.WhenAll(endTasks);
@@ -79,20 +88,20 @@ public partial class UserPage : ComponentBase
private async Task GetUserData() private async Task GetUserData()
{ {
User? user = await AuthenticationService.GetUserAsync(); _user = await AuthenticationService.GetUserAsync();
if (!Id.HasValue) if (!Id.HasValue)
{ {
if (user is null) if (_user is null)
{ {
NavigationManager.NavigateTo($"/auth?redirect_to={WebUtility.UrlEncode("/user")}"); NavigationManager.NavigateTo($"/auth?redirect_to={WebUtility.UrlEncode("/user")}");
_redirection = true; _redirection = true;
return; return;
} }
Id = user.Id; Id = _user.Id;
} }
await AccountsClientService.GetAccount(Id.Value, data => _accountData = data); await AccountsClientService.GetAccount(Id.Value, data => _accountData = data);
_owner = Id.Value == user?.Id; _owner = Id.Value == _user?.Id;
} }

View File

@@ -35,7 +35,11 @@
"PatchAccountPassword": "/password", "PatchAccountPassword": "/password",
"GetAccountRatedMovies": "/{0}/movies", "GetAccountRatedMovies": "/{0}/movies",
"GetAccountRatedSeries": "/{0}/series", "GetAccountRatedSeries": "/{0}/series",
"GetAccountRatedPersons": "/{0}/persons" "GetAccountRatedPersons": "/{0}/persons",
"GetAccountFollows": "/{0}/follows",
"GetAccountFollowers": "/{0}/followers",
"PostAccountFollow": "/follows/{0}",
"DeleteAccountFollow": "/follows/{0}"
}, },
"Genders": { "Genders": {
"Base": "/genders", "Base": "/genders",
@@ -49,7 +53,6 @@
"GetGenres": "", "GetGenres": "",
"GetGenre": "/{0}", "GetGenre": "/{0}",
"PostGenre": "", "PostGenre": "",
"PutGenre": "/{0}",
"DeleteGenre": "/{0}", "DeleteGenre": "/{0}",
"GetGenreMedia": "/{0}/media" "GetGenreMedia": "/{0}/media"
}, },

View File

@@ -66,6 +66,11 @@ body, html {
gap: 1rem; gap: 1rem;
} }
.metadata-pill-hoverable:hover {
background-color: gray;
color: black;
}