Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #165

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
29 changes: 29 additions & 0 deletions Core/Resgrid.Config/DataConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,43 @@
{
public class DataConfig
{
/// <summary>
/// The underlying database engine
/// </summary>
public static DatabaseTypes DatabaseType = DatabaseTypes.SqlServer;

/// <summary>
/// The underlying database engine for the document database (does not support SqlServer)
/// </summary>
public static DatabaseTypes DocDatabaseType = DatabaseTypes.MongoDb;

public static string ConnectionString = "Server=rgdevserver;Database=Resgrid;User Id=resgrid_app;Password=resgrid123;MultipleActiveResultSets=True;TrustServerCertificate=True;";

/// <summary>
/// Connection string for the core relational Resgrid database
/// </summary>
public static string CoreConnectionString = "";

/// <summary>
/// Connection string for storing JSON document types (Postgres)
/// </summary>
public static string DocumentConnectionString = "";


public static string NoSqlConnectionString = "mongodb://resgrid:resgrid123@rgdevserver:27017";
public static string NoSqlDatabaseName = "resgrid";
public static string NoSqlApplicationName = "Resgrid";

public static string UsersIdentityRoleId = "38b461d7-e848-46ef-8c06-ece5b618d9d1";
public static string AdminsIdentityRoleId = "1f6a03a8-62f4-4179-80fc-2eb96266cf04";
public static string AffiliatesIdentityRoleId = "3aba8863-e46d-40cc-ab86-309f9c3e4f97";
public static string QueryPrefix = "";
}

public enum DatabaseTypes
{
SqlServer,
Postgres,
MongoDb
}
}
5 changes: 5 additions & 0 deletions Core/Resgrid.Config/OidcConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace Resgrid.Config
{
public static class OidcConfig
{
/// <summary>
/// The underlying database engine for the OIDC database (Does not support Mongo)
/// </summary>
public static DatabaseTypes DatabaseType = DatabaseTypes.SqlServer;

public static string Key = "";

public static string ConnectionString = "Server=rgdevserver;Database=ResgridOIDC;User Id=resgrid_odic;Password=resgrid123;MultipleActiveResultSets=True;TrustServerCertificate=True;";
Expand Down
5 changes: 5 additions & 0 deletions Core/Resgrid.Config/WorkerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
{
public static class WorkerConfig
{
/// <summary>
/// The underlying database engine for the worker database (Does not support Mongo)
/// </summary>
public static DatabaseTypes DatabaseType = DatabaseTypes.SqlServer;

public static string WorkerDbConnectionString = "Server=rgdevserver;Database=ResgridWorkers;User Id=resgrid_workers;Password=resgrid123;MultipleActiveResultSets=True;";
public static string PayloadKey = "XsBYpdbdHkhuGsU3tvTMawyV6d3M2F8EQ8wQ2jVLBREECQmwngACk2hm4Ykb7eW7Qsm6za8RdJBY5Z3xvN6erYry47nJ5XmL";
}
Expand Down
24 changes: 24 additions & 0 deletions Core/Resgrid.Model/MapLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,67 @@ namespace Resgrid.Model
public class MapLayer: NoSqlDocument
{
[BsonElement("departmentId")]
[JsonProperty(PropertyName = "departmentId")]
public int DepartmentId { get; set; }

[Required]
[MaxLength(250)]
[BsonElement("name")]
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }

[BsonElement("type")]
[JsonProperty(PropertyName = "type")]
public int Type { get; set; }

[Required]
[MaxLength(50)]
[BsonElement("color")]
[JsonProperty(PropertyName = "color")]
public string Color { get; set; }

[BsonElement("data")]
[JsonProperty(PropertyName = "data")]
public MapLayerData Data { get; set; }

[BsonElement("isSearchable")]
[JsonProperty(PropertyName = "isSearchable")]
public bool IsSearchable { get; set; }

[BsonElement("isOnByDefault")]
[JsonProperty(PropertyName = "isOnByDefault")]
public bool IsOnByDefault { get; set; }

[BsonElement("addedById")]
[JsonProperty(PropertyName = "addedById")]
public string AddedById { get; set; }

[BsonElement("addedOn")]
[JsonProperty(PropertyName = "addedOn")]
public DateTime AddedOn { get; set; }

[BsonElement("isDeleted")]
[JsonProperty(PropertyName = "isDeleted")]
public bool IsDeleted { get; set; }

[BsonElement("updatedById")]
[JsonProperty(PropertyName = "updatedById")]
public string UpdatedById { get; set; }

[BsonElement("updatedOn")]
[JsonProperty(PropertyName = "updatedOn")]
public DateTime UpdatedOn { get; set; }

[BsonIgnore()]
[JsonProperty(PropertyName = "id")]
public string PgId { get; set; }

public string GetId()
{
if (!String.IsNullOrWhiteSpace(PgId))
return PgId;

return Id.ToString();
}
}
}
11 changes: 11 additions & 0 deletions Core/Resgrid.Model/PersonnelLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,16 @@ public class PersonnelLocation : NoSqlDocument

[BsonElement("heading")]
public decimal? Heading { get; set; }

[BsonIgnore()]
public string PgId { get; set; }

public string GetId()
{
if (!String.IsNullOrWhiteSpace(PgId))
return PgId;

return Id.ToString();
}
}
}
14 changes: 14 additions & 0 deletions Core/Resgrid.Model/Repositories/IMapLayersRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Resgrid.Model.Repositories
{
public interface IMapLayersDocRepository
{
Task<List<MapLayer>> GetAllMapLayersByDepartmentIdAsync(int departmentId, MapLayerTypes type);
Task<MapLayer> GetByIdAsync(string id);
Task<MapLayer> GetByOldIdAsync(string id);
Task<MapLayer> InsertAsync(MapLayer mapLayer);
Task<MapLayer> UpdateAsync(MapLayer mapLayer);
}
}
6 changes: 4 additions & 2 deletions Core/Resgrid.Model/Repositories/IOidcRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Resgrid.Model.Repositories
using System.Threading.Tasks;

