Compare commits

...

4 Commits

Author SHA1 Message Date
6876b623ac Created remaining CRUD controllers 2024-05-20 15:11:13 -05:00
2a99a5ba62 Created missing UpdateDTOS 2024-05-20 15:00:52 -05:00
e5522ed559 Code cleanup 2024-05-20 14:12:46 -05:00
d5642e4744 implemented adaptFromModel into remaining DTOS 2024-05-20 14:10:46 -05:00
23 changed files with 306 additions and 16 deletions

View File

@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0-preview.3.24172.4"/>
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2-dev-00338" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2-dev-00338"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup>

View File

@ -18,8 +18,8 @@ namespace API.Controllers
where TService : ServiceBase<TService, TDTO, TModel, TAuditModel, TAuthentication>
{
public readonly ILogger<TLoggerCategory> Logger;
public readonly UserService UserService;
public readonly TService Service;
public readonly UserService UserService;
public CRUDBase(ILogger<TLoggerCategory> logger, UserService userService, TService service)
{

View File

@ -0,0 +1,19 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using API.DTO.Base.Update;
using API.Services;
using DAL.Models;
using DAL.Models.Audits;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class EventController : CRUDBase<EventController, EventDTO, EventUpdateDTO, Event, AuditEvent, IYesAuthentication, EventService>
{
public EventController(ILogger<EventController> logger, UserService userService, EventService service) : base(logger, userService, service)
{
}
}
}

View File

@ -0,0 +1,19 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using API.DTO.Base.Update;
using API.Services;
using DAL.Models;
using DAL.Models.Audits;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class GrantController : CRUDBase<GrantController, GrantDTO, GrantUpdateDTO, Grant, AuditGrant, IYesAuthentication, GrantService>
{
public GrantController(ILogger<GrantController> logger, UserService userService, GrantService service) : base(logger, userService, service)
{
}
}
}

View File

@ -0,0 +1,19 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using API.DTO.Base.Update;
using API.Services;
using DAL.Models;
using DAL.Models.Audits;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class ImageController : CRUDBase<ImageController, ImageDTO, ImageUpdateDTO, Image, AuditImage, IYesAuthentication, ImageService>
{
public ImageController(ILogger<ImageController> logger, UserService userService, ImageService service) : base(logger, userService, service)
{
}
}
}

View File

@ -0,0 +1,19 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using API.DTO.Base.Update;
using API.Services;
using DAL.Models;
using DAL.Models.Audits;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class PermissionController : CRUDBase<PermissionController, PermissionDTO, PermissionUpdateDTO, Permission, AuditPermission, IYesAuthentication, PermissionService>
{
public PermissionController(ILogger<PermissionController> logger, UserService userService, PermissionService service) : base(logger, userService, service)
{
}
}
}

View File

@ -0,0 +1,19 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using API.DTO.Base.Update;
using API.Services;
using DAL.Models;
using DAL.Models.Audits;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class SavedEventController : CRUDBase<SavedEventController, SavedEventDTO, SavedEventUpdateDTO, SavedEvent, AuditSavedEvent, IYesAuthentication, SavedEventService>
{
public SavedEventController(ILogger<SavedEventController> logger, UserService userService, SavedEventService service) : base(logger, userService, service)
{
}
}
}

View File

@ -0,0 +1,19 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using API.DTO.Base.Update;
using API.Services;
using DAL.Models;
using DAL.Models.Audits;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class UserController : CRUDBase<UserController, UserDTO, UserUpdateDTO, User, AuditUser, IYesAuthentication, UserService>
{
public UserController(ILogger<UserController> logger, UserService userService, UserService service) : base(logger, userService, service)
{
}
}
}

View File

@ -23,7 +23,9 @@ namespace API.DTO.Base
red = red,
blue = blue,
green = green,
name = name
name = name,
updated = updated,
updater = updater
};
}
public void adaptFromModel(in Color model)
@ -33,6 +35,8 @@ namespace API.DTO.Base
blue = model.blue;
green = model.green;
name = model.name;
updated = model.updated;
updater = model.updater;
}
}
}

View File

@ -9,7 +9,7 @@ namespace API.DTO.Base
public ulong savedEventId { get; set; }
[MaxLength(64)]
public string? name { get; set; } = null!;
public string? name { get; set; }
public ulong? bgColorId { get; set; }
public ulong? fgColorId { get; set; }
@ -35,7 +35,15 @@ namespace API.DTO.Base
}
public void adaptFromModel(in Event model)
{
throw new NotImplementedException();
id = model.id;
savedEventId = model.savedEventId;
name = model.name;
bgColorId = model.bgColorId;
fgColorId = model.fgColorId;
imageId = model.imageId;
hidden = model.hidden;
updated = model.updated;
updater = model.updater;
}
}
}

View File

@ -29,7 +29,11 @@ namespace API.DTO.Base
}
public void adaptFromModel(in Grant model)
{
throw new NotImplementedException();
id = model.id;
name = model.name;
permissionId = model.permissionId;
updated = model.updated;
updater = model.updater;
}
}
}

View File

@ -30,7 +30,11 @@ namespace API.DTO.Base
}
public void adaptFromModel(in Image model)
{
throw new NotImplementedException();
id = model.id;
name = model.name;
filename = model.filename;
updated = model.updated;
updater = model.updater;
}
}
}

