database changes
This commit is contained in:
@@ -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; }
|
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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.AccountFollowedBy)
|
||||||
|
.HasForeignKey(x => x.AccountFollowedId)
|
||||||
|
.IsRequired();
|
||||||
|
builder.Property(x => x.AccountFollowedId)
|
||||||
|
.IsRequired();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -40,5 +40,8 @@ public class Account
|
|||||||
|
|
||||||
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> AccountFollowedBy { get; set; } = new List<AccountFollow>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
1412
WatchIt.Database/WatchIt.Database/Migrations/20241108200642_GenreDescriptionRemoved.Designer.cs
generated
Normal file
1412
WatchIt.Database/WatchIt.Database/Migrations/20241108200642_GenreDescriptionRemoved.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1459
WatchIt.Database/WatchIt.Database/Migrations/20241108211519_AccountFollowAdded.Designer.cs
generated
Normal file
1459
WatchIt.Database/WatchIt.Database/Migrations/20241108211519_AccountFollowAdded.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 = "sfA:fW!3D=GbwXn]X+rm",
|
||||||
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[] { 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 = "oT2N=y7^5,2o'+N>d}~!",
|
RightSalt = "@$rr>fSvr5Ls|D+Wp;?D",
|
||||||
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("AccountFollow");
|
||||||
|
});
|
||||||
|
|
||||||
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("AccountFollowedBy")
|
||||||
|
.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("AccountFollowedBy");
|
||||||
|
|
||||||
|
b.Navigation("AccountFollows");
|
||||||
|
|
||||||
b.Navigation("AccountRefreshTokens");
|
b.Navigation("AccountRefreshTokens");
|
||||||
|
|
||||||
b.Navigation("RatingMedia");
|
b.Navigation("RatingMedia");
|
||||||
|
|||||||
@@ -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)]
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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; }
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,6 @@
|
|||||||
"GetGenres": "",
|
"GetGenres": "",
|
||||||
"GetGenre": "/{0}",
|
"GetGenre": "/{0}",
|
||||||
"PostGenre": "",
|
"PostGenre": "",
|
||||||
"PutGenre": "/{0}",
|
|
||||||
"DeleteGenre": "/{0}",
|
"DeleteGenre": "/{0}",
|
||||||
"GetGenreMedia": "/{0}/media"
|
"GetGenreMedia": "/{0}/media"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user