person controller and service created
This commit is contained in:
@@ -108,7 +108,7 @@ public class MediaControllerService(DatabaseContext database, IUserService userS
|
||||
return RequestResult.NotFound();
|
||||
}
|
||||
|
||||
RatingResponse ratingResponse = new RatingResponse(item.RatingMedia);
|
||||
RatingResponse ratingResponse = RatingResponse.Create(item.RatingMedia);
|
||||
|
||||
return RequestResult.Ok(ratingResponse);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WatchIt.Common.Model.Persons;
|
||||
using WatchIt.Database;
|
||||
using WatchIt.WebAPI.Services.Controllers.Common;
|
||||
using WatchIt.WebAPI.Services.Utility.User;
|
||||
using Person = WatchIt.Database.Model.Person.Person;
|
||||
|
||||
namespace WatchIt.WebAPI.Services.Controllers.Persons;
|
||||
|
||||
public class PersonsControllerService
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public PersonsControllerService(DatabaseContext database, IUserService userService)
|
||||
{
|
||||
_database = database;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
#region Main
|
||||
|
||||
public async Task<RequestResult> GetAllPersons(PersonQueryParameters query)
|
||||
{
|
||||
IEnumerable<Person> rawData = await _database.Persons.ToListAsync();
|
||||
IEnumerable<PersonResponse> data = rawData.Select(x => new PersonResponse(x));
|
||||
data = query.PrepareData(data);
|
||||
return RequestResult.Ok(data);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> GetMovie(long id)
|
||||
{
|
||||
Person? item = await _database.Persons.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (item is null)
|
||||
{
|
||||
return RequestResult.NotFound();
|
||||
}
|
||||
|
||||
PersonResponse data = new PersonResponse(item);
|
||||
return RequestResult.Ok(data);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> PostPerson(PersonRequest data)
|
||||
{
|
||||
UserValidator validator = _userService.GetValidator().MustBeAdmin();
|
||||
if (!validator.IsValid)
|
||||
{
|
||||
return RequestResult.Forbidden();
|
||||
}
|
||||
|
||||
Person personItem = data.CreatePerson();
|
||||
await _database.Persons.AddAsync(personItem);
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
return RequestResult.Created($"persons/{personItem.Id}", new PersonResponse(personItem));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\WatchIt.Common\WatchIt.Common.Model\WatchIt.Common.Model.csproj" />
|
||||
<ProjectReference Include="..\..\..\..\WatchIt.Database\WatchIt.Database\WatchIt.Database.csproj" />
|
||||
<ProjectReference Include="..\..\WatchIt.WebAPI.Services.Utility\WatchIt.WebAPI.Services.Utility.User\WatchIt.WebAPI.Services.Utility.User.csproj" />
|
||||
<ProjectReference Include="..\WatchIt.WebAPI.Services.Controllers.Common\WatchIt.WebAPI.Services.Controllers.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user