View File

@ -26,7 +26,10 @@ namespace API.DTO.Base
}
public void adaptFromModel(in Permission model)
{
throw new NotImplementedException();
id = model.id;
name = model.name;
updated = model.updated;
updater = model.updater;
}
}
}

View File

@ -35,7 +35,13 @@ namespace API.DTO.Base
}
public void adaptFromModel(in SavedEvent model)
{
throw new NotImplementedException();
id = model.id;
name = model.name;
bgColorId = model.bgColorId;
fgColorId = model.fgColorId;
imageId = model.imageId;
updated = model.updated;
updater = model.updater;
}
}
}

View File

@ -0,0 +1,28 @@
using DAL.Models;
using System.ComponentModel.DataAnnotations;
namespace API.DTO.Base.Update
{
public class EventUpdateDTO : IUpdateAdaptable<Event>
{
public ulong? savedEventId { get; set; }
[MaxLength(64)]
public UnSettable<string?>? name { get; set; }
public UnSettable<ulong?>? bgColorId { get; set; }
public UnSettable<ulong?>? fgColorId { get; set; }
public UnSettable<ulong?>? imageId { get; set; }
public bool? hidden { get; set; }
public void adaptModel(ref Event model)
{
if (savedEventId != null) model.savedEventId = (ulong)savedEventId;
if (name != null) model.name = ((UnSettable<string?>)name).value;
if (bgColorId != null) model.bgColorId = bgColorId.Value.value;
if (fgColorId != null) model.bgColorId = fgColorId.Value.value;
if (imageId != null) model.imageId = imageId.Value.value;
if (hidden != null) model.hidden = (bool)hidden;
}
}
}

View File

@ -0,0 +1,19 @@
using DAL.Models;
using System.ComponentModel.DataAnnotations;
namespace API.DTO.Base.Update
{
public class GrantUpdateDTO : IUpdateAdaptable<Grant>
{
[MaxLength(128)]
public string? name { get; set; }
public ulong? permissionId { get; set; }
public void adaptModel(ref Grant model)
{
if (name != null) model.name = name;
if (permissionId != null) model.permissionId = (ulong)permissionId;
}
}
}

View File

@ -0,0 +1,20 @@
using DAL.Models;
using System.ComponentModel.DataAnnotations;
namespace API.DTO.Base.Update
{
public class ImageUpdateDTO : IUpdateAdaptable<Image>
{
[MaxLength(64)]
public string? name { get; set; }
[MaxLength(128)]
public string? filename { get; set; }
public void adaptModel(ref Image model)
{
if (name != null) model.name = name;
if (filename != null) model.filename = filename;
}
}
}

View File

@ -0,0 +1,16 @@
using DAL.Models;
using System.ComponentModel.DataAnnotations;
namespace API.DTO.Base.Update
{
public class PermissionUpdateDTO : IUpdateAdaptable<Permission>
{
[MaxLength(64)]
public string? name { get; set; }
public void adaptModel(ref Permission model)
{
if (name != null) model.name = name;
}
}
}

View File

@ -0,0 +1,25 @@
using DAL.Models;
using System.ComponentModel.DataAnnotations;
namespace API.DTO.Base.Update
{
public class SavedEventUpdateDTO : IUpdateAdaptable<SavedEvent>
{
[MaxLength(64)]
public string? name { get; set; }
public ulong? bgColorId { get; set; }
public ulong? fgColorId { get; set; }
public UnSettable<ulong?>? imageId { get; set; }
public void adaptModel(ref SavedEvent model)
{
if (name != null) model.name = name;
if (bgColorId != null) model.bgColorId = (ulong)bgColorId;
if (fgColorId != null) model.fgColorId = (ulong)fgColorId;
if (imageId != null) model.imageId = imageId.Value.value;
}
}
}

View File

@ -0,0 +1,26 @@
using DAL.Models;
using System.ComponentModel.DataAnnotations;
namespace API.DTO.Base.Update
{
public class UserUpdateDTO : IUpdateAdaptable<User>
{
[MaxLength(64)]
public string? firstName { get; set; }
[MaxLength(64)]
public string? lastName { get; set; }
public ulong? phoneNumber { get; set; }
public ulong? permissionId { get; set; }
public void adaptModel(ref User model)
{
if (firstName != null) model.firstName = firstName;
if (lastName != null) model.lastName = lastName;
if (phoneNumber != null) model.phoneNumber = (ulong)phoneNumber;
if (permissionId != null) model.permissionId = (ulong)permissionId;
}
}
}

View File

@ -36,7 +36,13 @@ namespace API.DTO.Base
}
public void adaptFromModel(in User model)
{
throw new NotImplementedException();
id = model.id;
firstName = model.firstName;
lastName = model.lastName;
phoneNumber = model.phoneNumber;
permissionId = model.permissionId;
updated = model.updated;
updater = model.updater;
}
}
}

7
API/DTO/UnSettable.cs Normal file
View File

@ -0,0 +1,7 @@
namespace API.DTO
{
public struct UnSettable<T>
{
public T value { get; set; }
}
}

View File

@ -7,12 +7,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0-preview.3.24172.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0-preview.3.24172.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0-preview.3.24172.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0-preview.3.24172.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.EntityFrameworkCore" Version="8.0.0"/>
</ItemGroup>
</Project>