namespace Resgrid.Model.Repositories
{
/// <summary>
/// Interface IOidcRepository
Expand All @@ -9,6 +11,6 @@ public interface IOidcRepository
/// Updates the Oidc Database
/// </summary>
/// <returns>If the operation was successful</returns>
bool UpdateOidcDatabase();
Task<bool> UpdateOidcDatabaseAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Resgrid.Model.Repositories
{
public interface IPersonnelLocationsDocRepository
{
Task<List<PersonnelLocation>> GetAllLocationsByUnitIdAsync(string userId);
Task<PersonnelLocation> GetLatestLocationsByUnitIdAsync(string userId);
Task<List<PersonnelLocation>> GetLatestLocationsByDepartmentIdAsync(int departmentId);
Task<PersonnelLocation> GetByIdAsync(string id);
Task<PersonnelLocation> GetByOldIdAsync(string id);
Task<PersonnelLocation> InsertAsync(PersonnelLocation location);
}
}
15 changes: 15 additions & 0 deletions Core/Resgrid.Model/Repositories/IUnitLocationsDocRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Resgrid.Model.Repositories
{
public interface IUnitLocationsDocRepository
{
Task<List<UnitsLocation>> GetAllLocationsByUnitIdAsync(int unitId);
Task<UnitsLocation> GetLatestLocationsByUnitIdAsync(int unitId);
Task<List<UnitsLocation>> GetLatestLocationsByDepartmentIdAsync(int departmentId);
Task<UnitsLocation> GetByIdAsync(string id);
Task<UnitsLocation> GetByOldIdAsync(string id);
Task<UnitsLocation> InsertAsync(UnitsLocation location);
}
}
11 changes: 11 additions & 0 deletions Core/Resgrid.Model/UnitsLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,16 @@ public class UnitsLocation : NoSqlDocument

[BsonElement("heading")]
public decimal? Heading { get; set; }

[BsonIgnore()]
public string PgId { get; set; }

public string GetId()
{
if (!String.IsNullOrWhiteSpace(PgId))
return PgId;

return Id.ToString();
}
}
}
54 changes: 44 additions & 10 deletions Core/Resgrid.Services/MappingService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -13,12 +14,15 @@ public class MappingService : IMappingService
private readonly IPoiTypesRepository _poiTypesRepository;
private readonly IPoisRepository _poisRepository;
private readonly IMongoRepository<MapLayer> _mapLayersRepository;
private readonly IMapLayersDocRepository _mapLayersDocRepository;

public MappingService(IPoiTypesRepository poiTypesRepository, IPoisRepository poisRepository, IMongoRepository<MapLayer> mapLayersRepository)
public MappingService(IPoiTypesRepository poiTypesRepository, IPoisRepository poisRepository, IMongoRepository<MapLayer> mapLayersRepository,
IMapLayersDocRepository mapLayersDocRepository)
{
_poiTypesRepository = poiTypesRepository;
_poisRepository = poisRepository;
_mapLayersRepository = mapLayersRepository;
_mapLayersDocRepository = mapLayersDocRepository;
}

public async Task<PoiType> SavePOITypeAsync(PoiType type, CancellationToken cancellationToken = default(CancellationToken))
Expand Down Expand Up @@ -59,26 +63,56 @@ public async Task<PoiType> GetTypeByIdAsync(int poiTypeId)

public async Task<MapLayer> SaveMapLayerAsync(MapLayer mapLayer)
{
if (mapLayer.Id.Timestamp == 0)
await _mapLayersRepository.InsertOneAsync(mapLayer);
if (Config.DataConfig.DocDatabaseType == Config.DatabaseTypes.Postgres)
{
if (String.IsNullOrEmpty(mapLayer.PgId))
await _mapLayersDocRepository.InsertAsync(mapLayer);
else
await _mapLayersDocRepository.UpdateAsync(mapLayer);

return mapLayer;
}
else
await _mapLayersRepository.ReplaceOneAsync(mapLayer);
{
if (mapLayer.Id.Timestamp == 0)
await _mapLayersRepository.InsertOneAsync(mapLayer);
else
await _mapLayersRepository.ReplaceOneAsync(mapLayer);

return mapLayer;
return mapLayer;
}
}

public async Task<List<MapLayer>> GetMapLayersForTypeDepartmentAsync(int departmentId, MapLayerTypes type)
{
var layers = await _mapLayersRepository.FilterByAsync(filter => filter.DepartmentId == departmentId && filter.Type == (int)type && filter.IsDeleted == false);
if (Config.DataConfig.DocDatabaseType == Config.DatabaseTypes.Postgres)
{
var layers = await _mapLayersDocRepository.GetAllMapLayersByDepartmentIdAsync(departmentId, type);

return layers.ToList();
return layers;
}
else
{
var layers = await _mapLayersRepository.FilterByAsync(filter => filter.DepartmentId == departmentId && filter.Type == (int)type && filter.IsDeleted == false);

return layers.ToList();
}
}

public async Task<MapLayer> GetMapLayersByIdAsync(string id)
{
var layers = await _mapLayersRepository.FindByIdAsync(id);
if (Config.DataConfig.DocDatabaseType == Config.DatabaseTypes.Postgres)
{
var layers = await _mapLayersDocRepository.GetByIdAsync(id);

return layers;
}
else
{
var layers = await _mapLayersRepository.FindByIdAsync(id);

return layers;
return layers;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FluentMigrator;

namespace Resgrid.Providers.MigrationsPg.Migrations
{
[Migration(1)]
public class M0001_InitialMigrationPg : Migration
{
public override void Up()
{
Execute.EmbeddedScript("Resgrid.Providers.MigrationsPg.Sql.M0001_InitialMigration.sql");
}

public override void Down()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using FluentMigrator;

namespace Resgrid.Providers.MigrationsPg.Migrations
{
[Migration(2)]
public class M0002_AddingContacts : Migration
{
public override void Up()
{
Create.Table("Contacts")
.WithColumn("ContactId").AsInt32().NotNullable().PrimaryKey().Identity()
.WithColumn("DepartmentId").AsInt32().NotNullable()
.WithColumn("ContactTypeId").AsInt32()
.WithColumn("Name").AsCustom("citext").NotNullable()
.WithColumn("PhoneNumber").AsCustom("citext")
.WithColumn("FaxNumber").AsCustom("citext")
.WithColumn("Email").AsCustom("citext")
.WithColumn("Twitter").AsCustom("citext")
.WithColumn("Facebook").AsCustom("citext")
.WithColumn("Notes").AsCustom("citext")
.WithColumn("Address").AsCustom("citext")
.WithColumn("City").AsCustom("citext")
.WithColumn("State").AsCustom("citext")
.WithColumn("PostalCode").AsCustom("citext")
.WithColumn("Country").AsCustom("citext")
.WithColumn("Location").AsCustom("citext");


Create.ForeignKey("FK_Conacts_Departments")
.FromTable("Contacts").ForeignColumn("DepartmentId")
.ToTable("Departments").PrimaryColumn("DepartmentId");
}

public override void Down()
{
Delete.Table("Contacts");
}
}
}
Loading
Loading