diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRole.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRole.cs index 446ad2f..22812dd 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRole.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRole.cs @@ -7,16 +7,16 @@ public class ActorRole #region PROPERTIES [JsonPropertyName("type_id")] - public required short TypeId { get; set; } + public short TypeId { get; set; } [JsonPropertyName("name")] - public required string Name { get; set; } + public string Name { get; set; } [JsonPropertyName("media_id")] - public required long MediaId { get; set; } + public long MediaId { get; set; } [JsonPropertyName("person_id")] - public required long PersonId { get; set; } + public long PersonId { get; set; } #endregion } \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleRequest.cs index c51f77c..747ec73 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleRequest.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleRequest.cs @@ -1,9 +1,27 @@ +using System.Diagnostics.CodeAnalysis; using WatchIt.Database.Model.Person; namespace WatchIt.Common.Model.Roles; public class ActorRoleRequest : ActorRole, IActorRoleMediaRequest, IActorRolePersonRequest { + #region CONSTRUCTORS + + [SetsRequiredMembers] + public ActorRoleRequest(ActorRoleResponse data) + { + Name = data.Name; + PersonId = data.PersonId; + MediaId = data.MediaId; + TypeId = data.TypeId; + } + + public ActorRoleRequest() {} + + #endregion + + + #region PUBLIC METHODS PersonActorRole IActorRoleMediaRequest.CreateActorRole(long mediaId) diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeResponse.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeResponse.cs index 56629e6..2b3dbe6 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeResponse.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeResponse.cs @@ -16,7 +16,7 @@ public class RoleTypeResponse : RoleType, IQueryOrderable [JsonPropertyName("id")] - public required short? Id { get; set; } + public required short Id { get; set; } #endregion diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs index ee25ae1..650141b 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs @@ -38,6 +38,11 @@ public class MediaController : ControllerBase #region Main + [HttpGet] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + public async Task GetAllMedia(MediaQueryParameters query) => await _mediaControllerService.GetAllMedia(query); + [HttpGet("{id}")] [AllowAnonymous] [ProducesResponseType(typeof(MediaResponse), StatusCodes.Status200OK)] diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/IMediaControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/IMediaControllerService.cs index 390a831..4dff60c 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/IMediaControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/IMediaControllerService.cs @@ -8,6 +8,7 @@ namespace WatchIt.WebAPI.Services.Controllers.Media; public interface IMediaControllerService { + Task GetAllMedia(MediaQueryParameters query); Task GetMedia(long mediaId); Task GetMediaGenres(long mediaId); diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/MediaControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/MediaControllerService.cs index 9d34b84..cc25650 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/MediaControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/MediaControllerService.cs @@ -21,6 +21,14 @@ public class MediaControllerService(DatabaseContext database, IUserService userS #region Main + public async Task GetAllMedia(MediaQueryParameters query) + { + IEnumerable rawData = await database.Media.ToListAsync(); + IEnumerable data = rawData.Select(x => new MediaResponse(x, database.MediaMovies.Any(y => y.Id == x.Id) ? MediaType.Movie : MediaType.Series)); + data = query.PrepareData(data); + return RequestResult.Ok(data); + } + public async Task GetMedia(long mediaId) { Database.Model.Media.Media? item = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Media.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Media.cs index fa20a8d..a7ae025 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Media.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Media.cs @@ -3,6 +3,7 @@ public class Media { public string Base { get; set; } + public string GetAllMedia { get; set; } public string GetMedia { get; set; } public string GetMediaGenres { get; set; } public string PostMediaGenre { get; set; } diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/IMediaWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/IMediaWebAPIService.cs index 86a9dee..ec33625 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/IMediaWebAPIService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/IMediaWebAPIService.cs @@ -8,6 +8,7 @@ namespace WatchIt.Website.Services.WebAPI.Media; public interface IMediaWebAPIService { + Task GetAllMedia(MediaQueryParameters? query = null, Action>? successAction = null); Task GetMedia(long mediaId, Action? successAction = null, Action? notFoundAction = null); Task GetMediaGenres(long mediaId, Action>? successAction = null, Action? notFoundAction = null); diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/MediaWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/MediaWebAPIService.cs index 4ec059a..0098bd6 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/MediaWebAPIService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/MediaWebAPIService.cs @@ -35,6 +35,18 @@ public class MediaWebAPIService : BaseWebAPIService, IMediaWebAPIService #region Main + public async Task GetAllMedia(MediaQueryParameters? query = null, Action>? successAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.GetAllMedia); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + request.Query = query; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .ExecuteAction(); + } + public async Task GetMedia(long mediaId, Action? successAction = null, Action? notFoundAction = null) { string url = GetUrl(EndpointsConfiguration.Media.GetMedia, mediaId); diff --git a/WatchIt.Website/WatchIt.Website/App.razor b/WatchIt.Website/WatchIt.Website/App.razor index fb9b08f..059458f 100644 --- a/WatchIt.Website/WatchIt.Website/App.razor +++ b/WatchIt.Website/WatchIt.Website/App.razor @@ -9,8 +9,8 @@ - - + + diff --git a/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonEditFormComponent.razor b/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonEditFormComponent.razor index c365b9d..24d0157 100644 --- a/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonEditFormComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonEditFormComponent.razor @@ -45,7 +45,7 @@ -
+
@if (!string.IsNullOrWhiteSpace(_error)) { diff --git a/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonRolesEditActorComponent.razor b/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonRolesEditActorComponent.razor new file mode 100644 index 0000000..95c812a --- /dev/null +++ b/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonRolesEditActorComponent.razor @@ -0,0 +1,117 @@ +@using Blazorise.Extensions +@using WatchIt.Common.Model.Roles + + + +
+ @if (_loaded) + { +
+
+
+
+

Actor roles

+
+ @if (!_editingMode) + { +
+ +
+ } + else + { +
+ +
+
+ +
+ } +
+
+ @if (!_editingMode) + { + if (_roles.IsNullOrEmpty()) + { + No items + } + else + { + + + + + + + + + + + + @foreach (Guid roleId in _roles.Keys) + { + + + + + + + + } + +
+ Media name + + Media type + + Role type + + Role name + + Actions +
+ @(Media[_roles[roleId].Data.MediaId].Title)@(Media[_roles[roleId].Data.MediaId].ReleaseDate.HasValue ? $" ({Media[_roles[roleId].Data.MediaId].ReleaseDate!.Value.Year})" : string.Empty) + + @(Media[_roles[roleId].Data.MediaId].Type == MediaType.Movie ? $"Movie" : "TV Series") + + @(_roleTypes[_roles[roleId].Data.TypeId]) + + @(_roles[roleId].Data.Name) + +
+ + +
+
+ } + } + else + { + + } +
+ } + else + { + + } +
\ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonRolesEditActorComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonRolesEditActorComponent.razor.cs new file mode 100644 index 0000000..06af0dd --- /dev/null +++ b/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonRolesEditActorComponent.razor.cs @@ -0,0 +1,100 @@ +using Microsoft.AspNetCore.Components; +using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Roles; +using WatchIt.Website.Services.WebAPI.Media; +using WatchIt.Website.Services.WebAPI.Persons; +using WatchIt.Website.Services.WebAPI.Roles; + +namespace WatchIt.Website.Components.PersonEditPage; + +public partial class PersonRolesEditActorComponent : ComponentBase +{ + #region SERVICES + + [Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!; + [Inject] private IMediaWebAPIService MediaWebAPIService { get; set; } = default!; + [Inject] private IRolesWebAPIService RolesWebAPIService { get; set; } = default!; + + #endregion + + + + #region PARAMETERS + + [Parameter] public required long? Id { get; set; } + [Parameter] public required Dictionary Media { get; set; } + [Parameter] public string Class { get; set; } = string.Empty; + + #endregion + + + + #region FIELDS + + private bool _loaded; + + private Dictionary _roles = []; + private Dictionary _roleTypes = []; + + + private Guid? _editedId; + private IActorRolePersonRequest _editedModel = new ActorRoleRequest(); + + private bool _editingMode; + private bool _saving; + + #endregion + + + + #region PUBLIC METHODS + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + List endTasks = new List(); + + // STEP 0 + if (Id.HasValue) + { + endTasks.AddRange( + [ + PersonsWebAPIService.GetPersonAllActorRoles(Id.Value, successAction: data => _roles = data.ToDictionary(x => x.Id, x => (x, false))), + RolesWebAPIService.GetAllActorRoleTypes(successAction: data => _roleTypes = data.ToDictionary(x => x.Id, x => x.Name)), + ]); + } + + // END + await Task.WhenAll(endTasks); + + _loaded = true; + StateHasChanged(); + } + } + + private void CancelEdit() + { + _editingMode = false; + } + + private void SaveEdit() + { + + } + + private void ActivateEdit(Guid? id = null) + { + _editedId = id; + _editedModel = id.HasValue ? new ActorRoleRequest(_roles[id.Value].Data) : new ActorRoleRequest(); + _editingMode = true; + } + + private async Task Delete(Guid id) + { + _roles[id] = (_roles[id].Data, true); + await RolesWebAPIService.DeleteActorRole(id, () => _roles.Remove(id)); + } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonRolesEditActorComponent.razor.css b/WatchIt.Website/WatchIt.Website/Components/PersonEditPage/PersonRolesEditActorComponent.razor.css new file mode 100644 index 0000000..e69de29 diff --git a/WatchIt.Website/WatchIt.Website/Pages/PersonEditPage.razor b/WatchIt.Website/WatchIt.Website/Pages/PersonEditPage.razor index 27ab84f..01dcb6c 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/PersonEditPage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/PersonEditPage.razor @@ -59,6 +59,12 @@ Class="h-100"/>
+
+
+ +
+
} else diff --git a/WatchIt.Website/WatchIt.Website/Pages/PersonEditPage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/PersonEditPage.razor.cs index 3efed3b..242d128 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/PersonEditPage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/PersonEditPage.razor.cs @@ -1,7 +1,9 @@ using Microsoft.AspNetCore.Components; +using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Persons; using WatchIt.Website.Layout; using WatchIt.Website.Services.Utility.Authentication; +using WatchIt.Website.Services.WebAPI.Media; using WatchIt.Website.Services.WebAPI.Persons; namespace WatchIt.Website.Pages; @@ -13,6 +15,7 @@ public partial class PersonEditPage : ComponentBase [Inject] private NavigationManager NavigationManager { get; set; } = default!; [Inject] private IAuthenticationService AuthenticationService { get; set; } = default!; [Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!; + [Inject] private IMediaWebAPIService MediaWebAPIService { get; set; } = default!; #endregion @@ -36,6 +39,7 @@ public partial class PersonEditPage : ComponentBase private User? _user; private PersonResponse? _person; + private Dictionary _media = []; #endregion @@ -53,7 +57,7 @@ public partial class PersonEditPage : ComponentBase // STEP 0 step1Tasks.AddRange( [ - Task.Run(async () => _user = await AuthenticationService.GetUserAsync()) + Task.Run(async () => _user = await AuthenticationService.GetUserAsync()), ]); // STEP 1 @@ -62,7 +66,8 @@ public partial class PersonEditPage : ComponentBase { endTasks.AddRange( [ - PersonsWebAPIService.GetPerson(Id.Value, data => _person = data, () => NavigationManager.NavigateTo("/person/new", true)) + PersonsWebAPIService.GetPerson(Id.Value, data => _person = data, () => NavigationManager.NavigateTo("/person/new", true)), + MediaWebAPIService.GetAllMedia(successAction: data => _media = data.ToDictionary(x => x.Id, x => x)), ]); } diff --git a/WatchIt.Website/WatchIt.Website/Program.cs b/WatchIt.Website/WatchIt.Website/Program.cs index 6975f44..9f05d6f 100644 --- a/WatchIt.Website/WatchIt.Website/Program.cs +++ b/WatchIt.Website/WatchIt.Website/Program.cs @@ -14,6 +14,7 @@ using WatchIt.Website.Services.WebAPI.Media; using WatchIt.Website.Services.WebAPI.Movies; using WatchIt.Website.Services.WebAPI.Persons; using WatchIt.Website.Services.WebAPI.Photos; +using WatchIt.Website.Services.WebAPI.Roles; using WatchIt.Website.Services.WebAPI.Series; namespace WatchIt.Website; @@ -79,6 +80,7 @@ public static class Program builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); return builder; } diff --git a/WatchIt.Website/WatchIt.Website/WatchIt.Website.csproj b/WatchIt.Website/WatchIt.Website/WatchIt.Website.csproj index 7a61124..eb28837 100644 --- a/WatchIt.Website/WatchIt.Website/WatchIt.Website.csproj +++ b/WatchIt.Website/WatchIt.Website/WatchIt.Website.csproj @@ -25,6 +25,7 @@ + @@ -46,6 +47,7 @@ + diff --git a/WatchIt.Website/WatchIt.Website/appsettings.json b/WatchIt.Website/WatchIt.Website/appsettings.json index 4300ef7..aa46c17 100644 --- a/WatchIt.Website/WatchIt.Website/appsettings.json +++ b/WatchIt.Website/WatchIt.Website/appsettings.json @@ -37,6 +37,7 @@ }, "Media": { "Base": "/media", + "GetAllMedia": "", "GetMedia": "/{0}", "GetMediaGenres": "/{0}/genres", "PostMediaGenre": "/{0}/genres/{1}", diff --git a/WatchIt.Website/WatchIt.Website/wwwroot/css/general.css b/WatchIt.Website/WatchIt.Website/wwwroot/css/general.css index 443ec27..263c518 100644 --- a/WatchIt.Website/WatchIt.Website/wwwroot/css/general.css +++ b/WatchIt.Website/WatchIt.Website/wwwroot/css/general.css @@ -42,7 +42,14 @@ body, html { -webkit-text-fill-color: transparent; } +.table-transparent { + --bs-table-bg: transparent !important; +} +.table td.table-cell-fit, .table th.table-cell-fit { + white-space: nowrap; + width: 1%; +}