diff --git a/WatchIt.Common/WatchIt.Common.Model/Rating/RatingResponse.cs b/WatchIt.Common/WatchIt.Common.Model/Rating/RatingResponse.cs index 6b34940..77fed60 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Rating/RatingResponse.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Rating/RatingResponse.cs @@ -33,7 +33,13 @@ public class RatingResponse public static RatingResponse Create(long ratingSum, long ratingCount) => new RatingResponse(ratingSum, ratingCount); - public static RatingResponse Create(IEnumerable ratingMedia) => new RatingResponse(ratingMedia.Sum(x => x.Rating), ratingMedia.Count()); + public static RatingResponse Create(IEnumerable ratingMedia) => Create(ratingMedia, x => x.Rating); + + public static RatingResponse Create(IEnumerable ratingPersonActorRoles) => Create(ratingPersonActorRoles, x => x.Rating); + + public static RatingResponse Create(IEnumerable ratingPersonCreatorRoles) => Create(ratingPersonCreatorRoles, x => x.Rating); + + public static RatingResponse Create(IEnumerable ratingList, Func ratingSelector) => new RatingResponse(ratingList.Sum(x => ratingSelector(x)), ratingList.Count()); public static RatingResponse Create(IEnumerable personActorRoles, IEnumerable personCreatorRoles) { diff --git a/WatchIt.Database/WatchIt.Database/DatabaseContext.cs b/WatchIt.Database/WatchIt.Database/DatabaseContext.cs index 977953d..d04598f 100644 --- a/WatchIt.Database/WatchIt.Database/DatabaseContext.cs +++ b/WatchIt.Database/WatchIt.Database/DatabaseContext.cs @@ -66,7 +66,7 @@ public class DatabaseContext : DbContext // Rating public virtual DbSet RatingsMedia { get; set; } public virtual DbSet RatingsPersonActorRole { get; set; } - public virtual DbSet RatingsPersonCreatorRole { get; set; } + public virtual DbSet RatingsPersonCreatorRole { get; set; } public virtual DbSet RatingsMediaSeriesSeason { get; set; } public virtual DbSet RatingsMediaSeriesEpisode { get; set; } diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/RolesController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/RolesController.cs index cb43f62..b656bd9 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/RolesController.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/RolesController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using WatchIt.Common.Model.Rating; using WatchIt.Common.Model.Roles; using WatchIt.WebAPI.Services.Controllers.Roles; @@ -56,6 +57,32 @@ public class RolesController : ControllerBase [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] public async Task DeleteActorRole([FromRoute]Guid id) => await _rolesControllerService.DeleteActorRole(id); + [HttpGet("actor/{id}/rating")] + [AllowAnonymous] + [ProducesResponseType(typeof(RatingResponse), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetActorRoleRating([FromRoute] Guid id) => await _rolesControllerService.GetActorRoleRating(id); + + [HttpGet("actor/{id}/rating/{user_id}")] + [AllowAnonymous] + [ProducesResponseType(typeof(short), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetActorRoleRatingByUser([FromRoute] Guid id, [FromRoute(Name = "user_id")]long userId) => await _rolesControllerService.GetActorRoleRatingByUser(id, userId); + + [HttpPut("actor/{id}/rating")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PutActorRoleRating([FromRoute] Guid id, [FromBody] RatingRequest data) => await _rolesControllerService.PutActorRoleRating(id, data); + + [HttpDelete("actor/{id}/rating")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public async Task DeleteActorRoleRating([FromRoute] Guid id) => await _rolesControllerService.DeleteActorRoleRating(id); + [HttpGet("actor/type")] [AllowAnonymous] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] @@ -107,6 +134,32 @@ public class RolesController : ControllerBase [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] public async Task DeleteCreatorRole([FromRoute]Guid id) => await _rolesControllerService.DeleteCreatorRole(id); + [HttpGet("creator/{id}/rating")] + [AllowAnonymous] + [ProducesResponseType(typeof(RatingResponse), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetCreatorRoleRating([FromRoute] Guid id) => await _rolesControllerService.GetCreatorRoleRating(id); + + [HttpGet("creator/{id}/rating/{user_id}")] + [AllowAnonymous] + [ProducesResponseType(typeof(short), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetCreatorRoleRatingByUser([FromRoute] Guid id, [FromRoute(Name = "user_id")] long userId) => await _rolesControllerService.GetCreatorRoleRatingByUser(id, userId); + + [HttpPut("creator/{id}/rating")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PutCreatorRoleRating([FromRoute] Guid id, [FromBody] RatingRequest data) => await _rolesControllerService.PutCreatorRoleRating(id, data); + + [HttpDelete("creator/{id}/rating")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public async Task DeleteCreatorRoleRating([FromRoute] Guid id) => await _rolesControllerService.DeleteCreatorRoleRating(id); + [HttpGet("creator/type")] [AllowAnonymous] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] 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 18f8364..46bde20 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 @@ -125,29 +125,17 @@ public class MediaControllerService(DatabaseContext database, IUserService userS public async Task GetMediaRatingByUser(long mediaId, long userId) { - Database.Model.Media.Media? item = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); - if (item is null) + RatingMedia? rating = await database.RatingsMedia.FirstOrDefaultAsync(x => x.MediaId == mediaId && x.AccountId == userId); + if (rating is null) { return RequestResult.NotFound(); } - short? rating = item.RatingMedia.FirstOrDefault(x => x.AccountId == userId)?.Rating; - if (!rating.HasValue) - { - return RequestResult.NotFound(); - } - - return RequestResult.Ok(rating.Value); + return RequestResult.Ok(rating.Rating); } public async Task PutMediaRating(long mediaId, RatingRequest data) { - short ratingValue = data.Rating; - if (ratingValue < 1 || ratingValue > 10) - { - return RequestResult.BadRequest(); - } - Database.Model.Media.Media? item = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); if (item is null) { @@ -159,7 +147,7 @@ public class MediaControllerService(DatabaseContext database, IUserService userS RatingMedia? rating = item.RatingMedia.FirstOrDefault(x => x.AccountId == userId); if (rating is not null) { - rating.Rating = ratingValue; + rating.Rating = data.Rating; } else { @@ -167,7 +155,7 @@ public class MediaControllerService(DatabaseContext database, IUserService userS { AccountId = userId, MediaId = mediaId, - Rating = ratingValue + Rating = data.Rating }; await database.RatingsMedia.AddAsync(rating); } 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 index 13b364c..5f9f67e 100644 --- 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 @@ -1,3 +1,4 @@ +using WatchIt.Common.Model.Rating; using WatchIt.Common.Model.Roles; using WatchIt.WebAPI.Services.Controllers.Common; @@ -8,6 +9,10 @@ public interface IRolesControllerService Task GetActorRole(Guid id); Task PutActorRole(Guid id, ActorRoleUniversalRequest data); Task DeleteActorRole(Guid id); + Task GetActorRoleRating(Guid id); + Task GetActorRoleRatingByUser(Guid id, long userId); + Task PutActorRoleRating(Guid id, RatingRequest data); + Task DeleteActorRoleRating(Guid id); Task GetAllActorRoleTypes(RoleTypeQueryParameters query); Task GetActorRoleType(short typeId); Task PostActorRoleType(RoleTypeRequest data); @@ -16,6 +21,10 @@ public interface IRolesControllerService Task GetCreatorRole(Guid id); Task PutCreatorRole(Guid id, CreatorRoleUniversalRequest data); Task DeleteCreatorRole(Guid id); + Task GetCreatorRoleRating(Guid id); + Task GetCreatorRoleRatingByUser(Guid id, long userId); + Task PutCreatorRoleRating(Guid id, RatingRequest data); + Task DeleteCreatorRoleRating(Guid id); Task GetAllCreatorRoleTypes(RoleTypeQueryParameters query); Task GetCreatorRoleType(short typeId); Task PostCreatorRoleType(RoleTypeRequest data); 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 index 3f6735e..d9d88c2 100644 --- 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 @@ -1,7 +1,9 @@ using Microsoft.EntityFrameworkCore; +using WatchIt.Common.Model.Rating; using WatchIt.Common.Model.Roles; using WatchIt.Database; using WatchIt.Database.Model.Person; +using WatchIt.Database.Model.Rating; using WatchIt.WebAPI.Services.Controllers.Common; using WatchIt.WebAPI.Services.Utility.User; @@ -87,6 +89,77 @@ public class RolesControllerService : IRolesControllerService return RequestResult.NoContent(); } + public async Task GetActorRoleRating(Guid id) + { + PersonActorRole? item = await _database.PersonActorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + RatingResponse ratingResponse = RatingResponse.Create(item.RatingPersonActorRole); + + return RequestResult.Ok(ratingResponse); + } + + public async Task GetActorRoleRatingByUser(Guid id, long userId) + { + RatingPersonActorRole? rating = await _database.RatingsPersonActorRole.FirstOrDefaultAsync(x => x.PersonActorRoleId == id && x.AccountId == userId); + if (rating is null) + { + return RequestResult.NotFound(); + } + + return RequestResult.Ok(rating.Rating); + } + + public async Task PutActorRoleRating(Guid id, RatingRequest data) + { + PersonActorRole? item = await _database.PersonActorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + long userId = _userService.GetUserId(); + + RatingPersonActorRole? rating = item.RatingPersonActorRole.FirstOrDefault(x => x.AccountId == userId); + if (rating is not null) + { + rating.Rating = data.Rating; + } + else + { + rating = new RatingPersonActorRole + { + AccountId = userId, + PersonActorRoleId = id, + Rating = data.Rating + }; + await _database.RatingsPersonActorRole.AddAsync(rating); + } + await _database.SaveChangesAsync(); + + return RequestResult.Ok(); + } + + public async Task DeleteActorRoleRating(Guid id) + { + long userId = _userService.GetUserId(); + + RatingPersonActorRole? item = await _database.RatingsPersonActorRole.FirstOrDefaultAsync(x => x.PersonActorRoleId == id && x.AccountId == userId); + if (item is null) + { + return RequestResult.Ok(); + } + + _database.RatingsPersonActorRole.Attach(item); + _database.RatingsPersonActorRole.Remove(item); + await _database.SaveChangesAsync(); + + return RequestResult.Ok(); + } + public async Task GetAllActorRoleTypes(RoleTypeQueryParameters query) { IEnumerable rawData = await _database.PersonActorRoleTypes.ToListAsync(); @@ -200,6 +273,77 @@ public class RolesControllerService : IRolesControllerService return RequestResult.NoContent(); } + public async Task GetCreatorRoleRating(Guid id) + { + PersonCreatorRole? item = await _database.PersonCreatorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + RatingResponse ratingResponse = RatingResponse.Create(item.RatingPersonCreatorRole); + + return RequestResult.Ok(ratingResponse); + } + + public async Task GetCreatorRoleRatingByUser(Guid id, long userId) + { + RatingPersonCreatorRole? rating = await _database.RatingsPersonCreatorRole.FirstOrDefaultAsync(x => x.PersonCreatorRoleId == id && x.AccountId == userId); + if (rating is null) + { + return RequestResult.NotFound(); + } + + return RequestResult.Ok(rating.Rating); + } + + public async Task PutCreatorRoleRating(Guid id, RatingRequest data) + { + PersonCreatorRole? item = await _database.PersonCreatorRoles.FirstOrDefaultAsync(x => x.Id == id); + if (item is null) + { + return RequestResult.NotFound(); + } + + long userId = _userService.GetUserId(); + + RatingPersonCreatorRole? rating = item.RatingPersonCreatorRole.FirstOrDefault(x => x.AccountId == userId); + if (rating is not null) + { + rating.Rating = data.Rating; + } + else + { + rating = new RatingPersonCreatorRole + { + AccountId = userId, + PersonCreatorRoleId = id, + Rating = data.Rating + }; + await _database.RatingsPersonCreatorRole.AddAsync(rating); + } + await _database.SaveChangesAsync(); + + return RequestResult.Ok(); + } + + public async Task DeleteCreatorRoleRating(Guid id) + { + long userId = _userService.GetUserId(); + + RatingPersonCreatorRole? item = await _database.RatingsPersonCreatorRole.FirstOrDefaultAsync(x => x.PersonCreatorRoleId == id && x.AccountId == userId); + if (item is null) + { + return RequestResult.Ok(); + } + + _database.RatingsPersonCreatorRole.Attach(item); + _database.RatingsPersonCreatorRole.Remove(item); + await _database.SaveChangesAsync(); + + return RequestResult.Ok(); + } + public async Task GetAllCreatorRoleTypes(RoleTypeQueryParameters query) { IEnumerable rawData = await _database.PersonCreatorRoleTypes.ToListAsync(); diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Rating/RatingRequestValidator.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Rating/RatingRequestValidator.cs new file mode 100644 index 0000000..0d300c4 --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Rating/RatingRequestValidator.cs @@ -0,0 +1,12 @@ +using FluentValidation; +using WatchIt.Common.Model.Rating; + +namespace WatchIt.WebAPI.Validators.Rating; + +public class RatingRequestValidator : AbstractValidator +{ + public RatingRequestValidator() + { + RuleFor(x => x.Rating).InclusiveBetween((short)1, (short)10); + } +} \ 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 index 9805329..6eec92e 100644 --- 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 @@ -6,6 +6,10 @@ public class Roles public string GetActorRole { get; set; } public string PutActorRole { get; set; } public string DeleteActorRole { get; set; } + public string GetActorRoleRating { get; set; } + public string GetActorRoleRatingByUser { get; set; } + public string PutActorRoleRating { get; set; } + public string DeleteActorRoleRating { get; set; } public string GetAllActorRoleTypes { get; set; } public string GetActorRoleType { get; set; } public string PostActorRoleType { get; set; } @@ -13,6 +17,10 @@ public class Roles public string GetCreatorRole { get; set; } public string PutCreatorRole { get; set; } public string DeleteCreatorRole { get; set; } + public string GetCreatorRoleRating { get; set; } + public string GetCreatorRoleRatingByUser { get; set; } + public string PutCreatorRoleRating { get; set; } + public string DeleteCreatorRoleRating { get; set; } public string GetAllCreatorRoleTypes { get; set; } public string GetCreatorRoleType { get; set; } public string PostCreatorRoleType { get; set; } 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 index 106027b..b270d98 100644 --- 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 @@ -1,3 +1,4 @@ +using WatchIt.Common.Model.Rating; using WatchIt.Common.Model.Roles; namespace WatchIt.Website.Services.WebAPI.Roles; @@ -7,6 +8,10 @@ public interface IRolesWebAPIService Task GetActorRole(Guid id, Action? successAction = null, Action? notFoundAction = null); Task PutActorRole(Guid id, ActorRoleUniversalRequest 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 GetActorRoleRating(Guid id, Action? successAction = null, Action? notFoundAction = null); + Task GetActorRoleRatingByUser(Guid id, long userId, Action? successAction = null, Action? notFoundAction = null); + Task PutActorRoleRating(Guid id, RatingRequest body, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null); + Task DeleteActorRoleRating(Guid id, Action? successAction = null, Action? unauthorizedAction = 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); @@ -15,6 +20,10 @@ public interface IRolesWebAPIService Task GetCreatorRole(Guid id, Action? successAction = null, Action? notFoundAction = null); Task PutCreatorRole(Guid id, CreatorRoleUniversalRequest 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 GetCreatorRoleRating(Guid id, Action? successAction = null, Action? notFoundAction = null); + Task GetCreatorRoleRatingByUser(Guid id, long userId, Action? successAction = null, Action? notFoundAction = null); + Task PutCreatorRoleRating(Guid id, RatingRequest body, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null); + Task DeleteCreatorRoleRating(Guid id, Action? successAction = null, Action? unauthorizedAction = 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); 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 index 4e6a1b9..09b0418 100644 --- 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 @@ -1,4 +1,5 @@ -using WatchIt.Common.Model.Roles; +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.WebAPI.Common; @@ -70,6 +71,59 @@ public class RolesWebAPIService : BaseWebAPIService, IRolesWebAPIService .RegisterActionFor403Forbidden(forbiddenAction) .ExecuteAction(); } + + public async Task GetActorRoleRating(Guid id, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetActorRoleRating, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task GetActorRoleRatingByUser(Guid id, long userId, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetActorRoleRatingByUser, id, userId); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task PutActorRoleRating(Guid id, RatingRequest body, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.PutActorRoleRating, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Put, url) + { + Body = body + }; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task DeleteActorRoleRating(Guid id, Action? successAction = null, Action? unauthorizedAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.DeleteActorRoleRating, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .ExecuteAction(); + } public async Task GetAllActorRoleTypes(RoleTypeQueryParameters? query = null, Action>? successAction = null) { @@ -168,6 +222,59 @@ public class RolesWebAPIService : BaseWebAPIService, IRolesWebAPIService .ExecuteAction(); } + public async Task GetCreatorRoleRating(Guid id, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetCreatorRoleRating, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task GetCreatorRoleRatingByUser(Guid id, long userId, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.GetCreatorRoleRatingByUser, id, userId); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task PutCreatorRoleRating(Guid id, RatingRequest body, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.PutCreatorRoleRating, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Put, url) + { + Body = body + }; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task DeleteCreatorRoleRating(Guid id, Action? successAction = null, Action? unauthorizedAction = null) + { + string url = GetUrl(EndpointsConfiguration.Roles.DeleteCreatorRoleRating, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .ExecuteAction(); + } + public async Task GetAllCreatorRoleTypes(RoleTypeQueryParameters? query = null, Action>? successAction = null) { string url = GetUrl(EndpointsConfiguration.Roles.GetAllCreatorRoleTypes); diff --git a/WatchIt.Website/WatchIt.Website/appsettings.json b/WatchIt.Website/WatchIt.Website/appsettings.json index 4417577..2142c32 100644 --- a/WatchIt.Website/WatchIt.Website/appsettings.json +++ b/WatchIt.Website/WatchIt.Website/appsettings.json @@ -108,6 +108,10 @@ "GetActorRole": "/actor/{0}", "PutActorRole": "/actor/{0}", "DeleteActorRole": "/actor/{0}", + "GetActorRoleRating": "/actor/{0}/rating", + "GetActorRoleRatingByUser": "/actor/{0}/rating/{1}", + "PutActorRoleRating": "/actor/{0}/rating", + "DeleteActorRoleRating": "/actor/{0}/rating", "GetAllActorRoleTypes": "/actor/type", "GetActorRoleType": "/actor/type/{0}", "PostActorRoleType": "/actor/type", @@ -115,6 +119,10 @@ "GetCreatorRole": "/creator/{0}", "PutCreatorRole": "/creator/{0}", "DeleteCreatorRole": "/creator/{0}", + "GetCreatorRoleRating": "/creator/{0}/rating", + "GetCreatorRoleRatingByUser": "/creator/{0}/rating/{1}", + "PutCreatorRoleRating": "/creator/{0}/rating", + "DeleteCreatorRoleRating": "/creator/{0}/rating", "GetAllCreatorRoleTypes": "/creator/type", "GetCreatorRoleType": "/creator/type/{0}", "PostCreatorRoleType": "/creator/type",