person view add endpoint added
This commit is contained in:
@@ -77,7 +77,13 @@ public class PersonsController : ControllerBase
|
|||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[ProducesResponseType(typeof(IEnumerable<PersonResponse>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(IEnumerable<PersonResponse>), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
public async Task<ActionResult> GetMoviesViewRank([FromQuery] int first = 5, [FromQuery] int days = 7) => await _personsControllerService.GetPersonsViewRank(first, days);
|
public async Task<ActionResult> GetPersonsViewRank([FromQuery] int first = 5, [FromQuery] int days = 7) => await _personsControllerService.GetPersonsViewRank(first, days);
|
||||||
|
|
||||||
|
[HttpPost("{id}/view")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ActionResult> PostPersonsView([FromRoute] long id) => await _personsControllerService.PostPersonsView(id);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public interface IPersonsControllerService
|
|||||||
Task<RequestResult> DeletePerson(long id);
|
Task<RequestResult> DeletePerson(long id);
|
||||||
|
|
||||||
Task<RequestResult> GetPersonsViewRank(int first, int days);
|
Task<RequestResult> GetPersonsViewRank(int first, int days);
|
||||||
|
Task<RequestResult> PostPersonsView(long personId);
|
||||||
|
|
||||||
Task<RequestResult> GetPersonPhoto(long id);
|
Task<RequestResult> GetPersonPhoto(long id);
|
||||||
Task<RequestResult> PutPersonPhoto(long id, PersonPhotoRequest data);
|
Task<RequestResult> PutPersonPhoto(long id, PersonPhotoRequest data);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using WatchIt.Common.Model.Persons;
|
|||||||
using WatchIt.Common.Model.Roles;
|
using WatchIt.Common.Model.Roles;
|
||||||
using WatchIt.Database;
|
using WatchIt.Database;
|
||||||
using WatchIt.Database.Model.Person;
|
using WatchIt.Database.Model.Person;
|
||||||
|
using WatchIt.Database.Model.ViewCount;
|
||||||
using WatchIt.WebAPI.Services.Controllers.Common;
|
using WatchIt.WebAPI.Services.Controllers.Common;
|
||||||
using WatchIt.WebAPI.Services.Utility.User;
|
using WatchIt.WebAPI.Services.Utility.User;
|
||||||
using Person = WatchIt.Database.Model.Person.Person;
|
using Person = WatchIt.Database.Model.Person.Person;
|
||||||
@@ -141,6 +142,35 @@ public class PersonsControllerService : IPersonsControllerService
|
|||||||
|
|
||||||
return RequestResult.Ok(data);
|
return RequestResult.Ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<RequestResult> PostPersonsView(long personId)
|
||||||
|
{
|
||||||
|
Database.Model.Media.Media? item = await _database.Media.FirstOrDefaultAsync(x => x.Id == personId);
|
||||||
|
if (item is null)
|
||||||
|
{
|
||||||
|
return RequestResult.NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
DateOnly dateNow = DateOnly.FromDateTime(DateTime.Now);
|
||||||
|
ViewCountPerson? viewCount = await _database.ViewCountsPerson.FirstOrDefaultAsync(x => x.PersonId == personId && x.Date == dateNow);
|
||||||
|
if (viewCount is null)
|
||||||
|
{
|
||||||
|
viewCount = new ViewCountPerson
|
||||||
|
{
|
||||||
|
PersonId = personId,
|
||||||
|
Date = dateNow,
|
||||||
|
ViewCount = 1
|
||||||
|
};
|
||||||
|
await _database.ViewCountsPerson.AddAsync(viewCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
viewCount.ViewCount++;
|
||||||
|
}
|
||||||
|
await _database.SaveChangesAsync();
|
||||||
|
|
||||||
|
return RequestResult.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ public class Persons
|
|||||||
public string PutPerson { get; set; }
|
public string PutPerson { get; set; }
|
||||||
public string DeletePerson { get; set; }
|
public string DeletePerson { get; set; }
|
||||||
public string GetPersonsViewRank { get; set; }
|
public string GetPersonsViewRank { get; set; }
|
||||||
|
public string PostPersonsView { get; set; }
|
||||||
public string GetPersonPhoto { get; set; }
|
public string GetPersonPhoto { get; set; }
|
||||||
public string PutPersonPhoto { get; set; }
|
public string PutPersonPhoto { get; set; }
|
||||||
public string DeletePersonPhoto { get; set; }
|
public string DeletePersonPhoto { get; set; }
|
||||||
|
|||||||
@@ -138,6 +138,18 @@ public class PersonsWebAPIService : BaseWebAPIService, IPersonsWebAPIService
|
|||||||
.RegisterActionFor400BadRequest(badRequestAction)
|
.RegisterActionFor400BadRequest(badRequestAction)
|
||||||
.ExecuteAction();
|
.ExecuteAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task PostPersonsView(long personId, Action? successAction = null, Action? notFoundAction = null)
|
||||||
|
{
|
||||||
|
string url = GetUrl(EndpointsConfiguration.Persons.PostPersonsView, personId);
|
||||||
|
|
||||||
|
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
|
||||||
|
|
||||||
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
||||||
|
response.RegisterActionFor2XXSuccess(successAction)
|
||||||
|
.RegisterActionFor404NotFound(notFoundAction)
|
||||||
|
.ExecuteAction();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,7 @@
|
|||||||
"PutPerson": "/{0}",
|
"PutPerson": "/{0}",
|
||||||
"DeletePerson": "/{0}",
|
"DeletePerson": "/{0}",
|
||||||
"GetPersonsViewRank": "/view",
|
"GetPersonsViewRank": "/view",
|
||||||
|
"PostPersonsView": "/{0}/view",
|
||||||
"GetPersonPhoto": "/{0}/photo",
|
"GetPersonPhoto": "/{0}/photo",
|
||||||
"PutPersonPhoto": "/{0}/photo",
|
"PutPersonPhoto": "/{0}/photo",
|
||||||
"DeletePersonPhoto": "/{0}/photo",
|
"DeletePersonPhoto": "/{0}/photo",
|
||||||
|
|||||||
Reference in New Issue
Block a user