Skip to content

Commit

Permalink
Merge 82b0395 into 82121f3
Browse files Browse the repository at this point in the history
  • Loading branch information
dlidstrom committed Mar 15, 2022
2 parents 82121f3 + 82b0395 commit fa855fc
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 29 deletions.
26 changes: 18 additions & 8 deletions Snittlistan.Test/ApiControllers/Infrastructure/InMemoryContext.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.Collections;
#nullable enable

using System.Collections;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq.Expressions;
using System.Reflection;
using Snittlistan.Web.Infrastructure.Database;

#nullable enable

namespace Snittlistan.Test.ApiControllers.Infrastructure;

public sealed class InMemoryDbSet<T> : IDbSet<T>, IDbAsyncEnumerable<T> where T : class
{
private readonly IdGenerator _generator;
Expand Down Expand Up @@ -106,19 +107,28 @@ public InMemoryContext()
IdGenerator generator = new();
PublishedTasks = new InMemoryDbSet<PublishedTask>(generator);
Tenants = new InMemoryDbSet<Tenant>(generator);
Teams = new InMemoryDbSet<Bits_Team>(generator);
Hallar = new InMemoryDbSet<Bits_Hall>(generator);
Team = new InMemoryDbSet<Bits_Team>(generator);
Hall = new InMemoryDbSet<Bits_Hall>(generator);
RosterMails = new InMemoryDbSet<RosterMail>(generator);
ChangeLogs = new InMemoryDbSet<ChangeLog>(generator);
KeyValueProperties = new InMemoryDbSet<KeyValueProperty>(generator);
SentEmails = new InMemoryDbSet<SentEmail>(generator);
Match = new InMemoryDbSet<Bits_Match>(generator);
TeamRef = new InMemoryDbSet<Bits_TeamRef>(generator);
OilProfile = new InMemoryDbSet<Bits_OilProfile>(generator);
}

public IDbSet<PublishedTask> PublishedTasks { get; }

public IDbSet<Bits_Team> Teams { get; }
public IDbSet<Bits_Team> Team { get; }

public IDbSet<Bits_Hall> Hall { get; }

public IDbSet<Bits_Match> Match { get; }

public IDbSet<Bits_TeamRef> TeamRef { get; }

public IDbSet<Bits_Hall> Hallar { get; }
public IDbSet<Bits_OilProfile> OilProfile { get; }

public IDbSet<Tenant> Tenants { get; }

Expand All @@ -130,7 +140,7 @@ public InMemoryContext()

public IDbSet<SentEmail> SentEmails { get; }

public DbChangeTracker ChangeTracker => throw new NotImplementedException();
public DbChangeTracker ChangeTracker { get; } = null!;

public int SaveChanges()
{
Expand Down
4 changes: 2 additions & 2 deletions Snittlistan.Web/Areas/V1/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public JsonResult TeamsQuickSearch(string term)
}

var query =
from team in CompositionRoot.Databases.Bits.Teams
from team in CompositionRoot.Databases.Bits.Team
where team.TeamAlias.StartsWith(term)
orderby team.TeamAlias
select new
Expand All @@ -35,7 +35,7 @@ public JsonResult LocationsQuickSearch(string term)
}

