Refactor data model: rename entities and update mappings
This commit includes a significant refactoring of the data model, renaming `ProfileObject` to `PObject` and `ProfileControlsTF` to `PControlsTF`. Key changes: - Updated `IProfileObjRepository` to reflect new entity names. - Added `TFControls` property to `ObjectDto`. - Adjusted `MappingProfile` for new entity mappings. - Replaced `ProfileControlsTF` and `ProfileObjState` with `PControlsTF` and `PObjectState`. - Updated `WFDBContext` with new DbSet properties for the renamed entities. - Modified `ProfileObjRepository` to align with the new data structure. These changes enhance clarity and maintainability across the application.
This commit is contained in:
parent
c2e8b335e0
commit
a3cbe69fd6
@ -3,21 +3,21 @@
|
||||
namespace WorkFlow.Application.Contracts.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Repository for retrieving <see cref="ProfileObject"/> entities from the database.
|
||||
/// Repository for retrieving <see cref="PObject"/> entities from the database.
|
||||
/// </summary>
|
||||
public interface IProfileObjRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the list of <see cref="ProfileObject"/> associated with a given user ID and profile ID by calling a database function.
|
||||
/// Retrieves the list of <see cref="PObject"/> associated with a given user ID and profile ID by calling a database function.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the user whose profile is to be retrieved.</param>
|
||||
/// <param name="profileId">The unique identifier of the profile whose object is to be retrieved.</param>
|
||||
/// <param name="cancel">Propagates notification that operations should be canceled.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the <see cref="ProfileObject"/> object if found; otherwise, <c>null</c>.
|
||||
/// A task that represents the asynchronous operation. The task result contains the <see cref="PObject"/> object if found; otherwise, <c>null</c>.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// Logs an error if no profile is found, or if multiple profiles are returned, indicating potential data issues.
|
||||
/// </remarks>
|
||||
public Task<IEnumerable<ProfileObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default);
|
||||
public Task<IEnumerable<PObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default);
|
||||
}
|
||||
@ -13,4 +13,6 @@ public class ObjectDto
|
||||
public string? CmdCheckIn { get; set; }
|
||||
|
||||
public IEnumerable<string?> States { get; set; } = Array.Empty<string>();
|
||||
|
||||
public IEnumerable<ProfileControlsTFDto> TFControls { get; set; } = Array.Empty<ProfileControlsTFDto>();
|
||||
}
|
||||
|
||||
@ -11,14 +11,13 @@ public class MappingProfile : AutoMapper.Profile
|
||||
// Mapping entity to DTO
|
||||
CreateMap<Config, ConfigDto>();
|
||||
CreateMap<Profile, ProfileDto>();
|
||||
CreateMap<ProfileControlsTF, ProfileControlsTFDto>();
|
||||
CreateMap<PControlsTF, ProfileControlsTFDto>();
|
||||
CreateMap<State, StateDto>();
|
||||
CreateMap<Button, ButtonDto>();
|
||||
CreateMap<ProfileObject, ObjectDto>()
|
||||
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src =>
|
||||
new[] { src.Headline1, src.Headline2 }))
|
||||
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src =>
|
||||
new[] { src.Subline1, src.Subline2 }))
|
||||
.ForMember(dest => dest.States, opt => opt.MapFrom(src => src.States != null ? src.States.ToList() : Array.Empty<string>()));
|
||||
CreateMap<PObject, ObjectDto>()
|
||||
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src => new[] { src.Headline1, src.Headline2 }))
|
||||
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src => new[] { src.Subline1, src.Subline2 }))
|
||||
.ForMember(dest => dest.States, opt => opt.MapFrom(src => src.State != null ? src.State.ToList() : Array.Empty<string>()))
|
||||
.ForMember(dest => dest.TFControls, opt => opt.MapFrom(src => src.State != null ? src.State.TFControls : null));
|
||||
}
|
||||
}
|
||||
@ -4,20 +4,15 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_PROF_CONTROLS_TF", Schema = "dbo")]
|
||||
public class ProfileControlsTF
|
||||
public class PControlsTF
|
||||
{
|
||||
[Key]
|
||||
[Column("GUID", TypeName = "bigint")]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Although this field is marked as <c>nullable</c> in the database schema to allow
|
||||
/// for greater flexibility during database-level operations or migrations, it is
|
||||
/// treated as <c>required</c> and <c>not null</c> within the application logic.
|
||||
/// Validation should be enforced at the application level to ensure a value is provided.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Column("OBJ_STATE_ID", TypeName = "bigint")]
|
||||
public long? ObjStateId { get; set; }
|
||||
public long ObjStateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Although this field is marked as <c>nullable</c> in the database schema to allow
|
||||
@ -96,7 +91,4 @@ public class ProfileControlsTF
|
||||
|
||||
[Column("ADDED_WHEN", TypeName = "datetime")]
|
||||
public DateTime AddedWhen { get; set; }
|
||||
|
||||
[ForeignKey("ObjStateId")]
|
||||
public virtual ProfileObjState? State { get; set; }
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
public class ProfileObject
|
||||
public class PObject
|
||||
{
|
||||
[Column("ObjStateID")]
|
||||
public long? ObjStateId { get; set; }
|
||||
@ -26,5 +26,5 @@ public class ProfileObject
|
||||
public string? CmdCheckIn { get; set; }
|
||||
|
||||
[ForeignKey("ObjStateId")]
|
||||
public virtual ProfileObjState? States { get; set; }
|
||||
public virtual PObjectState? State { get; set; }
|
||||
}
|
||||
@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace WorkFlow.Domain.Entities;
|
||||
|
||||
[Table("TBMWF_PROFILE_OBJ_STATE", Schema = "dbo")]
|
||||
public class ProfileObjState
|
||||
public class PObjectState
|
||||
{
|
||||
[Key]
|
||||
[Column("GUID", TypeName = "bigint")]
|
||||
@ -82,7 +82,7 @@ public class ProfileObjState
|
||||
[ForeignKey("ObjStateId")]
|
||||
public virtual State? State1 { get; set; }
|
||||
|
||||
public IEnumerable<ProfileControlsTF> TFControls { get; set; } = Array.Empty<ProfileControlsTF>();
|
||||
public IEnumerable<PControlsTF> TFControls { get; set; } = Array.Empty<PControlsTF>();
|
||||
|
||||
public IEnumerable<string?> ToList() => new List<string?>
|
||||
{
|
||||
@ -26,7 +26,7 @@ public class Profile
|
||||
public string? BackColor { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public IEnumerable<ProfileObject>? Objects { get; set; }
|
||||
public IEnumerable<PObject>? Objects { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public IEnumerable<Button>? Buttons { get; set; }
|
||||
|
||||
@ -16,11 +16,11 @@ public static class DependencyInjection
|
||||
services.TryAddScoped<IProfileObjRepository, ProfileObjRepository>();
|
||||
|
||||
services.AddDbRepository<WFDBContext, Config>(c => c.Configs).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, ProfileControlsTF>(c => c.ProfileControlsTFs).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, PControlsTF>(c => c.ProfileControlsTFs).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, State>(c => c.States).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, Button>(c => c.Buttons).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, State>(c => c.States).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, ProfileObjState>(c => c.ProfileObjStates).UseAutoMapper();
|
||||
services.AddDbRepository<WFDBContext, PObjectState>(c => c.ProfileObjStates).UseAutoMapper();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ using WorkFlow.Domain.Entities;
|
||||
namespace WorkFlow.Infrastructure.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Repository implementation for retrieving <see cref="ProfileObject"/> entities from the database.
|
||||
/// Repository implementation for retrieving <see cref="PObject"/> entities from the database.
|
||||
/// </summary>
|
||||
public class ProfileObjRepository : IProfileObjRepository
|
||||
{
|
||||
@ -21,21 +21,21 @@ public class ProfileObjRepository : IProfileObjRepository
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the list of <see cref="ProfileObject"/> associated with a given user ID and profile ID by calling a database function.
|
||||
/// Retrieves the list of <see cref="PObject"/> associated with a given user ID and profile ID by calling a database function.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the user whose profile is to be retrieved.</param>
|
||||
/// <param name="profileId">The unique identifier of the profile whose object is to be retrieved.</param>
|
||||
/// <param name="cancel">Propagates notification that operations should be canceled.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the <see cref="ProfileObject"/> object if found; otherwise, <c>null</c>.
|
||||
/// A task that represents the asynchronous operation. The task result contains the <see cref="PObject"/> object if found; otherwise, <c>null</c>.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// Logs an error if no profile is found, or if multiple profiles are returned, indicating potential data issues.
|
||||
/// </remarks>
|
||||
public async Task<IEnumerable<ProfileObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default)
|
||||
public async Task<IEnumerable<PObject>> ReadAsync(int userId, int profileId, CancellationToken cancel = default)
|
||||
=> await _context.Objects
|
||||
.FromSqlRaw("SELECT * FROM [FNMWF_GET_PROFILE_OBJECTS] ({0}, {1})", userId, profileId)
|
||||
.Include(obj => obj.States).ThenInclude(objState => objState != null ? objState.State1 : null)
|
||||
.Include(obj => obj.States).ThenInclude(objState => objState != null ? objState.TFControls : null)
|
||||
.Include(obj => obj.State).ThenInclude(objState => objState != null ? objState.State1 : null)
|
||||
.Include(obj => obj.State).ThenInclude(objState => objState != null ? objState.TFControls : null)
|
||||
.ToListAsync(cancel);
|
||||
}
|
||||
@ -11,13 +11,13 @@ public class WFDBContext : DbContext, IUserManagerDbContext
|
||||
{
|
||||
public DbSet<Config> Configs { get; set; }
|
||||
|
||||
public DbSet<ProfileControlsTF> ProfileControlsTFs { get; set; }
|
||||
public DbSet<PControlsTF> ProfileControlsTFs { get; set; }
|
||||
|
||||
public DbSet<Profile> Profiles { get; set; }
|
||||
|
||||
public DbSet<ProfileObject> Objects { get; set; }
|
||||
public DbSet<PObject> Objects { get; set; }
|
||||
|
||||
public DbSet<ProfileObjState> ProfileObjStates { get; set; }
|
||||
public DbSet<PObjectState> ProfileObjStates { get; set; }
|
||||
|
||||
public DbSet<State> States { get; set; }
|
||||
|
||||
@ -46,8 +46,8 @@ public class WFDBContext : DbContext, IUserManagerDbContext
|
||||
//configure model builder for user manager tables
|
||||
modelBuilder.ConfigureUserManager();
|
||||
|
||||
modelBuilder.Entity<ProfileObjState>()
|
||||
.HasMany(pos => pos.ControlsTF)
|
||||
modelBuilder.Entity<PObjectState>()
|
||||
.HasMany(pos => pos.TFControls)
|
||||
.WithOne()
|
||||
.HasForeignKey(pctf => pctf.ObjStateId)
|
||||
.HasPrincipalKey(pos => pos.Id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user