Skip to content

Commit

Permalink
Cwdoe 1372 build inject catalog api (#102)
Browse files Browse the repository at this point in the history
* add models to DB and new migration
* add services and controllers
  • Loading branch information
sei-tspencer authored Jun 14, 2024
1 parent fd5001f commit c545ae2
Show file tree
Hide file tree
Showing 38 changed files with 4,904 additions and 18 deletions.
5 changes: 5 additions & 0 deletions Blueprint.Api.Data/BlueprintContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ public BlueprintContext(DbContextOptions<BlueprintContext> options) : base(optio
public DbSet<OrganizationEntity> Organizations { get; set; }
public DbSet<CardEntity> Cards { get; set; }
public DbSet<CardTeamEntity> CardTeams { get; set; }
public DbSet<CatalogEntity> Catalogs { get; set; }
public DbSet<CatalogInjectEntity> CatalogInjects { get; set; }
public DbSet<CatalogUnitEntity> CatalogUnits { get; set; }
public DbSet<CiteActionEntity> CiteActions { get; set; }
public DbSet<CiteRoleEntity> CiteRoles { get; set; }
public DbSet<InjectTypeEntity> InjectTypes { get; set; }
public DbSet<PlayerApplicationEntity> PlayerApplications { get; set; }
public DbSet<PlayerApplicationTeamEntity> PlayerApplicationTeams { get; set; }
public DbSet<MselPageEntity> MselPages { get; set; }
public DbSet<InjectEntity> Injects { get; set; }
public DbSet<InvitationEntity> Invitations { get; set; }
public DbSet<UnitEntity> Units { get; set; }
public DbSet<UnitUserEntity> UnitUsers { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions Blueprint.Api.Data/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public enum IntegrationType {
Connect = 30
}

public enum EventType {
Inject = 10,
Information = 20,
Facilitation = 30
}

public enum EventExecutionStatus
{
Executed = 10,
Expand Down
39 changes: 39 additions & 0 deletions Blueprint.Api.Data/Models/Catalog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license, please see LICENSE.md in the project root for license information or contact [email protected] for full terms.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Blueprint.Api.Data.Models
{
public class CatalogEntity : BaseEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Guid InjectTypeId { get; set; }
public InjectTypeEntity InjectType { get; set; }
public bool IsPublic { get; set; }
public Guid? ParentId { get; set; }
public CatalogEntity Parent { get; set; }
public virtual ICollection<InjectEntity> Injects { get; set; } = new HashSet<InjectEntity>();
public virtual ICollection<CatalogUnitEntity> CatalogUnits { get; set; } = new HashSet<CatalogUnitEntity>();
public virtual ICollection<CatalogInjectEntity> CatalogInjects { get; set; } = new HashSet<CatalogInjectEntity>();
}

public class CatalogConfiguration : IEntityTypeConfiguration<CatalogEntity>
{
public void Configure(EntityTypeBuilder<CatalogEntity> builder)
{
builder.HasIndex(x => new { x.Name }).IsUnique();
}
}

}

52 changes: 52 additions & 0 deletions Blueprint.Api.Data/Models/CatalogInject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license, please see LICENSE.md in the project root for license information or contact [email protected] for full terms.

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Blueprint.Api.Data.Models
{
public class CatalogInjectEntity
{
public CatalogInjectEntity() { }

public CatalogInjectEntity(Guid injectId, Guid catalogId)
{
InjectId = injectId;
CatalogId = catalogId;
}

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }

public Guid InjectId { get; set; }
public InjectEntity Inject { get; set; }

public Guid CatalogId { get; set; }
public CatalogEntity Catalog { get; set; }
}

public class CatalogInjectConfiguration : IEntityTypeConfiguration<CatalogInjectEntity>
{
public void Configure(EntityTypeBuilder<CatalogInjectEntity> builder)
{
builder.HasIndex(x => new { x.InjectId, x.CatalogId }).IsUnique();

builder
.HasOne(u => u.Inject)
.WithMany(p => p.CatalogInjects)
.HasForeignKey(x => x.InjectId)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(u => u.Catalog)
.WithMany(p => p.CatalogInjects)
.HasForeignKey(x => x.CatalogId)
.OnDelete(DeleteBehavior.Cascade);
}
}
}

52 changes: 52 additions & 0 deletions Blueprint.Api.Data/Models/CatalogUnit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license, please see LICENSE.md in the project root for license information or contact [email protected] for full terms.

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Blueprint.Api.Data.Models
{
public class CatalogUnitEntity
{
public CatalogUnitEntity() { }

public CatalogUnitEntity(Guid unitId, Guid catalogId)
{
UnitId = unitId;
CatalogId = catalogId;
}

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }

public Guid UnitId { get; set; }
public UnitEntity Unit { get; set; }

public Guid CatalogId { get; set; }
public CatalogEntity Catalog { get; set; }
}

public class CatalogUnitConfiguration : IEntityTypeConfiguration<CatalogUnitEntity>
{
public void Configure(EntityTypeBuilder<CatalogUnitEntity> builder)
{
builder.HasIndex(x => new { x.UnitId, x.CatalogId }).IsUnique();

builder
.HasOne(u => u.Unit)
.WithMany(p => p.CatalogUnits)
.HasForeignKey(x => x.UnitId)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(u => u.Catalog)
.WithMany(p => p.CatalogUnits)
.HasForeignKey(x => x.CatalogId)
.OnDelete(DeleteBehavior.Cascade);
}
}
}

9 changes: 8 additions & 1 deletion Blueprint.Api.Data/Models/DataField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class DataFieldEntity : BaseEntity
public Guid Id { get; set; }
public Guid? MselId { get; set; }
public virtual MselEntity Msel { get; set; }
public Guid? InjectTypeId { get; set; }
public virtual InjectTypeEntity InjectType { get; set; }
public string Name { get; set; }
public DataFieldType DataType { get; set; }
public int DisplayOrder { get; set; }
Expand All @@ -37,12 +39,17 @@ public class DataFieldEntityConfiguration : IEntityTypeConfiguration<DataFieldEn
{
public void Configure(EntityTypeBuilder<DataFieldEntity> builder)
{
builder.HasCheckConstraint("data_field_msel_or_inject_type",
"(msel_id IS NOT NULL AND inject_type_id IS NULL) OR (msel_id IS NULL AND inject_type_id IS NOT NULL)");
builder
.HasOne(d => d.Msel)
.WithMany(d => d.DataFields)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(d => d.InjectType)
.WithMany(d => d.DataFields)
.OnDelete(DeleteBehavior.Cascade);
}
}

}

13 changes: 10 additions & 3 deletions Blueprint.Api.Data/Models/DataValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public class DataValueEntity : BaseEntity
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public string Value { get; set; }
public Guid ScenarioEventId { get; set; }
public Guid? ScenarioEventId { get; set; }
public virtual ScenarioEventEntity ScenarioEvent { get; set; }
public Guid? InjectId { get; set; }
public virtual InjectEntity Inject { get; set; }
public Guid DataFieldId { get; set; }
public virtual DataFieldEntity DataField { get; set; }
public string CellMetadata { get; set; }
Expand All @@ -27,13 +29,18 @@ public class DataValueEntityConfiguration : IEntityTypeConfiguration<DataValueEn
public void Configure(EntityTypeBuilder<DataValueEntity> builder)
{
builder.HasIndex(e => e.Id).IsUnique();
builder.HasIndex(e => new { e.ScenarioEventId, e.DataFieldId }).IsUnique();
builder.HasCheckConstraint("data_value_scenario_event_or_inject",
"(scenario_event_id IS NOT NULL AND inject_id IS NULL) OR (scenario_event_id IS NULL AND inject_id IS NOT NULL)");
builder.HasIndex(e => new { e.ScenarioEventId, e.InjectId, e.DataFieldId }).IsUnique();
builder
.HasOne(d => d.ScenarioEvent)
.WithMany(d => d.DataValues)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(d => d.Inject)
.WithMany(d => d.DataValues)
.OnDelete(DeleteBehavior.Cascade);
}
}

}

25 changes: 25 additions & 0 deletions Blueprint.Api.Data/Models/Inject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license, please see LICENSE.md in the project root for license information or contact [email protected] for full terms.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Blueprint.Api.Data.Models
{
public class InjectEntity : BaseEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public Guid InjectTypeId { get; set; }
public InjectTypeEntity InjectType { get; set; }
public Guid? RequiresInjectId { get; set; }
public virtual InjectEntity RequiresInject { get; set; }
public virtual ICollection<DataValueEntity> DataValues { get; set; } = new HashSet<DataValueEntity>();
public virtual ICollection<CatalogInjectEntity> CatalogInjects { get; set; } = new HashSet<CatalogInjectEntity>();
}

}

31 changes: 31 additions & 0 deletions Blueprint.Api.Data/Models/InjectType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license, please see LICENSE.md in the project root for license information or contact [email protected] for full terms.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Blueprint.Api.Data.Models
{
public class InjectTypeEntity : BaseEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<DataFieldEntity> DataFields { get; set; } = new HashSet<DataFieldEntity>();
}

public class InjectTypeConfiguration : IEntityTypeConfiguration<InjectTypeEntity>
{
public void Configure(EntityTypeBuilder<InjectTypeEntity> builder)
{
builder.HasIndex(x => new { x.Name }).IsUnique();
}
}
}

4 changes: 4 additions & 0 deletions Blueprint.Api.Data/Models/ScenarioEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class ScenarioEventEntity : BaseEntity
public bool IsHidden { get; set; } // flag that hides the secenario event on the Exercise View shown to participants
public string RowMetadata { get; set; } // comma separated values (row height number, integer R, integer G, integer B)
public int DeltaSeconds { get; set; } // time from the start of the MSEL when this event should be executed
public EventType ScenarioEventType { get; set; }
public string Description { get; set; }
public Guid? InjectId { get; set; }
public InjectEntity Inject { get; set; }
}

public class ScenarioEventEntityConfiguration : IEntityTypeConfiguration<ScenarioEventEntity>
Expand Down
2 changes: 1 addition & 1 deletion Blueprint.Api.Data/Models/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UnitEntity : BaseEntity
public string ShortName { get; set; }
public ICollection<UnitUserEntity> UnitUsers { get; set; } = new List<UnitUserEntity>();
public virtual ICollection<MselUnitEntity> MselUnits { get; set; } = new HashSet<MselUnitEntity>();
public Guid? OldTeamId { get; set; }
public virtual ICollection<CatalogUnitEntity> CatalogUnits { get; set; } = new HashSet<CatalogUnitEntity>();
}

public class UnitConfiguration : IEntityTypeConfiguration<UnitEntity>
Expand Down
Loading

0 comments on commit c545ae2

Please sign in to comment.