var query =
from hall in CompositionRoot.Databases.Bits.Hallar
from hall in CompositionRoot.Databases.Bits.Hall
where hall.HallName.StartsWith(term)
orderby hall.HallName
select new
Expand Down
20 changes: 20 additions & 0 deletions Snittlistan.Web/Areas/V2/Controllers/Api/TaskController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ namespace Snittlistan.Web.Areas.V2.Controllers.Api;
[OnlyLocalAllowed]
public class TaskController : AbstractApiController
{
public async Task<IHttpActionResult> Get()
{
var query =
from m in CompositionRoot.Databases.Bits.Match
where m.MatchId == 6422
select new
{
m.ExternalMatchId,
HomeTeamName = m.HomeTeamRef.TeamName,
AwayTeamName = m.AwayTeamRef.TeamName,
m.MatchDateTime,
m.HallRef.HallRefId,
HallRef_HallName = m.HallRef.HallName,
HallName = m.HallRef.Hall!.HallName ?? "<null>"
};
var result = await query
.FirstOrDefaultAsync();
return Ok(result);
}

public async Task<IHttpActionResult> Post(TaskRequest request)
{
Logger.InfoFormat("Received task {taskJson}", request.TaskJson);
Expand Down
32 changes: 25 additions & 7 deletions Snittlistan.Web/Infrastructure/Database/BitsContext.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
using Npgsql.NameTranslation;
using System.Data.Entity;
#nullable enable

#nullable enable
using Npgsql.NameTranslation;

namespace Snittlistan.Web.Infrastructure.Database;

public class BitsContext : DbContext, IBitsContext
{
public IDbSet<Bits_Team> Teams { get; set; } = null!;
public BitsContext()
{
Configuration.AutoDetectChangesEnabled = false;
Configuration.LazyLoadingEnabled = false;
}

public IDbSet<Bits_Team> Team { get; set; } = null!;

public IDbSet<Bits_Hall> Hall { get; set; } = null!;

public IDbSet<Bits_Hall> Hallar { get; set; } = null!;
public IDbSet<Bits_Match> Match { get; set; } = null!;

public IDbSet<Bits_TeamRef> TeamRef { get; set; } = null!;

public IDbSet<Bits_OilProfile> OilProfile { get; set; } = null!;

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
System.Data.Entity.Database.SetInitializer(new NullDatabaseInitializer<BitsContext>());
NpgsqlSnakeCaseNameTranslator mapper = new();
_ = modelBuilder.HasDefaultSchema("bits");
modelBuilder.Properties().Configure(x => x.HasColumnName(mapper.TranslateMemberName(x.ClrPropertyInfo.Name)));
modelBuilder.Types().Configure(x => x.ToTable(mapper.TranslateMemberName(x.ClrType.Name.Replace("Bits", string.Empty))));
modelBuilder.Properties().Configure(x => x.HasColumnName(
mapper.TranslateMemberName(x.ClrPropertyInfo.Name)));
modelBuilder.Types().Configure(x => x.ToTable(
mapper.TranslateMemberName(x.ClrType.Name.Replace("Bits_", string.Empty))));

_ = modelBuilder.Entity<Bits_HallRef>()
.HasOptional(x => x.Hall)
.WithOptionalDependent(x => x!.HallRef)
.Map(x => x.MapKey("hall_id"));
}
}
13 changes: 11 additions & 2 deletions Snittlistan.Web/Infrastructure/Database/Bits_Hall.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#nullable enable

using System.ComponentModel.DataAnnotations;

namespace Snittlistan.Web.Infrastructure.Database;

public class Bits_Hall
{
public int ExternalHallId { get; set; }
[Key]
public int HallId { get; private set; }

public int ExternalHallId { get; private set; }

public string HallName { get; private set; } = string.Empty;

public int HallRefId { get; set; }

public string HallName { get; set; } = null!;
public Bits_HallRef HallRef { get; private set; } = null!;
}
21 changes: 21 additions & 0 deletions Snittlistan.Web/Infrastructure/Database/Bits_HallRef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#nullable enable

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Snittlistan.Web.Infrastructure.Database;

public class Bits_HallRef
{
[Key]
public int HallRefId { get; private set; }

public int ExternalHallId { get; private set; }

//[ForeignKey(nameof(Hall))]
//public int HallId { get; private set; }

public string HallName { get; private set; } = string.Empty;

public Bits_Hall? Hall { get; private set; }
}
59 changes: 59 additions & 0 deletions Snittlistan.Web/Infrastructure/Database/Bits_Match.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#nullable enable

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Snittlistan.Web.Infrastructure.Database;

/*
* SELECT
m.external_match_id,
tr_home.team_name AS home_team_name,
tr_home.team_alias AS home_team_alias,
tr_away.team_name AS away_team_name,
tr_away.team_alias AS away_team_alias,
op.oil_profile_name,
hr.hall_name
FROM
bits.match m
JOIN bits.team_ref tr_home ON m.match_home_team_ref_id = tr_home.team_ref_id
JOIN bits.team_ref tr_away ON m.match_away_team_ref_id = tr_away.team_ref_id
JOIN bits.oil_profile op ON m.match_oil_profile_id = op.oil_profile_id
JOIN bits.hall_ref hr ON m.match_hall_ref_id = hr.hall_ref_id
WHERE
m.external_match_id = 3235829;
*/
public class Bits_Match
{
[Key]
public int MatchId { get; private set; }

public int ExternalMatchId { get; private set; }

public DateTime MatchDateTime { get; private set; }

[Column("match_home_team_ref_id")]
[ForeignKey(nameof(HomeTeamRef))]
public int HomeTeamRefId { get; private set; }

public virtual Bits_TeamRef HomeTeamRef { get; private set; } = null!;

[Column("match_away_team_ref_id")]
[ForeignKey(nameof(AwayTeamRef))]
public int AwayTeamRefId { get; private set; }

public virtual Bits_TeamRef AwayTeamRef { get; private set; } = null!;

[Column("match_oil_profile_id")]
[ForeignKey(nameof(OilProfile))]
public int OilProfileId { get; private set; }

public virtual Bits_OilProfile OilProfile { get; private set; } = null!;

[Column("match_hall_ref_id")]
[ForeignKey(nameof(HallRef))]
public int HallRefId { get; private set; }

public Bits_HallRef HallRef { get; private set; } = null!;
}
16 changes: 16 additions & 0 deletions Snittlistan.Web/Infrastructure/Database/Bits_OilProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#nullable enable

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Snittlistan.Web.Infrastructure.Database;

public class Bits_OilProfile
{
[Key]
public int OilProfileId { get; set; }

[InverseProperty(nameof(Bits_Match.OilProfile))]
public virtual ICollection<Bits_Match> Matches { get; set; } =
new HashSet<Bits_Match>();
}
5 changes: 5 additions & 0 deletions Snittlistan.Web/Infrastructure/Database/Bits_Team.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#nullable enable

using System.ComponentModel.DataAnnotations;

namespace Snittlistan.Web.Infrastructure.Database;

public class Bits_Team
{
[Key]
public int TeamId { get; set; }

public int ExternalTeamId { get; set; }

public string TeamName { get; set; } = null!;
Expand Down
26 changes: 26 additions & 0 deletions Snittlistan.Web/Infrastructure/Database/Bits_TeamRef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#nullable enable

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Snittlistan.Web.Infrastructure.Database;

public class Bits_TeamRef
{
[Key]
public int TeamRefId { get; private set; }

public int ExternalTeamId { get; set; }

public string TeamName { get; private set; } = string.Empty;

public string TeamAlias { get; set; } = string.Empty;

[InverseProperty(nameof(Bits_Match.HomeTeamRef))]
public virtual ICollection<Bits_Match> HomeMatches { get; private set; } =
new HashSet<Bits_Match>();

[InverseProperty(nameof(Bits_Match.AwayTeamRef))]
public virtual ICollection<Bits_Match> AwayMatches { get; private set; } =
new HashSet<Bits_Match>();
}
16 changes: 10 additions & 6 deletions Snittlistan.Web/Infrastructure/Database/IBitsContext.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

using System.Data.Entity;

#nullable enable
#nullable enable

namespace Snittlistan.Web.Infrastructure.Database;

public interface IBitsContext
{
public IDbSet<Bits_Team> Teams { get; }
public IDbSet<Bits_Team> Team { get; }

public IDbSet<Bits_Hall> Hall { get; }

public IDbSet<Bits_Match> Match { get; }

public IDbSet<Bits_TeamRef> TeamRef { get; }

public IDbSet<Bits_Hall> Hallar { get; }
public IDbSet<Bits_OilProfile> OilProfile { get; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#nullable enable

using System.Data.Entity;
using System.Data.Entity.Infrastructure;

namespace Snittlistan.Web.Infrastructure.Database;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#nullable enable

using Npgsql.NameTranslation;
using System.Data.Entity;

namespace Snittlistan.Web.Infrastructure.Database;

Expand Down
4 changes: 4 additions & 0 deletions Snittlistan.Web/Snittlistan.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
<DependentUpon>Index.cshtml</DependentUpon>
</Compile>
<Compile Include="Commands\UpdateUserSettingsCommandHandler.cs" />
<Compile Include="Infrastructure\Database\Bits_HallRef.cs" />
<Compile Include="Infrastructure\Database\Bits_Match.cs" />
<Compile Include="Infrastructure\Database\Bits_OilProfile.cs" />
<Compile Include="Infrastructure\Database\Bits_TeamRef.cs" />
<Compile Include="Infrastructure\MsmqFactory.cs" />
<Compile Include="Models\UserSettings.cs" />
<Compile Include="RazorGeneratorMvcStart.cs" />
Expand Down
11 changes: 10 additions & 1 deletion Snittlistan.Web/Views/Emails/UpdateRoster.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ Content-Type: text/html; charset=utf-8
}
</p>
<p>
<h1>@Model.FormattedAuditLog.Title</h1>
<dl>
<dt>Hemmalag</dt>
<dd>@Model.HomeTeamName</dd>
<dt>Bortalag</dt>
<dd>@Model.AwayTeamName</dd>
<dt>Datum</dt>
<dd>@Model.MatchDate</dd>
<dt>Online scoring</dt>
<dd>@Model.OnlineScoringLink</dd>
</dl>
<table>
<tr>
<th>Bord</th>
Expand Down
2 changes: 1 addition & 1 deletion Snittlistan.Web/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<add name="Snittlistan-SiteWide" connectionString="Url=http://localhost:8080;Database=Snittlistan-SiteWide"/>
<add name="Snittlistan-hofvet" connectionString="Url=http://localhost:8080;Database=Snittlistan"/>
<add name="Snittlistan-vartansik" connectionString="Url=http://localhost:8080;Database=Snittlistan-vartansik"/>
<add name="BitsContext" connectionString="Server=localhost;Database=snittlistan;Username=postgres;Password=postgres" providerName="Npgsql" />
<add name="BitsContext" connectionString="Server=172.20.10.2;Database=prisma;Username=prisma;Password=prisma" providerName="Npgsql" />
<add name="SnittlistanContext" connectionString="Server=localhost;Database=snittlistan;Username=postgres;Password=postgres" providerName="Npgsql" />
</connectionStrings>
<appSettings>
Expand Down

0 comments on commit fa855fc

Please sign in to comment.