Skip to content

Commit

Permalink
rename repositories and db models
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkoSekulic committed Jan 10, 2025
1 parent c091a31 commit c9a23f1
Show file tree
Hide file tree
Showing 33 changed files with 79 additions and 80 deletions.
4 changes: 2 additions & 2 deletions backend/src/Designer/Infrastructure/ServiceRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static IServiceCollection RegisterServiceImplementations(this IServiceCol
options.UseNpgsql(postgresSettings.FormattedConnectionString());
});

services.AddScoped<IReleaseRepository, ORMReleaseRepository>();
services.AddScoped<IDeploymentRepository, ORMDeploymentRepository>();
services.AddScoped<IReleaseRepository, ReleaseRepository>();
services.AddScoped<IDeploymentRepository, DeploymentRepository>();
services.AddScoped<IAppScopesRepository, AppScopesRepository>();
services.AddTransient<IReleaseService, ReleaseService>();
services.AddTransient<IDeploymentService, DeploymentService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<AppScopesEntity> GetAppScopesAsync(AltinnRepoContext repoConte
public async Task<AppScopesEntity> UpsertAppScopesAsync(AppScopesEntity appScopesEntity,
CancellationToken cancellationToken = default)
{
AppScopesDbObject existing = await _dbContext.AppScopes.AsNoTracking().SingleOrDefaultAsync(a => a.Org == appScopesEntity.Org && a.App == appScopesEntity.App, cancellationToken);
AppScopesDbModel existing = await _dbContext.AppScopes.AsNoTracking().SingleOrDefaultAsync(a => a.Org == appScopesEntity.Org && a.App == appScopesEntity.App, cancellationToken);

var dbObject = existing is null
? AppScopesMapper.MapToDbModel(appScopesEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public DesignerdbContext(DbContextOptions<DesignerdbContext> options)
{
}

public virtual DbSet<Deployment> Deployments { get; set; }
public virtual DbSet<Release> Releases { get; set; }
public virtual DbSet<AppScopesDbObject> AppScopes { get; set; }
public virtual DbSet<DeploymentDbModel> Deployments { get; set; }
public virtual DbSet<ReleaseDbModel> Releases { get; set; }
public virtual DbSet<AppScopesDbModel> AppScopes { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Data.EntityConfigurations;

public class AppScopesConfiguration : IEntityTypeConfiguration<AppScopesDbObject>
public class AppScopesConfiguration : IEntityTypeConfiguration<AppScopesDbModel>
{
public void Configure(EntityTypeBuilder<AppScopesDbObject> builder)
public void Configure(EntityTypeBuilder<AppScopesDbModel> builder)
{
builder.ToTable("app_scopes", "designer");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Data.EntityConfigurations;

public class BuildConfiguration : IEntityTypeConfiguration<BuildDbObject>
public class BuildConfiguration : IEntityTypeConfiguration<BuildDbModel>
{
public void Configure(EntityTypeBuilder<BuildDbObject> builder)
public void Configure(EntityTypeBuilder<BuildDbModel> builder)
{
builder.ToTable("builds", "designer");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Data.EntityConfigurations;

public class DeploymentConfiguration : IEntityTypeConfiguration<Deployment>
public class DeploymentConfiguration : IEntityTypeConfiguration<DeploymentDbModel>
{
public void Configure(EntityTypeBuilder<Deployment> builder)
public void Configure(EntityTypeBuilder<DeploymentDbModel> builder)
{
builder.HasKey(e => e.Sequenceno).HasName("deployments_pkey");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Data.EntityConfigurations;

public class ReleaseConfiguration : IEntityTypeConfiguration<Release>
public class ReleaseConfiguration : IEntityTypeConfiguration<ReleaseDbModel>
{
public void Configure(EntityTypeBuilder<Release> builder)
public void Configure(EntityTypeBuilder<ReleaseDbModel> builder)
{
builder.HasKey(e => e.Sequenceno).HasName("releases_pkey");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation;

public class ORMDeploymentRepository : IDeploymentRepository
public class DeploymentRepository : IDeploymentRepository
{
private readonly DesignerdbContext _dbContext;

public ORMDeploymentRepository(DesignerdbContext dbContext)
public DeploymentRepository(DesignerdbContext dbContext)
{
_dbContext = dbContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class AppScopesMapper
WriteIndented = false
};

public static AppScopesDbObject MapToDbModel(AppScopesEntity appScopes)
public static AppScopesDbModel MapToDbModel(AppScopesEntity appScopes)
{
return new AppScopesDbObject
return new AppScopesDbModel
{
App = appScopes.App,
Org = appScopes.Org,
Expand All @@ -27,24 +27,24 @@ public static AppScopesDbObject MapToDbModel(AppScopesEntity appScopes)
};
}

public static AppScopesDbObject MapToDbModel(AppScopesEntity appScopes, long id)
public static AppScopesDbModel MapToDbModel(AppScopesEntity appScopes, long id)
{
var dbModel = MapToDbModel(appScopes);
dbModel.Id = id;
return dbModel;
}

public static AppScopesEntity MapToModel(AppScopesDbObject appScopesDbObject)
public static AppScopesEntity MapToModel(AppScopesDbModel appScopesDbModel)
{
return new AppScopesEntity
{
App = appScopesDbObject.App,
Org = appScopesDbObject.Org,
Created = appScopesDbObject.Created,
Scopes = JsonSerializer.Deserialize<ISet<MaskinPortenScopeEntity>>(appScopesDbObject.Scopes, s_jsonOptions),
CreatedBy = appScopesDbObject.CreatedBy,
LastModifiedBy = appScopesDbObject.LastModifiedBy,
Version = appScopesDbObject.Version
App = appScopesDbModel.App,
Org = appScopesDbModel.Org,
Created = appScopesDbModel.Created,
Scopes = JsonSerializer.Deserialize<ISet<MaskinPortenScopeEntity>>(appScopesDbModel.Scopes, s_jsonOptions),
CreatedBy = appScopesDbModel.CreatedBy,
LastModifiedBy = appScopesDbModel.LastModifiedBy,
Version = appScopesDbModel.Version
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace Altinn.Studio.Designer.Repository.ORMImplementation.Mappers;

public static class BuildMapper
{
public static BuildEntity MapToModel(BuildDbObject buildDbObject) =>
public static BuildEntity MapToModel(BuildDbModel buildDbModel) =>
new()
{
Id = buildDbObject.ExternalId,
Status = Enum.Parse<BuildStatus>(buildDbObject.Status, true),
Result = Enum.Parse<BuildResult>(buildDbObject.Result, true),
Started = buildDbObject.Started?.DateTime,
Finished = buildDbObject.Finished?.DateTime
Id = buildDbModel.ExternalId,
Status = Enum.Parse<BuildStatus>(buildDbModel.Status, true),
Result = Enum.Parse<BuildResult>(buildDbModel.Result, true),
Started = buildDbModel.Started?.DateTime,
Finished = buildDbModel.Finished?.DateTime
};

public static BuildDbObject MapToDbModel(BuildEntity buildEntity, BuildType buildType) =>
public static BuildDbModel MapToDbModel(BuildEntity buildEntity, BuildType buildType) =>
new()
{
ExternalId = buildEntity.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Altinn.Studio.Designer.Repository.Models;
using Altinn.Studio.Designer.Repository.ORMImplementation.Models;
using Altinn.Studio.Designer.TypedHttpClients.AzureDevOps.Enums;
using Deployment = Altinn.Studio.Designer.Repository.ORMImplementation.Models.Deployment;

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Mappers;

Expand All @@ -18,9 +17,9 @@ public static class DeploymentMapper
Converters = { new JsonStringEnumConverter() }
};

public static Deployment MapToDbModel(DeploymentEntity deploymentEntity)
public static DeploymentDbModel MapToDbModel(DeploymentEntity deploymentEntity)
{
return new Deployment
return new DeploymentDbModel
{
Buildid = deploymentEntity.Build.Id,
Tagname = deploymentEntity.TagName,
Expand All @@ -33,7 +32,7 @@ public static Deployment MapToDbModel(DeploymentEntity deploymentEntity)
Build = BuildMapper.MapToDbModel(deploymentEntity.Build, BuildType.Deployment),
};
}
public static Deployment MapToDbModel(DeploymentEntity deploymentEntity, long deploymentSequenceNo, long buildId)
public static DeploymentDbModel MapToDbModel(DeploymentEntity deploymentEntity, long deploymentSequenceNo, long buildId)
{
var dbModel = MapToDbModel(deploymentEntity);
dbModel.Sequenceno = deploymentSequenceNo;
Expand All @@ -42,7 +41,7 @@ public static Deployment MapToDbModel(DeploymentEntity deploymentEntity, long de
return dbModel;
}

public static DeploymentEntity MapToModel(Deployment dbObject)
public static DeploymentEntity MapToModel(DeploymentDbModel dbObject)
{
return new DeploymentEntity
{
Expand All @@ -56,7 +55,7 @@ public static DeploymentEntity MapToModel(Deployment dbObject)
};
}

public static IEnumerable<DeploymentEntity> MapToModels(IEnumerable<Deployment> deployments)
public static IEnumerable<DeploymentEntity> MapToModels(IEnumerable<DeploymentDbModel> deployments)
{
return deployments.Select(MapToModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static class ReleaseMapper
Converters = { new JsonStringEnumConverter() }
};

public static Release MapToDbModel(ReleaseEntity releaseEntity)
public static ReleaseDbModel MapToDbModel(ReleaseEntity releaseEntity)
{
return new Release
return new ReleaseDbModel
{
Buildid = releaseEntity.Build.Id,
Tagname = releaseEntity.TagName,
Expand All @@ -32,19 +32,19 @@ public static Release MapToDbModel(ReleaseEntity releaseEntity)
};
}

public static Release MapToDbModel(long sequenceNo, ReleaseEntity releaseEntity)
public static ReleaseDbModel MapToDbModel(long sequenceNo, ReleaseEntity releaseEntity)
{
var dbModel = MapToDbModel(releaseEntity);
dbModel.Sequenceno = sequenceNo;
return dbModel;
}

public static ReleaseEntity MapToModel(Release release)
public static ReleaseEntity MapToModel(ReleaseDbModel releaseDbModel)
{
return JsonSerializer.Deserialize<ReleaseEntity>(release.Entity, s_jsonOptions);
return JsonSerializer.Deserialize<ReleaseEntity>(releaseDbModel.Entity, s_jsonOptions);
}

public static IEnumerable<ReleaseEntity> MapToModels(IEnumerable<Release> releases)
public static IEnumerable<ReleaseEntity> MapToModels(IEnumerable<ReleaseDbModel> releases)
{
return releases.Select(MapToModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Models;

public class AppScopesDbObject
public class AppScopesDbModel
{
/// <summary>
/// The unique identifier for the object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Models;

public class BuildDbObject
public class BuildDbModel
{
public long Id { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Models;

public partial class Deployment
public partial class DeploymentDbModel
{
public long Sequenceno { get; set; }

Expand All @@ -26,5 +26,5 @@ public partial class Deployment

public long? InternalBuildId { get; set; }

public BuildDbObject Build { get; set; } = null!;
public BuildDbModel Build { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation.Models;

public partial class Release
public partial class ReleaseDbModel
{
public long Sequenceno { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Altinn.Studio.Designer.Repository.ORMImplementation;

public class ORMReleaseRepository : IReleaseRepository
public class ReleaseRepository : IReleaseRepository
{
private readonly DesignerdbContext _dbContext;

public ORMReleaseRepository(DesignerdbContext dbContext)
public ReleaseRepository(DesignerdbContext dbContext)
{
_dbContext = dbContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Designer.Tests.DbIntegrationTests;

public partial class EntityAssertions
{
public static void AssertEqual(AppScopesEntity appScopesEntity, Altinn.Studio.Designer.Repository.ORMImplementation.Models.AppScopesDbObject dbRecord)
public static void AssertEqual(AppScopesEntity appScopesEntity, Altinn.Studio.Designer.Repository.ORMImplementation.Models.AppScopesDbModel dbRecord)
{
dbRecord.App.Should().BeEquivalentTo(appScopesEntity.App);
dbRecord.Org.Should().BeEquivalentTo(appScopesEntity.Org);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected async Task PrepareEntitiesInDatabase(IEnumerable<DeploymentEntity> dep
}
}

private Altinn.Studio.Designer.Repository.ORMImplementation.Models.Deployment MapToDbObject(DeploymentEntity entity) =>
private Altinn.Studio.Designer.Repository.ORMImplementation.Models.DeploymentDbModel MapToDbObject(DeploymentEntity entity) =>
new()
{
Buildid = entity.Build.Id,
Expand All @@ -52,7 +52,7 @@ private Altinn.Studio.Designer.Repository.ORMImplementation.Models.Deployment Ma
Build = MapBuildToDbModel(entity.Build)
};

private static Altinn.Studio.Designer.Repository.ORMImplementation.Models.BuildDbObject MapBuildToDbModel(BuildEntity buildEntity) =>
private static Altinn.Studio.Designer.Repository.ORMImplementation.Models.BuildDbModel MapBuildToDbModel(BuildEntity buildEntity) =>
new()
{
ExternalId = buildEntity.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CreateIntegrationTests(DesignerDbFixture dbFixture) : base(dbFixture)
[InlineData("ttd")]
public async Task Create_ShouldInsertRecordInDatabase(string org)
{
var repository = new ORMDeploymentRepository(DbFixture.DbContext);
var repository = new DeploymentRepository(DbFixture.DbContext);
var buildId = Guid.NewGuid();
var deploymentEntity = EntityGenerationUtils.Deployment.GenerateDeploymentEntity(org, buildId: buildId.ToString());
await repository.Create(deploymentEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task Get_ShouldReturnCorrectRecordsFromDatabase(string org, string
var deploymentEntities = EntityGenerationUtils.Deployment.GenerateDeploymentEntities(org, app, allEntitiesCount).ToList();
await PrepareEntitiesInDatabase(deploymentEntities);

var repository = new ORMDeploymentRepository(DbFixture.DbContext);
var repository = new DeploymentRepository(DbFixture.DbContext);
var query = new DocumentQueryModel { Top = top, SortDirection = sortDirection };
var result = (await repository.Get(org, app, query)).ToList();

Expand All @@ -52,7 +52,7 @@ public async Task Get_Without_TopDefined_ShouldReturnAllRecordsForGivenApp(strin
var deploymentEntities = EntityGenerationUtils.Deployment.GenerateDeploymentEntities(org, app, allEntitiesCount).ToList();
await PrepareEntitiesInDatabase(deploymentEntities);

var repository = new ORMDeploymentRepository(DbFixture.DbContext);
var repository = new DeploymentRepository(DbFixture.DbContext);
var query = new DocumentQueryModel
{
Top = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task Get_ShouldReturnRecordFromDatabase(string org)
var deploymentEntity = EntityGenerationUtils.Deployment.GenerateDeploymentEntity(org);
await PrepareEntityInDatabase(deploymentEntity);

var repository = new ORMDeploymentRepository(DbFixture.DbContext);
var repository = new DeploymentRepository(DbFixture.DbContext);
var result = await repository.Get(deploymentEntity.Org, deploymentEntity.Build.Id);

result.Should().BeEquivalentTo(deploymentEntity, options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public UpdateIntegrationTests(DesignerDbFixture dbFixture) : base(dbFixture)
[InlineData("ttd")]
public async Task Update_ShouldUpdateRecordInDatabase(string org)
{
var repository = new ORMDeploymentRepository(DbFixture.DbContext);
var repository = new DeploymentRepository(DbFixture.DbContext);
var buildId = Guid.NewGuid();
var deploymentEntity = EntityGenerationUtils.Deployment.GenerateDeploymentEntity(
org,
Expand Down
Loading

0 comments on commit c9a23f1

Please sign in to comment.