diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRole.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRole.cs new file mode 100644 index 0000000..446ad2f --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRole.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; + +namespace WatchIt.Common.Model.Roles; + +public class ActorRole +{ + #region PROPERTIES + + [JsonPropertyName("type_id")] + public required short TypeId { get; set; } + + [JsonPropertyName("name")] + public required string Name { get; set; } + + [JsonPropertyName("media_id")] + public required long MediaId { get; set; } + + [JsonPropertyName("person_id")] + public required long PersonId { get; set; } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleMediaQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleMediaQueryParameters.cs new file mode 100644 index 0000000..aea4560 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleMediaQueryParameters.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WatchIt.Common.Model.Roles; + +public class ActorRoleMediaQueryParameters : ActorRoleQueryParameters +{ + #region PROPERTIES + + [FromQuery(Name = "person_id")] + public long? PersonId { get; set; } + + #endregion + + + + #region PRIVATE METHODS + + protected override bool IsMeetingConditions(ActorRoleResponse item) => + ( + base.IsMeetingConditions(item) + && + Test(item.PersonId, PersonId) + ); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRolePersonQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRolePersonQueryParameters.cs new file mode 100644 index 0000000..b31e24f --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRolePersonQueryParameters.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WatchIt.Common.Model.Roles; + +public class ActorRolePersonQueryParameters : ActorRoleQueryParameters +{ + #region PROPERTIES + + [FromQuery(Name = "media_id")] + public long? MediaId { get; set; } + + #endregion + + + + #region PRIVATE METHODS + + protected override bool IsMeetingConditions(ActorRoleResponse item) => + ( + base.IsMeetingConditions(item) + && + Test(item.MediaId, MediaId) + ); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleQueryParameters.cs new file mode 100644 index 0000000..b4a926c --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleQueryParameters.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; +using WatchIt.Common.Query; + +namespace WatchIt.Common.Model.Roles; + +public abstract class ActorRoleQueryParameters : QueryParameters +{ + #region PROPERTIES + + [FromQuery(Name = "type_id")] + public short? TypeId { get; set; } + + [FromQuery(Name = "name")] + public string? Name { get; set; } + + #endregion + + + + #region PRIVATE METHODS + + protected override bool IsMeetingConditions(ActorRoleResponse item) => + ( + Test(item.TypeId, TypeId) + && + TestStringWithRegex(item.Name, Name) + ); + + #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 new file mode 100644 index 0000000..c51f77c --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleRequest.cs @@ -0,0 +1,38 @@ +using WatchIt.Database.Model.Person; + +namespace WatchIt.Common.Model.Roles; + +public class ActorRoleRequest : ActorRole, IActorRoleMediaRequest, IActorRolePersonRequest +{ + #region PUBLIC METHODS + + PersonActorRole IActorRoleMediaRequest.CreateActorRole(long mediaId) + { + MediaId = mediaId; + return CreateActorRole(); + } + + PersonActorRole IActorRolePersonRequest.CreateActorRole(long personId) + { + PersonId = personId; + return CreateActorRole(); + } + + public PersonActorRole CreateActorRole() => new PersonActorRole + { + MediaId = MediaId, + PersonId = PersonId, + PersonActorRoleTypeId = TypeId, + RoleName = Name, + }; + + public void UpdateActorRole(PersonActorRole item) + { + item.MediaId = MediaId; + item.PersonId = PersonId; + item.PersonActorRoleTypeId = TypeId; + item.RoleName = Name; + } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleResponse.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleResponse.cs new file mode 100644 index 0000000..8f6e024 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ActorRoleResponse.cs @@ -0,0 +1,42 @@ +using System.Diagnostics.CodeAnalysis; +using System.Text.Json.Serialization; +using WatchIt.Common.Query; + +namespace WatchIt.Common.Model.Roles; + +public class ActorRoleResponse : ActorRole, IQueryOrderable +{ + #region PROPERTIES + + [JsonIgnore] + public static IDictionary> OrderableProperties { get; } = new Dictionary> + { + { "name", item => item.Name }, + { "type_id", item => item.TypeId }, + }; + + + [JsonPropertyName("id")] + public required Guid Id { get; set; } + + #endregion + + + + #region CONSTRUCTORS + + [JsonConstructor] + public ActorRoleResponse() {} + + [SetsRequiredMembers] + public ActorRoleResponse(Database.Model.Person.PersonActorRole data) + { + Id = data.Id; + MediaId = data.MediaId; + PersonId = data.PersonId; + TypeId = data.PersonActorRoleTypeId; + Name = data.RoleName; + } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRole.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRole.cs new file mode 100644 index 0000000..0eab7d9 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRole.cs @@ -0,0 +1,19 @@ +using System.Text.Json.Serialization; + +namespace WatchIt.Common.Model.Roles; + +public class CreatorRole +{ + #region PROPERTIES + + [JsonPropertyName("type_id")] + public required short TypeId { get; set; } + + [JsonPropertyName("media_id")] + public required long MediaId { get; set; } + + [JsonPropertyName("person_id")] + public required long PersonId { get; set; } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleMediaQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleMediaQueryParameters.cs new file mode 100644 index 0000000..94daf61 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleMediaQueryParameters.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WatchIt.Common.Model.Roles; + +public class CreatorRoleMediaQueryParameters : CreatorRoleQueryParameters +{ + #region PROPERTIES + + [FromQuery(Name = "person_id")] + public long? PersonId { get; set; } + + #endregion + + + + #region PRIVATE METHODS + + protected override bool IsMeetingConditions(CreatorRoleResponse item) => + ( + base.IsMeetingConditions(item) + && + Test(item.PersonId, PersonId) + ); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRolePersonQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRolePersonQueryParameters.cs new file mode 100644 index 0000000..a8604dd --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRolePersonQueryParameters.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WatchIt.Common.Model.Roles; + +public class CreatorRolePersonQueryParameters : CreatorRoleQueryParameters +{ + #region PROPERTIES + + [FromQuery(Name = "media_id")] + public long? MediaId { get; set; } + + #endregion + + + + #region PRIVATE METHODS + + protected override bool IsMeetingConditions(CreatorRoleResponse item) => + ( + base.IsMeetingConditions(item) + && + Test(item.MediaId, MediaId) + ); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleQueryParameters.cs new file mode 100644 index 0000000..8d416f6 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleQueryParameters.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Mvc; +using WatchIt.Common.Query; + +namespace WatchIt.Common.Model.Roles; + +public abstract class CreatorRoleQueryParameters : QueryParameters +{ + #region PROPERTIES + + [FromQuery(Name = "type_id")] + public short? TypeId { get; set; } + + #endregion + + + + #region PRIVATE METHODS + + protected override bool IsMeetingConditions(CreatorRoleResponse item) => + ( + Test(item.TypeId, TypeId) + ); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleRequest.cs new file mode 100644 index 0000000..ad9fa5c --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleRequest.cs @@ -0,0 +1,36 @@ +using WatchIt.Database.Model.Person; + +namespace WatchIt.Common.Model.Roles; + +public class CreatorRoleRequest : CreatorRole, ICreatorRoleMediaRequest, ICreatorRolePersonRequest +{ + #region PUBLIC METHODS + + PersonCreatorRole ICreatorRoleMediaRequest.CreateCreatorRole(long mediaId) + { + MediaId = mediaId; + return CreateCreatorRole(); + } + + PersonCreatorRole ICreatorRolePersonRequest.CreateCreatorRole(long personId) + { + PersonId = personId; + return CreateCreatorRole(); + } + + public PersonCreatorRole CreateCreatorRole() => new PersonCreatorRole + { + MediaId = MediaId, + PersonId = PersonId, + PersonCreatorRoleTypeId = TypeId, + }; + + public void UpdateCreatorRole(PersonCreatorRole item) + { + item.MediaId = MediaId; + item.PersonId = PersonId; + item.PersonCreatorRoleTypeId = TypeId; + } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleResponse.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleResponse.cs new file mode 100644 index 0000000..c1b4433 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/CreatorRoleResponse.cs @@ -0,0 +1,40 @@ +using System.Diagnostics.CodeAnalysis; +using System.Text.Json.Serialization; +using WatchIt.Common.Query; + +namespace WatchIt.Common.Model.Roles; + +public class CreatorRoleResponse : CreatorRole, IQueryOrderable +{ + #region PROPERTIES + + [JsonIgnore] + public static IDictionary> OrderableProperties { get; } = new Dictionary> + { + { "type_id", item => item.TypeId }, + }; + + + [JsonPropertyName("id")] + public required Guid Id { get; set; } + + #endregion + + + + #region CONSTRUCTORS + + [JsonConstructor] + public CreatorRoleResponse() {} + + [SetsRequiredMembers] + public CreatorRoleResponse(Database.Model.Person.PersonCreatorRole data) + { + Id = data.Id; + MediaId = data.MediaId; + PersonId = data.PersonId; + TypeId = data.PersonCreatorRoleTypeId; + } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/IActorRoleMediaRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/IActorRoleMediaRequest.cs new file mode 100644 index 0000000..2bf7bf9 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/IActorRoleMediaRequest.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; +using WatchIt.Database.Model.Person; + +namespace WatchIt.Common.Model.Roles; + +public interface IActorRoleMediaRequest +{ + #region PROPERTIES + + [JsonPropertyName("person_id")] + long PersonId { get; set; } + + [JsonPropertyName("type_id")] + short TypeId { get; set; } + + [JsonPropertyName("name")] + string Name { get; set; } + + #endregion + + + + #region PUBLIC METHODS + + PersonActorRole CreateActorRole(long mediaId); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/IActorRolePersonRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/IActorRolePersonRequest.cs new file mode 100644 index 0000000..05d475b --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/IActorRolePersonRequest.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; +using WatchIt.Database.Model.Person; + +namespace WatchIt.Common.Model.Roles; + +public interface IActorRolePersonRequest +{ + #region PROPERTIES + + [JsonPropertyName("media_id")] + long MediaId { get; set; } + + [JsonPropertyName("type_id")] + short TypeId { get; set; } + + [JsonPropertyName("name")] + string Name { get; set; } + + #endregion + + + + #region PUBLIC METHODS + + PersonActorRole CreateActorRole(long personId); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ICreatorRoleMediaRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ICreatorRoleMediaRequest.cs new file mode 100644 index 0000000..cc7cc47 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ICreatorRoleMediaRequest.cs @@ -0,0 +1,25 @@ +using System.Text.Json.Serialization; +using WatchIt.Database.Model.Person; + +namespace WatchIt.Common.Model.Roles; + +public interface ICreatorRoleMediaRequest +{ + #region PROPERTIES + + [JsonPropertyName("person_id")] + long PersonId { get; set; } + + [JsonPropertyName("type_id")] + short TypeId { get; set; } + + #endregion + + + + #region PUBLIC METHODS + + PersonCreatorRole CreateCreatorRole(long mediaId); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/ICreatorRolePersonRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/ICreatorRolePersonRequest.cs new file mode 100644 index 0000000..2702520 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/ICreatorRolePersonRequest.cs @@ -0,0 +1,25 @@ +using System.Text.Json.Serialization; +using WatchIt.Database.Model.Person; + +namespace WatchIt.Common.Model.Roles; + +public interface ICreatorRolePersonRequest +{ + #region PROPERTIES + + [JsonPropertyName("media_id")] + long MediaId { get; set; } + + [JsonPropertyName("type_id")] + short TypeId { get; set; } + + #endregion + + + + #region PUBLIC METHODS + + PersonCreatorRole CreateCreatorRole(long personId); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/RoleType.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleType.cs new file mode 100644 index 0000000..cb3ed4e --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleType.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; + +namespace WatchIt.Common.Model.Roles; + +public class RoleType +{ + #region PROPERTIES + + [JsonPropertyName("name")] + public required string Name { get; set; } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeQueryParameters.cs new file mode 100644 index 0000000..2198ee9 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeQueryParameters.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Mvc; +using WatchIt.Common.Query; + +namespace WatchIt.Common.Model.Roles; + +public class RoleTypeQueryParameters : QueryParameters +{ + #region PROPERTIES + + [FromQuery(Name = "name")] + public string? Name { get; set; } + + #endregion + + + + #region PRIVATE METHODS + + protected override bool IsMeetingConditions(RoleTypeResponse item) => TestStringWithRegex(item.Name, Name); + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeRequest.cs new file mode 100644 index 0000000..cfefe02 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeRequest.cs @@ -0,0 +1,18 @@ +namespace WatchIt.Common.Model.Roles; + +public class RoleTypeRequest : RoleType +{ + #region PUBLIC METHODS + + public Database.Model.Person.PersonActorRoleType CreateActorRoleType() => new Database.Model.Person.PersonActorRoleType() + { + Name = Name + }; + + public Database.Model.Person.PersonCreatorRoleType CreateCreatorRoleType() => new Database.Model.Person.PersonCreatorRoleType() + { + Name = Name + }; + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeResponse.cs b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeResponse.cs new file mode 100644 index 0000000..56629e6 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Roles/RoleTypeResponse.cs @@ -0,0 +1,45 @@ +using System.Diagnostics.CodeAnalysis; +using System.Text.Json.Serialization; +using WatchIt.Common.Query; + +namespace WatchIt.Common.Model.Roles; + +public class RoleTypeResponse : RoleType, IQueryOrderable +{ + #region PROPERTIES + + [JsonIgnore] + public static IDictionary> OrderableProperties { get; } = new Dictionary> + { + { "name", item => item.Name } + }; + + + [JsonPropertyName("id")] + public required short? Id { get; set; } + + #endregion + + + + #region CONSTRUCTORS + + [JsonConstructor] + public RoleTypeResponse() { } + + [SetsRequiredMembers] + public RoleTypeResponse(Database.Model.Person.PersonCreatorRoleType creatorRoleType) + { + Id = creatorRoleType.Id; + Name = creatorRoleType.Name; + } + + [SetsRequiredMembers] + public RoleTypeResponse(Database.Model.Person.PersonActorRoleType actorRoleType) + { + Id = actorRoleType.Id; + Name = actorRoleType.Name; + } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/GendersController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/GendersController.cs index af3be9f..4f6e24d 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/GendersController.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/GendersController.cs @@ -55,7 +55,7 @@ public class GendersController : ControllerBase [HttpDelete("{id}")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] - [ProducesResponseType(typeof(GenderResponse), StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] public async Task DeleteGender([FromRoute]short id) => await _gendersControllerService.DeleteGender(id); diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs index 0a095e1..ee25ae1 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs @@ -6,6 +6,7 @@ using WatchIt.Common.Model.Genres; using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Rating; +using WatchIt.Common.Model.Roles; using WatchIt.WebAPI.Services.Controllers.Media; namespace WatchIt.WebAPI.Controllers; @@ -160,6 +161,40 @@ public class MediaController : ControllerBase [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task PostPhoto([FromRoute]long id, [FromBody]MediaPhotoRequest body) => await _mediaControllerService.PostMediaPhoto(id, body); + #endregion + + #region Roles + + [HttpGet("{id}/roles/actor")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetMediaAllActorRoles([FromRoute]long id, ActorRoleMediaQueryParameters query) => await _mediaControllerService.GetMediaAllActorRoles(id, query); + + [HttpPost("{id}/roles/actor")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(ActorRoleResponse), StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PostMediaActorRole([FromRoute]long id, [FromBody]IActorRoleMediaRequest body) => await _mediaControllerService.PostMediaActorRole(id, body); + + [HttpGet("{id}/roles/creator")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetMediaAllCreatorRoles([FromRoute]long id, CreatorRoleMediaQueryParameters query) => await _mediaControllerService.GetMediaAllCreatorRoles(id, query); + + [HttpPost("{id}/roles/creator")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(CreatorRoleResponse), StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PostMediaCreatorRole([FromRoute]long id, [FromBody]ICreatorRoleMediaRequest body) => await _mediaControllerService.PostMediaCreatorRole(id, body); + #endregion #endregion diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PersonsController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PersonsController.cs index 258763a..4b84e5e 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PersonsController.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PersonsController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Roles; using WatchIt.WebAPI.Services.Controllers.Persons; namespace WatchIt.WebAPI.Controllers; @@ -104,6 +105,40 @@ public class PersonsController : ControllerBase [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] public async Task DeletePersonPhoto([FromRoute]long id) => await _personsControllerService.DeletePersonPhoto(id); + #endregion + + #region Roles + + [HttpGet("{id}/roles/actor")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetPersonAllActorRoles([FromRoute]long id, ActorRolePersonQueryParameters query) => await _personsControllerService.GetPersonAllActorRoles(id, query); + + [HttpPost("{id}/roles/actor")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(ActorRoleResponse), StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PostPersonActorRole([FromRoute]long id, [FromBody]IActorRolePersonRequest body) => await _personsControllerService.PostPersonActorRole(id, body); + + [HttpGet("{id}/roles/creator")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetPersonAllCreatorRoles([FromRoute]long id, CreatorRolePersonQueryParameters query) => await _personsControllerService.GetPersonAllCreatorRoles(id, query); + + [HttpPost("{id}/roles/creator")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(CreatorRoleResponse), StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PostPersonCreatorRole([FromRoute]long id, [FromBody]ICreatorRolePersonRequest body) => await _personsControllerService.PostPersonCreatorRole(id, body); + #endregion #endregion diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/RolesController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/RolesController.cs new file mode 100644 index 0000000..100b4e0 --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/RolesController.cs @@ -0,0 +1,139 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using WatchIt.Common.Model.Roles; +using WatchIt.WebAPI.Services.Controllers.Roles; + +namespace WatchIt.WebAPI.Controllers; + +[ApiController] +[Route("roles")] +public class RolesController : ControllerBase +{ + #region SERVICES + + private readonly IRolesControllerService _rolesControllerService; + + #endregion + + + + #region CONSTRUCTORS + + public RolesController(IRolesControllerService rolesControllerService) + { + _rolesControllerService = rolesControllerService; + } + + #endregion + + + + #region METHODS + + #region Actor + + [HttpGet("actor/{id}")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetActorRole([FromRoute]Guid id) => await _rolesControllerService.GetActorRole(id); + + [HttpPut("actor/{id}")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PutActorRole([FromRoute]Guid id, [FromBody]ActorRoleRequest body) => await _rolesControllerService.PutActorRole(id, body); + + [HttpDelete("actor/{id}")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + public async Task DeleteActorRole([FromRoute]Guid id) => await _rolesControllerService.DeleteActorRole(id); + + [HttpGet("actor/type")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + public async Task GetAllActorRoleTypes(RoleTypeQueryParameters query) => await _rolesControllerService.GetAllActorRoleTypes(query); + + [HttpGet("actor/type/{type_id}")] + [AllowAnonymous] + [ProducesResponseType(typeof(RoleTypeResponse), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetActorRoleType([FromRoute(Name = "type_id")]short typeId) => await _rolesControllerService.GetActorRoleType(typeId); + + [HttpPost("actor/type")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(RoleTypeResponse), StatusCodes.Status201Created)] + [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + public async Task PostActorRoleType([FromBody]RoleTypeRequest body) => await _rolesControllerService.PostActorRoleType(body); + + [HttpDelete("actor/type/{type_id}")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + public async Task DeleteActorRoleType([FromRoute(Name = "type_id")]short typeId) => await _rolesControllerService.DeleteActorRoleType(typeId); + + #endregion + + #region Creator + + [HttpGet("creator/{id}")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + public async Task GetCreatorRole([FromRoute]Guid id) => await _rolesControllerService.GetCreatorRole(id); + + [HttpPut("creator/{id}")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PutCreatorRole([FromRoute]Guid id, [FromBody]CreatorRoleRequest body) => await _rolesControllerService.PutCreatorRole(id, body); + + [HttpDelete("creator/{id}")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + public async Task DeleteCreatorRole([FromRoute]Guid id) => await _rolesControllerService.DeleteCreatorRole(id); + + [HttpGet("creator/type")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + public async Task GetAllCreatorRoleTypes(RoleTypeQueryParameters query) => await _rolesControllerService.GetAllCreatorRoleTypes(query); + + [HttpGet("creator/type/{id}")] + [AllowAnonymous] + [ProducesResponseType(typeof(RoleTypeResponse), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetCreatorRoleType([FromRoute]short id) => await _rolesControllerService.GetCreatorRoleType(id); + + [HttpPost("creator/type")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(RoleTypeResponse), StatusCodes.Status201Created)] + [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + public async Task PostCreatorRoleType([FromBody]RoleTypeRequest body) => await _rolesControllerService.PostCreatorRoleType(body); + + [HttpDelete("creator/type/{id}")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + public async Task DeleteCreatorRoleType([FromRoute]short id) => await _rolesControllerService.DeleteCreatorRoleType(id); + + #endregion + + #endregion +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/WatchIt.WebAPI.Controllers.csproj b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/WatchIt.WebAPI.Controllers.csproj index c2bb202..c2ab0dd 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/WatchIt.WebAPI.Controllers.csproj +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/WatchIt.WebAPI.Controllers.csproj @@ -20,6 +20,7 @@ + diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Genders/GendersControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Genders/GendersControllerService.cs index 43011b9..6c7d7dc 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Genders/GendersControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Genders/GendersControllerService.cs @@ -33,6 +33,8 @@ public class GendersControllerService : IGendersControllerService #region PUBLIC METHODS + #region Main + public async Task GetAllGenders(GenderQueryParameters query) { IEnumerable rawData = await _database.Genders.ToListAsync(); @@ -90,4 +92,6 @@ public class GendersControllerService : IGendersControllerService } #endregion + + #endregion } \ No newline at end of file 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 a93a938..390a831 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 @@ -1,6 +1,7 @@ using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Rating; +using WatchIt.Common.Model.Roles; using WatchIt.WebAPI.Services.Controllers.Common; namespace WatchIt.WebAPI.Services.Controllers.Media; @@ -27,4 +28,9 @@ public interface IMediaControllerService Task GetMediaPhotos(long mediaId, PhotoQueryParameters queryParameters); Task GetMediaPhotoRandomBackground(long mediaId); Task PostMediaPhoto(long mediaId, MediaPhotoRequest data); + + Task GetMediaAllActorRoles(long mediaId, ActorRoleMediaQueryParameters queryParameters); + Task PostMediaActorRole(long mediaId, IActorRoleMediaRequest data); + Task GetMediaAllCreatorRoles(long mediaId, CreatorRoleMediaQueryParameters queryParameters); + Task PostMediaCreatorRole(long mediaId, ICreatorRoleMediaRequest data); } \ No newline at end of file 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 f8a3f2b..9d34b84 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 @@ -4,8 +4,10 @@ using WatchIt.Common.Model.Genres; using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Rating; +using WatchIt.Common.Model.Roles; using WatchIt.Database; using WatchIt.Database.Model.Media; +using WatchIt.Database.Model.Person; using WatchIt.Database.Model.Rating; using WatchIt.Database.Model.ViewCount; using WatchIt.WebAPI.Services.Controllers.Common; @@ -267,7 +269,7 @@ public class MediaControllerService(DatabaseContext database, IUserService userS await database.SaveChangesAsync(); - MediaPosterResponse returnData = new MediaPosterResponse(media.MediaPosterImage); + MediaPosterResponse returnData = new MediaPosterResponse(media.MediaPosterImage!); return RequestResult.Ok(returnData); } @@ -351,5 +353,79 @@ public class MediaControllerService(DatabaseContext database, IUserService userS #endregion + #region Roles + + public async Task GetMediaAllActorRoles(long mediaId, ActorRoleMediaQueryParameters queryParameters) + { + Database.Model.Media.Media? media = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); + if (media is null) + { + return RequestResult.NotFound(); + } + + IEnumerable dataRaw = await database.PersonActorRoles.Where(x => x.MediaId == mediaId).ToListAsync(); + IEnumerable data = dataRaw.Select(x => new ActorRoleResponse(x)); + data = queryParameters.PrepareData(data); + return RequestResult.Ok(data); + } + + public async Task PostMediaActorRole(long mediaId, IActorRoleMediaRequest data) + { + UserValidator validator = userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + Database.Model.Media.Media? media = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); + if (media is null) + { + return RequestResult.NotFound(); + } + + PersonActorRole item = data.CreateActorRole(mediaId); + await database.PersonActorRoles.AddAsync(item); + await database.SaveChangesAsync(); + + return RequestResult.Created($"roles/actor/{item.Id}", new ActorRoleResponse(item)); + } + + public async Task GetMediaAllCreatorRoles(long mediaId, CreatorRoleMediaQueryParameters queryParameters) + { + Database.Model.Media.Media? media = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); + if (media is null) + { + return RequestResult.NotFound(); + } + + IEnumerable dataRaw = await database.PersonCreatorRoles.Where(x => x.MediaId == mediaId).ToListAsync(); + IEnumerable data = dataRaw.Select(x => new CreatorRoleResponse(x)); + data = queryParameters.PrepareData(data); + return RequestResult.Ok(data); + } + + public async Task PostMediaCreatorRole(long mediaId, ICreatorRoleMediaRequest data) + { + UserValidator validator = userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + Database.Model.Media.Media? media = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); + if (media is null) + { + return RequestResult.NotFound(); + } + + PersonCreatorRole item = data.CreateCreatorRole(mediaId); + await database.PersonCreatorRoles.AddAsync(item); + await database.SaveChangesAsync(); + + return RequestResult.Created($"roles/creator/{item.Id}", new CreatorRoleResponse(item)); + } + + #endregion + #endregion } \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Persons/IPersonsControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Persons/IPersonsControllerService.cs index d3bd360..760d9f3 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Persons/IPersonsControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Persons/IPersonsControllerService.cs @@ -1,4 +1,5 @@ using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Roles; using WatchIt.WebAPI.Services.Controllers.Common; namespace WatchIt.WebAPI.Services.Controllers.Persons; @@ -16,4 +17,9 @@ public interface IPersonsControllerService Task GetPersonPhoto(long id); Task PutPersonPhoto(long id, PersonPhotoRequest data); Task DeletePersonPhoto(long id); + + Task GetPersonAllActorRoles(long personId, ActorRolePersonQueryParameters queryParameters); + Task PostPersonActorRole(long personId, IActorRolePersonRequest data); + Task GetPersonAllCreatorRoles(long personId, CreatorRolePersonQueryParameters queryParameters); + Task PostPersonCreatorRole(long personId, ICreatorRolePersonRequest data); } \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Persons/PersonsControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Persons/PersonsControllerService.cs index 549a5c1..d7031f5 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Persons/PersonsControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Persons/PersonsControllerService.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Roles; using WatchIt.Database; using WatchIt.Database.Model.Person; using WatchIt.WebAPI.Services.Controllers.Common; @@ -218,5 +219,79 @@ public class PersonsControllerService : IPersonsControllerService #endregion + #region Roles + + public async Task GetPersonAllActorRoles(long personId, ActorRolePersonQueryParameters queryParameters) + { + Database.Model.Person.Person? person = await _database.Persons.FirstOrDefaultAsync(x => x.Id == personId); + if (person is null) + { + return RequestResult.NotFound(); + } + + IEnumerable dataRaw = await _database.PersonActorRoles.Where(x => x.PersonId == personId).ToListAsync(); + IEnumerable data = dataRaw.Select(x => new ActorRoleResponse(x)); + data = queryParameters.PrepareData(data); + return RequestResult.Ok(data); + } + + public async Task PostPersonActorRole(long personId, IActorRolePersonRequest data) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + Database.Model.Person.Person? person = await _database.Persons.FirstOrDefaultAsync(x => x.Id == personId); + if (person is null) + { + return RequestResult.NotFound(); + } + + PersonActorRole item = data.CreateActorRole(personId); + await _database.PersonActorRoles.AddAsync(item); + await _database.SaveChangesAsync(); + + return RequestResult.Created($"roles/actor/{item.Id}", new ActorRoleResponse(item)); + } + + public async Task GetPersonAllCreatorRoles(long personId, CreatorRolePersonQueryParameters queryParameters) + { + Database.Model.Person.Person? media = await _database.Persons.FirstOrDefaultAsync(x => x.Id == personId); + if (media is null) + { + return RequestResult.NotFound(); + } + + IEnumerable dataRaw = await _database.PersonCreatorRoles.Where(x => x.PersonId == personId).ToListAsync(); + IEnumerable data = dataRaw.Select(x => new CreatorRoleResponse(x)); + data = queryParameters.PrepareData(data); + return RequestResult.Ok(data); + } + + public async Task PostPersonCreatorRole(long personId, ICreatorRolePersonRequest data) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + Database.Model.Person.Person? media = await _database.Persons.FirstOrDefaultAsync(x => x.Id == personId); + if (media is null) + { + return RequestResult.NotFound(); + } + + PersonCreatorRole item = data.CreateCreatorRole(personId); + await _database.PersonCreatorRoles.AddAsync(item); + await _database.SaveChangesAsync(); + + return RequestResult.Created($"roles/creator/{item.Id}", new CreatorRoleResponse(item)); + } + + #endregion + #endregion } \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/IRolesControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/IRolesControllerService.cs new file mode 100644 index 0000000..6841b05 --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/IRolesControllerService.cs @@ -0,0 +1,23 @@ +using WatchIt.Common.Model.Roles; +using WatchIt.WebAPI.Services.Controllers.Common; + +namespace WatchIt.WebAPI.Services.Controllers.Roles; + +public interface IRolesControllerService +{ + Task GetActorRole(Guid id); + Task PutActorRole(Guid id, ActorRoleRequest data); + Task DeleteActorRole(Guid id); + Task GetAllActorRoleTypes(RoleTypeQueryParameters query); + Task GetActorRoleType(short typeId); + Task PostActorRoleType(RoleTypeRequest data); + Task DeleteActorRoleType(short typeId); + + Task GetCreatorRole(Guid id); + Task PutCreatorRole(Guid id, CreatorRoleRequest data); + Task DeleteCreatorRole(Guid id); + Task GetAllCreatorRoleTypes(RoleTypeQueryParameters query); + Task GetCreatorRoleType(short typeId); + Task PostCreatorRoleType(RoleTypeRequest data); + Task DeleteCreatorRoleType(short typeId); +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/RolesControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/RolesControllerService.cs new file mode 100644 index 0000000..f004d9b --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/RolesControllerService.cs @@ -0,0 +1,262 @@ +using Microsoft.EntityFrameworkCore; +using WatchIt.Common.Model.Roles; +using WatchIt.Database; +using WatchIt.Database.Model.Person; +using WatchIt.WebAPI.Services.Controllers.Common; +using WatchIt.WebAPI.Services.Utility.User; + +namespace WatchIt.WebAPI.Services.Controllers.Roles; + +public class RolesControllerService : IRolesControllerService +{ + #region SERVICES + + private readonly DatabaseContext _database; + private readonly IUserService _userService; + + #endregion + + + + #region CONSTRUCTORS + + public RolesControllerService(DatabaseContext database, IUserService userService) + { + _database = database; + _userService = userService; + } + + #endregion + + + + #region PUBLIC METHODS + + #region Actor + + public async Task GetActorRole(Guid id) + { + PersonActorRole? item = await _database.PersonActorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + ActorRoleResponse data = new ActorRoleResponse(item); + return RequestResult.Ok(data); + } + + public async Task PutActorRole(Guid id, ActorRoleRequest data) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + PersonActorRole? item = await _database.PersonActorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + data.UpdateActorRole(item); + await _database.SaveChangesAsync(); + + return RequestResult.Ok(); + } + + public async Task DeleteActorRole(Guid id) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + PersonActorRole? item = await _database.PersonActorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NoContent(); + } + + _database.PersonActorRoles.Attach(item); + _database.PersonActorRoles.Remove(item); + await _database.SaveChangesAsync(); + + return RequestResult.NoContent(); + } + + public async Task GetAllActorRoleTypes(RoleTypeQueryParameters query) + { + IEnumerable rawData = await _database.PersonActorRoleTypes.ToListAsync(); + IEnumerable data = rawData.Select(x => new RoleTypeResponse(x)); + data = query.PrepareData(data); + return RequestResult.Ok(data); + } + + public async Task GetActorRoleType(short id) + { + PersonActorRoleType? item = await _database.PersonActorRoleTypes.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + RoleTypeResponse data = new RoleTypeResponse(item); + return RequestResult.Ok(data); + } + + public async Task PostActorRoleType(RoleTypeRequest data) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + PersonActorRoleType item = data.CreateActorRoleType(); + await _database.PersonActorRoleTypes.AddAsync(item); + await _database.SaveChangesAsync(); + + return RequestResult.Created($"roles/actor/{item.Id}", new RoleTypeResponse(item)); + } + + public async Task DeleteActorRoleType(short id) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + PersonActorRoleType? item = await _database.PersonActorRoleTypes.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NoContent(); + } + + _database.PersonActorRoleTypes.Attach(item); + _database.PersonActorRoleTypes.Remove(item); + await _database.SaveChangesAsync(); + + return RequestResult.NoContent(); + } + + #endregion + + #region Creator + + public async Task GetCreatorRole(Guid id) + { + PersonCreatorRole? item = await _database.PersonCreatorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + CreatorRoleResponse data = new CreatorRoleResponse(item); + return RequestResult.Ok(data); + } + + public async Task PutCreatorRole(Guid id, CreatorRoleRequest data) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + PersonCreatorRole? item = await _database.PersonCreatorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + data.UpdateCreatorRole(item); + await _database.SaveChangesAsync(); + + return RequestResult.Ok(); + } + + public async Task DeleteCreatorRole(Guid id) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + PersonCreatorRole? item = await _database.PersonCreatorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NoContent(); + } + + _database.PersonCreatorRoles.Attach(item); + _database.PersonCreatorRoles.Remove(item); + await _database.SaveChangesAsync(); + + return RequestResult.NoContent(); + } + + public async Task GetAllCreatorRoleTypes(RoleTypeQueryParameters query) + { + IEnumerable rawData = await _database.PersonCreatorRoleTypes.ToListAsync(); + IEnumerable data = rawData.Select(x => new RoleTypeResponse(x)); + data = query.PrepareData(data); + return RequestResult.Ok(data); + } + + public async Task GetCreatorRoleType(short id) + { + PersonCreatorRoleType? item = await _database.PersonCreatorRoleTypes.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + RoleTypeResponse data = new RoleTypeResponse(item); + return RequestResult.Ok(data); + } + + public async Task PostCreatorRoleType(RoleTypeRequest data) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + PersonCreatorRoleType item = data.CreateCreatorRoleType(); + await _database.PersonCreatorRoleTypes.AddAsync(item); + await _database.SaveChangesAsync(); + + return RequestResult.Created($"roles/creator/{item.Id}", new RoleTypeResponse(item)); + } + + public async Task DeleteCreatorRoleType(short id) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + PersonCreatorRoleType? item = await _database.PersonCreatorRoleTypes.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NoContent(); + } + + _database.PersonCreatorRoleTypes.Attach(item); + _database.PersonCreatorRoleTypes.Remove(item); + await _database.SaveChangesAsync(); + + return RequestResult.NoContent(); + } + + #endregion + + #endregion +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/WatchIt.WebAPI.Services.Controllers.Roles.csproj b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/WatchIt.WebAPI.Services.Controllers.Roles.csproj new file mode 100644 index 0000000..9e4603e --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Roles/WatchIt.WebAPI.Services.Controllers.Roles.csproj @@ -0,0 +1,16 @@ + + + + net8.0 + enable + enable + + + + + + + + + + diff --git a/WatchIt.WebAPI/WatchIt.WebAPI/Program.cs b/WatchIt.WebAPI/WatchIt.WebAPI/Program.cs index d8a531d..7d987e4 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI/Program.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI/Program.cs @@ -16,6 +16,7 @@ using WatchIt.WebAPI.Services.Controllers.Media; using WatchIt.WebAPI.Services.Controllers.Movies; using WatchIt.WebAPI.Services.Controllers.Persons; using WatchIt.WebAPI.Services.Controllers.Photos; +using WatchIt.WebAPI.Services.Controllers.Roles; using WatchIt.WebAPI.Services.Controllers.Series; using WatchIt.WebAPI.Services.Utility.Configuration; using WatchIt.WebAPI.Services.Utility.Tokens; @@ -162,6 +163,7 @@ public static class Program builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); + builder.Services.AddTransient(); return builder; } diff --git a/WatchIt.WebAPI/WatchIt.WebAPI/WatchIt.WebAPI.csproj b/WatchIt.WebAPI/WatchIt.WebAPI/WatchIt.WebAPI.csproj index 37917aa..56996dc 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI/WatchIt.WebAPI.csproj +++ b/WatchIt.WebAPI/WatchIt.WebAPI/WatchIt.WebAPI.csproj @@ -28,6 +28,7 @@ + diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Endpoints.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Endpoints.cs index 8052021..386b6c1 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Endpoints.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Endpoints.cs @@ -11,4 +11,5 @@ public class Endpoints public Series Series { get; set; } public Photos Photos { get; set; } public Persons Persons { get; set; } + public Roles Roles { get; set; } } \ No newline at end of file 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 3774ebd..fa20a8d 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 @@ -18,4 +18,8 @@ public class Media public string GetMediaPhotos { get; set; } public string GetMediaPhotoRandomBackground { get; set; } public string PostMediaPhoto { get; set; } + public string GetMediaAllActorRoles { get; set; } + public string PostMediaActorRole { get; set; } + public string GetMediaAllCreatorRoles { get; set; } + public string PostMediaCreatorRole { get; set; } } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Persons.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Persons.cs index a1c1ab6..4a1381f 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Persons.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Persons.cs @@ -12,4 +12,8 @@ public class Persons public string GetPersonPhoto { get; set; } public string PutPersonPhoto { get; set; } public string DeletePersonPhoto { get; set; } + public string GetPersonAllActorRoles { get; set; } + public string PostPersonActorRole { get; set; } + public string GetPersonAllCreatorRoles { get; set; } + public string PostPersonCreatorRole { get; set; } } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Roles.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Roles.cs new file mode 100644 index 0000000..9805329 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Roles.cs @@ -0,0 +1,20 @@ +namespace WatchIt.Website.Services.Utility.Configuration.Model; + +public class Roles +{ + public string Base { get; set; } + public string GetActorRole { get; set; } + public string PutActorRole { get; set; } + public string DeleteActorRole { get; set; } + public string GetAllActorRoleTypes { get; set; } + public string GetActorRoleType { get; set; } + public string PostActorRoleType { get; set; } + public string DeleteActorRoleType { get; set; } + public string GetCreatorRole { get; set; } + public string PutCreatorRole { get; set; } + public string DeleteCreatorRole { get; set; } + public string GetAllCreatorRoleTypes { get; set; } + public string GetCreatorRoleType { get; set; } + public string PostCreatorRoleType { get; set; } + public string DeleteCreatorRoleType { get; set; } +} \ No newline at end of file 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 9e5c9b4..86a9dee 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 @@ -2,6 +2,7 @@ using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Rating; +using WatchIt.Common.Model.Roles; namespace WatchIt.Website.Services.WebAPI.Media; @@ -27,4 +28,9 @@ public interface IMediaWebAPIService Task GetMediaPhotos(long mediaId, PhotoQueryParameters? query = null, Action>? successAction = null, Action? notFoundAction = null); Task GetMediaPhotoRandomBackground(long mediaId, Action? successAction = null, Action? notFoundAction = null); Task PostMediaPhoto(long mediaId, MediaPhotoRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); + + Task GetMediaAllActorRoles(long id, ActorRoleMediaQueryParameters? query = null, Action>? successAction = null); + Task PostMediaActorRole(long id, IActorRoleMediaRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task GetMediaAllCreatorRoles(long id, CreatorRoleMediaQueryParameters? query = null, Action>? successAction = null); + Task PostMediaCreatorRole(long id, ICreatorRoleMediaRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); } \ No newline at end of file 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 f95ae52..4ec059a 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 @@ -2,6 +2,7 @@ using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Rating; +using WatchIt.Common.Model.Roles; using WatchIt.Common.Services.HttpClient; using WatchIt.Website.Services.Utility.Configuration; using WatchIt.Website.Services.Utility.Configuration.Model; @@ -258,6 +259,64 @@ public class MediaWebAPIService : BaseWebAPIService, IMediaWebAPIService #endregion + #region Roles + + public async Task GetMediaAllActorRoles(long id, ActorRoleMediaQueryParameters? query = null, Action>? successAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.GetMediaAllActorRoles, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + request.Query = query; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .ExecuteAction(); + } + + public async Task PostMediaActorRole(long id, IActorRoleMediaRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.PostMediaActorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Post, url); + request.Body = data; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + public async Task GetMediaAllCreatorRoles(long id, CreatorRoleMediaQueryParameters? query = null, Action>? successAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.GetMediaAllCreatorRoles, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + request.Query = query; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .ExecuteAction(); + } + + public async Task PostMediaCreatorRole(long id, ICreatorRoleMediaRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.PostMediaCreatorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Post, url); + request.Body = data; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + #endregion + #endregion diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Persons/IPersonsWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Persons/IPersonsWebAPIService.cs index 3572536..0570417 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Persons/IPersonsWebAPIService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Persons/IPersonsWebAPIService.cs @@ -1,4 +1,5 @@ using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Roles; namespace WatchIt.Website.Services.WebAPI.Persons; @@ -15,4 +16,9 @@ public interface IPersonsWebAPIService Task GetPersonPhoto(long id, Action? successAction = null, Action>? badRequestAction = null, Action? notFoundAction = null); Task PutPersonPhoto(long id, PersonPhotoRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); Task DeletePersonPhoto(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + + Task GetPersonAllActorRoles(long id, ActorRolePersonQueryParameters? query = null, Action>? successAction = null); + Task PostPersonActorRole(long id, IActorRolePersonRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task GetPersonAllCreatorRoles(long id, CreatorRolePersonQueryParameters? query = null, Action>? successAction = null); + Task PostPersonCreatorRole(long id, ICreatorRolePersonRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Persons/PersonsWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Persons/PersonsWebAPIService.cs index cd40eff..375b597 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Persons/PersonsWebAPIService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Persons/PersonsWebAPIService.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Primitives; using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Roles; using WatchIt.Common.Services.HttpClient; using WatchIt.Website.Services.Utility.Configuration; using WatchIt.Website.Services.WebAPI.Common; @@ -185,6 +186,64 @@ public class PersonsWebAPIService : BaseWebAPIService, IPersonsWebAPIService .ExecuteAction(); } + #endregion + + #region Roles + + public async Task GetPersonAllActorRoles(long id, ActorRolePersonQueryParameters? query = null, Action>? successAction = null) + { + string url = GetUrl(EndpointsConfiguration.Persons.GetPersonAllActorRoles, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + request.Query = query; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .ExecuteAction(); + } + + public async Task PostPersonActorRole(long id, IActorRolePersonRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Persons.PostPersonActorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Post, url); + request.Body = data; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + public async Task GetPersonAllCreatorRoles(long id, CreatorRolePersonQueryParameters? query = null, Action>? successAction = null) + { + string url = GetUrl(EndpointsConfiguration.Persons.GetPersonAllCreatorRoles, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + request.Query = query; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .ExecuteAction(); + } + + public async Task PostPersonCreatorRole(long id, ICreatorRolePersonRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Persons.PostPersonCreatorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Post, url); + request.Body = data; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + #endregion #endregion diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/IRolesWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/IRolesWebAPIService.cs new file mode 100644 index 0000000..d88111e --- /dev/null +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/IRolesWebAPIService.cs @@ -0,0 +1,21 @@ +using WatchIt.Common.Model.Roles; + +namespace WatchIt.Website.Services.WebAPI.Roles; + +public interface IRolesWebAPIService +{ + Task GetActorRole(Guid id, Action? successAction = null, Action? notFoundAction = null); + Task PutActorRole(Guid id, ActorRoleRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); + Task DeleteActorRole(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task GetAllActorRoleTypes(RoleTypeQueryParameters? query = null, Action>? successAction = null); + Task GetActorRoleType(long typeId, Action? successAction = null, Action? notFoundAction = null); + Task PostActorRoleType(RoleTypeRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task DeleteActorRoleType(long typeId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task GetCreatorRole(Guid id, Action? successAction = null, Action? notFoundAction = null); + Task PutCreatorRole(Guid id, CreatorRoleRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); + Task DeleteCreatorRole(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task GetAllCreatorRoleTypes(RoleTypeQueryParameters? query = null, Action>? successAction = null); + Task GetCreatorRoleType(long typeId, Action? successAction = null, Action? notFoundAction = null); + Task PostCreatorRoleType(RoleTypeRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task DeleteCreatorRoleType(long typeId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/RolesWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/RolesWebAPIService.cs new file mode 100644 index 0000000..839aca8 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/RolesWebAPIService.cs @@ -0,0 +1,234 @@ +using WatchIt.Common.Model.Roles; +using WatchIt.Common.Services.HttpClient; +using WatchIt.Website.Services.Utility.Configuration; +using WatchIt.Website.Services.WebAPI.Common; + +namespace WatchIt.Website.Services.WebAPI.Roles; + +public class RolesWebAPIService : BaseWebAPIService, IRolesWebAPIService +{ + #region SERVICES + + private IHttpClientService _httpClientService; + + #endregion + + + + #region CONSTRUCTORS + + public RolesWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService) + { + _httpClientService = httpClientService; + } + + #endregion + + + + #region PUBLIC METHODS + + #region Actor + + public async Task GetActorRole(Guid id, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetActorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task PutActorRole(Guid id, ActorRoleRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.PutActorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Put, url); + request.Body = data; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task DeleteActorRole(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.DeleteActorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + public async Task GetAllActorRoleTypes(RoleTypeQueryParameters? query = null, Action>? successAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetAllActorRoleTypes); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + request.Query = query; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .ExecuteAction(); + } + + public async Task GetActorRoleType(long typeId, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetActorRoleType, typeId); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task PostActorRoleType(RoleTypeRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.PostActorRoleType); + + HttpRequest request = new HttpRequest(HttpMethodType.Post, url); + request.Body = data; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + public async Task DeleteActorRoleType(long typeId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.DeleteActorRoleType, typeId); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + #endregion + + #region Creator + + public async Task GetCreatorRole(Guid id, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetCreatorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task PutCreatorRole(Guid id, CreatorRoleRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.PutCreatorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Put, url); + request.Body = data; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task DeleteCreatorRole(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.DeleteCreatorRole, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + public async Task GetAllCreatorRoleTypes(RoleTypeQueryParameters? query = null, Action>? successAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetAllCreatorRoleTypes); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + request.Query = query; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .ExecuteAction(); + } + + public async Task GetCreatorRoleType(long typeId, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetCreatorRoleType, typeId); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task PostCreatorRoleType(RoleTypeRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.PostCreatorRoleType); + + HttpRequest request = new HttpRequest(HttpMethodType.Post, url); + request.Body = data; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + public async Task DeleteCreatorRoleType(long typeId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.DeleteCreatorRoleType, typeId); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .ExecuteAction(); + } + + #endregion + + #endregion + + + + #region PRIVATE METHODS + + protected override string GetServiceBase() => EndpointsConfiguration.Roles.Base; + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/WatchIt.Website.Services.WebAPI.Roles.csproj b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/WatchIt.Website.Services.WebAPI.Roles.csproj new file mode 100644 index 0000000..abf3359 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Roles/WatchIt.Website.Services.WebAPI.Roles.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/WatchIt.Website/WatchIt.Website/appsettings.json b/WatchIt.Website/WatchIt.Website/appsettings.json index b58c6b7..4300ef7 100644 --- a/WatchIt.Website/WatchIt.Website/appsettings.json +++ b/WatchIt.Website/WatchIt.Website/appsettings.json @@ -51,7 +51,11 @@ "DeleteMediaPoster": "/{0}/poster", "GetMediaPhotos": "/{0}/photos", "GetMediaPhotoRandomBackground": "/{0}/photos/random_background", - "PostMediaPhoto": "/{0}/photos" + "PostMediaPhoto": "/{0}/photos", + "GetMediaAllActorRoles": "/{0}/roles/actor", + "PostMediaActorRole": "/{0}/roles/actor", + "GetMediaAllCreatorRoles": "/{0}/roles/creator", + "PostMediaCreatorRole": "/{0}/roles/creator" }, "Movies": { "Base": "/movies", @@ -88,7 +92,28 @@ "GetPersonsViewRank": "/view", "GetPersonPhoto": "/{0}/photo", "PutPersonPhoto": "/{0}/photo", - "DeletePersonPhoto": "/{0}/photo" + "DeletePersonPhoto": "/{0}/photo", + "GetPersonAllActorRoles": "/{0}/roles/actor", + "PostPersonActorRole": "/{0}/roles/actor", + "GetPersonAllCreatorRoles": "/{0}/roles/creator", + "PostPersonCreatorRole": "/{0}/roles/creator" + }, + "Roles": { + "Base": "/roles", + "GetActorRole": "/actor/{0}", + "PutActorRole": "/actor/{0}", + "DeleteActorRole": "/actor/{0}", + "GetAllActorRoleTypes": "/actor/type", + "GetActorRoleType": "/actor/type/{0}", + "PostActorRoleType": "/actor/type", + "DeleteActorRoleType": "/actor/type/{0}", + "GetCreatorRole": "/creator/{0}", + "PutCreatorRole": "/creator/{0}", + "DeleteCreatorRole": "/creator/{0}", + "GetAllCreatorRoleTypes": "/creator/type", + "GetCreatorRoleType": "/creator/type/{0}", + "PostCreatorRoleType": "/creator/type", + "DeleteCreatorRoleType": "/creator/type/{0}" } } } diff --git a/WatchIt.sln b/WatchIt.sln index 5cd82c9..70d247e 100644 --- a/WatchIt.sln +++ b/WatchIt.sln @@ -96,6 +96,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.WebAPI.Services.Con EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Website.Services.WebAPI.Genders", "WatchIt.Website\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Genders\WatchIt.Website.Services.WebAPI.Genders.csproj", "{B74144DE-EF62-430A-AB80-5D185DD03C05}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.WebAPI.Services.Controllers.Roles", "WatchIt.WebAPI\WatchIt.WebAPI.Services\WatchIt.WebAPI.Services.Controllers\WatchIt.WebAPI.Services.Controllers.Roles\WatchIt.WebAPI.Services.Controllers.Roles.csproj", "{847D157A-E486-4FB6-9AA3-43931A60FB5F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Website.Services.WebAPI.Roles", "WatchIt.Website\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Roles\WatchIt.Website.Services.WebAPI.Roles.csproj", "{3D8B7909-BAC2-42FD-8A72-D1DADDB3BC82}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -146,6 +150,8 @@ Global {83D42D72-FF67-4577-8280-2ABD5B20F985} = {46E3711F-18BD-4004-AF53-EA4D8643D92F} {13BE36AB-2120-4F1B-815A-6F5E3F589EE8} = {CEC468DB-CC49-47D3-9E3E-1CC9530C3CE7} {B74144DE-EF62-430A-AB80-5D185DD03C05} = {46E3711F-18BD-4004-AF53-EA4D8643D92F} + {847D157A-E486-4FB6-9AA3-43931A60FB5F} = {CEC468DB-CC49-47D3-9E3E-1CC9530C3CE7} + {3D8B7909-BAC2-42FD-8A72-D1DADDB3BC82} = {46E3711F-18BD-4004-AF53-EA4D8643D92F} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {23383776-1F27-4B5D-8C7C-57BFF75FA473}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -292,5 +298,13 @@ Global {B74144DE-EF62-430A-AB80-5D185DD03C05}.Debug|Any CPU.Build.0 = Debug|Any CPU {B74144DE-EF62-430A-AB80-5D185DD03C05}.Release|Any CPU.ActiveCfg = Release|Any CPU {B74144DE-EF62-430A-AB80-5D185DD03C05}.Release|Any CPU.Build.0 = Release|Any CPU + {847D157A-E486-4FB6-9AA3-43931A60FB5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {847D157A-E486-4FB6-9AA3-43931A60FB5F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {847D157A-E486-4FB6-9AA3-43931A60FB5F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {847D157A-E486-4FB6-9AA3-43931A60FB5F}.Release|Any CPU.Build.0 = Release|Any CPU + {3D8B7909-BAC2-42FD-8A72-D1DADDB3BC82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D8B7909-BAC2-42FD-8A72-D1DADDB3BC82}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D8B7909-BAC2-42FD-8A72-D1DADDB3BC82}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D8B7909-BAC2-42FD-8A72-D1DADDB3BC82}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal