WebApi + ClientApp, GraphQL, Reflection
This commit is contained in:
143
Events.GraphQL/Events.EF/Data/MSSQL/EventsContext.cs
Normal file
143
Events.GraphQL/Events.EF/Data/MSSQL/EventsContext.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Events.EF.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Events.EF.Data.MSSQL;
|
||||
|
||||
public partial class EventsContext : DbContext
|
||||
{
|
||||
public EventsContext(DbContextOptions<EventsContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<Country> Countries { get; set; }
|
||||
|
||||
public virtual DbSet<Event> Events { get; set; }
|
||||
|
||||
public virtual DbSet<Person> People { get; set; }
|
||||
|
||||
public virtual DbSet<Registration> Registrations { get; set; }
|
||||
|
||||
public virtual DbSet<Sport> Sports { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Country>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Code);
|
||||
|
||||
entity.ToTable("Country");
|
||||
|
||||
entity.HasIndex(e => e.Name, "UQ_Country_Name").IsUnique();
|
||||
|
||||
entity.Property(e => e.Code)
|
||||
.HasMaxLength(3)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.Alpha3)
|
||||
.HasMaxLength(3)
|
||||
.IsUnicode(false)
|
||||
.IsFixedLength();
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Event>(entity =>
|
||||
{
|
||||
entity.ToTable("Event");
|
||||
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(150)
|
||||
.IsUnicode(false);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Person>(entity =>
|
||||
{
|
||||
entity.ToTable("Person");
|
||||
|
||||
entity.HasIndex(e => new { e.DocumentNumber, e.CountryCode }, "UQ_Person_DocumentNumber_CountryCode").IsUnique();
|
||||
|
||||
entity.Property(e => e.AddressCountry)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.AddressLine)
|
||||
.HasMaxLength(200)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.City)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.ContactPhone)
|
||||
.HasMaxLength(50)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.CountryCode)
|
||||
.HasMaxLength(3)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.DocumentNumber)
|
||||
.HasMaxLength(50)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.Email)
|
||||
.HasMaxLength(255)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.FirstName)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.FirstNameTranscription)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.LastName)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.LastNameTranscription)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
entity.Property(e => e.PostalCode)
|
||||
.HasMaxLength(20)
|
||||
.IsUnicode(false);
|
||||
|
||||
entity.HasOne(d => d.CountryCodeNavigation).WithMany(p => p.People)
|
||||
.HasForeignKey(d => d.CountryCode)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("FK_Person_Country");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Registration>(entity =>
|
||||
{
|
||||
entity.ToTable("Registration");
|
||||
|
||||
entity.HasIndex(e => new { e.PersonId, e.SportId, e.EventId }, "UQ_Registration_PersonId_SportId_EventId").IsUnique();
|
||||
|
||||
entity.Property(e => e.RegisteredAt).HasDefaultValueSql("(sysutcdatetime())", "DF_Registration_RegisteredAt");
|
||||
|
||||
entity.HasOne(d => d.Event).WithMany(p => p.Registrations)
|
||||
.HasForeignKey(d => d.EventId)
|
||||
.HasConstraintName("FK_Registration_Event");
|
||||
|
||||
entity.HasOne(d => d.Person).WithMany(p => p.Registrations)
|
||||
.HasForeignKey(d => d.PersonId)
|
||||
.HasConstraintName("FK_Registration_Person");
|
||||
|
||||
entity.HasOne(d => d.Sport).WithMany(p => p.Registrations)
|
||||
.HasForeignKey(d => d.SportId)
|
||||
.HasConstraintName("FK_Registration_Sport");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Sport>(entity =>
|
||||
{
|
||||
entity.ToTable("Sport");
|
||||
|
||||
entity.HasIndex(e => e.Name, "UQ_Sport_Name").IsUnique();
|
||||
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(100)
|
||||
.IsUnicode(false);
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
165
Events.GraphQL/Events.EF/Data/Postgres/EventsContext.cs
Normal file
165
Events.GraphQL/Events.EF/Data/Postgres/EventsContext.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Events.EF.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Events.EF.Data.Postgres;
|
||||
|
||||
public partial class EventsContext : DbContext
|
||||
{
|
||||
public EventsContext(DbContextOptions<EventsContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<Country> Countries { get; set; }
|
||||
|
||||
public virtual DbSet<Event> Events { get; set; }
|
||||
|
||||
public virtual DbSet<Person> People { get; set; }
|
||||
|
||||
public virtual DbSet<Registration> Registrations { get; set; }
|
||||
|
||||
public virtual DbSet<Sport> Sports { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Country>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Code).HasName("country_pkey");
|
||||
|
||||
entity.ToTable("country");
|
||||
|
||||
entity.HasIndex(e => e.Name, "country_name_key").IsUnique();
|
||||
|
||||
entity.Property(e => e.Code)
|
||||
.HasMaxLength(3)
|
||||
.HasColumnName("code");
|
||||
entity.Property(e => e.Alpha3)
|
||||
.HasMaxLength(3)
|
||||
.IsFixedLength()
|
||||
.HasColumnName("alpha3");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnName("name");
|
||||
entity.Property(e => e.Translations)
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("translations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Event>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("event_pkey");
|
||||
|
||||
entity.ToTable("event");
|
||||
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
entity.Property(e => e.EventDate).HasColumnName("event_date");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(150)
|
||||
.HasColumnName("name");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Person>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("person_pkey");
|
||||
|
||||
entity.ToTable("person");
|
||||
|
||||
entity.HasIndex(e => new { e.DocumentNumber, e.CountryCode }, "person_document_number_country_code_key").IsUnique();
|
||||
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
entity.Property(e => e.AddressCountry)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnName("address_country");
|
||||
entity.Property(e => e.AddressLine)
|
||||
.HasMaxLength(200)
|
||||
.HasColumnName("address_line");
|
||||
entity.Property(e => e.BirthDate).HasColumnName("birth_date");
|
||||
entity.Property(e => e.City)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnName("city");
|
||||
entity.Property(e => e.ContactPhone)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnName("contact_phone");
|
||||
entity.Property(e => e.CountryCode)
|
||||
.HasMaxLength(3)
|
||||
.HasColumnName("country_code");
|
||||
entity.Property(e => e.DocumentNumber)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnName("document_number");
|
||||
entity.Property(e => e.Email)
|
||||
.HasMaxLength(255)
|
||||
.HasColumnName("email");
|
||||
entity.Property(e => e.FirstName)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnName("first_name");
|
||||
entity.Property(e => e.FirstNameTranscription)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnName("first_name_transcription");
|
||||
entity.Property(e => e.LastName)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnName("last_name");
|
||||
entity.Property(e => e.LastNameTranscription)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnName("last_name_transcription");
|
||||
entity.Property(e => e.PostalCode)
|
||||
.HasMaxLength(20)
|
||||
.HasColumnName("postal_code");
|
||||
|
||||
entity.HasOne(d => d.CountryCodeNavigation).WithMany(p => p.People)
|
||||
.HasForeignKey(d => d.CountryCode)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("person_country_code_fkey");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Registration>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("registration_pkey");
|
||||
|
||||
entity.ToTable("registration");
|
||||
|
||||
entity.HasIndex(e => new { e.PersonId, e.SportId, e.EventId }, "registration_person_id_sport_id_event_id_key").IsUnique();
|
||||
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
entity.Property(e => e.EventId).HasColumnName("event_id");
|
||||
entity.Property(e => e.PersonId).HasColumnName("person_id");
|
||||
entity.Property(e => e.RegisteredAt)
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP")
|
||||
.HasColumnName("registered_at");
|
||||
entity.Property(e => e.SportId).HasColumnName("sport_id");
|
||||
|
||||
entity.HasOne(d => d.Event).WithMany(p => p.Registrations)
|
||||
.HasForeignKey(d => d.EventId)
|
||||
.HasConstraintName("registration_event_id_fkey");
|
||||
|
||||
entity.HasOne(d => d.Person).WithMany(p => p.Registrations)
|
||||
.HasForeignKey(d => d.PersonId)
|
||||
.HasConstraintName("registration_person_id_fkey");
|
||||
|
||||
entity.HasOne(d => d.Sport).WithMany(p => p.Registrations)
|
||||
.HasForeignKey(d => d.SportId)
|
||||
.HasConstraintName("registration_sport_id_fkey");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Sport>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("sport_pkey");
|
||||
|
||||
entity.ToTable("sport");
|
||||
|
||||
entity.HasIndex(e => e.Name, "sport_name_key").IsUnique();
|
||||
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnName("name");
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
14
Events.GraphQL/Events.EF/Events.EF.csproj
Normal file
14
Events.GraphQL/Events.EF/Events.EF.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.5" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
19
Events.GraphQL/Events.EF/Models/Country.cs
Normal file
19
Events.GraphQL/Events.EF/Models/Country.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Events.EF.Models;
|
||||
|
||||
public partial class Country
|
||||
{
|
||||
public string Code { get; set; } = null!;
|
||||
|
||||
public string Alpha3 { get; set; } = null!;
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public string? Translations { get; set; }
|
||||
|
||||
public virtual ICollection<Person> People { get; set; } = new List<Person>();
|
||||
}
|
||||
17
Events.GraphQL/Events.EF/Models/Event.cs
Normal file
17
Events.GraphQL/Events.EF/Models/Event.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Events.EF.Models;
|
||||
|
||||
public partial class Event
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public DateOnly EventDate { get; set; }
|
||||
|
||||
public virtual ICollection<Registration> Registrations { get; set; } = new List<Registration>();
|
||||
}
|
||||
41
Events.GraphQL/Events.EF/Models/Person.cs
Normal file
41
Events.GraphQL/Events.EF/Models/Person.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Events.EF.Models;
|
||||
|
||||
public partial class Person
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string? FirstName { get; set; }
|
||||
|
||||
public string? LastName { get; set; }
|
||||
|
||||
public string FirstNameTranscription { get; set; } = null!;
|
||||
|
||||
public string LastNameTranscription { get; set; } = null!;
|
||||
|
||||
public string? AddressLine { get; set; }
|
||||
|
||||
public string? PostalCode { get; set; }
|
||||
|
||||
public string? City { get; set; }
|
||||
|
||||
public string? AddressCountry { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? ContactPhone { get; set; }
|
||||
|
||||
public DateOnly BirthDate { get; set; }
|
||||
|
||||
public string DocumentNumber { get; set; } = null!;
|
||||
|
||||
public string CountryCode { get; set; } = null!;
|
||||
|
||||
public virtual Country CountryCodeNavigation { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<Registration> Registrations { get; set; } = new List<Registration>();
|
||||
}
|
||||
25
Events.GraphQL/Events.EF/Models/Registration.cs
Normal file
25
Events.GraphQL/Events.EF/Models/Registration.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Events.EF.Models;
|
||||
|
||||
public partial class Registration
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int PersonId { get; set; }
|
||||
|
||||
public int SportId { get; set; }
|
||||
|
||||
public int EventId { get; set; }
|
||||
|
||||
public DateTime RegisteredAt { get; set; }
|
||||
|
||||
public virtual Event Event { get; set; } = null!;
|
||||
|
||||
public virtual Person Person { get; set; } = null!;
|
||||
|
||||
public virtual Sport Sport { get; set; } = null!;
|
||||
}
|
||||
15
Events.GraphQL/Events.EF/Models/Sport.cs
Normal file
15
Events.GraphQL/Events.EF/Models/Sport.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Events.EF.Models;
|
||||
|
||||
public partial class Sport
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<Registration> Registrations { get; set; } = new List<Registration>();
|
||||
}
|
||||
70
Events.GraphQL/Events.EF/efpt.mssql.config.json
Normal file
70
Events.GraphQL/Events.EF/efpt.mssql.config.json
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"CodeGenerationMode": 6,
|
||||
"ContextClassName": "EventsContext",
|
||||
"ContextNamespace": null,
|
||||
"FilterSchemas": false,
|
||||
"IncludeConnectionString": false,
|
||||
"IrregularWords": null,
|
||||
"MinimumProductVersion": "2.6.1465",
|
||||
"ModelNamespace": null,
|
||||
"OutputContextPath": "Data\/MSSQL",
|
||||
"OutputPath": "Models",
|
||||
"PluralRules": null,
|
||||
"PreserveCasingWithRegex": true,
|
||||
"ProjectRootNamespace": "Events.EF",
|
||||
"Schemas": null,
|
||||
"SelectedHandlebarsLanguage": 2,
|
||||
"SelectedToBeGenerated": 0,
|
||||
"SingularRules": null,
|
||||
"T4TemplatePath": null,
|
||||
"Tables": [
|
||||
{
|
||||
"Name": "[dbo].[Country]",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "[dbo].[Event]",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "[dbo].[Person]",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "[dbo].[Registration]",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "[dbo].[Sport]",
|
||||
"ObjectType": 0
|
||||
}
|
||||
],
|
||||
"UiHint": null,
|
||||
"UncountableWords": null,
|
||||
"UseAsyncStoredProcedureCalls": true,
|
||||
"UseBoolPropertiesWithoutDefaultSql": false,
|
||||
"UseDatabaseNames": false,
|
||||
"UseDatabaseNamesForRoutines": true,
|
||||
"UseDateOnlyTimeOnly": true,
|
||||
"UseDbContextSplitting": false,
|
||||
"UseDecimalDataAnnotationForSprocResult": true,
|
||||
"UseFluentApiOnly": true,
|
||||
"UseHandleBars": false,
|
||||
"UseHierarchyId": false,
|
||||
"UseInflector": true,
|
||||
"UseInternalAccessModifiersForSprocsAndFunctions": false,
|
||||
"UseLegacyPluralizer": false,
|
||||
"UseManyToManyEntity": false,
|
||||
"UseNoDefaultConstructor": true,
|
||||
"UseNoNavigations": false,
|
||||
"UseNoObjectFilter": false,
|
||||
"UseNodaTime": false,
|
||||
"UseNullableReferences": true,
|
||||
"UsePrefixNavigationNaming": false,
|
||||
"UseSchemaFolders": false,
|
||||
"UseSchemaNamespaces": false,
|
||||
"UseSpatial": false,
|
||||
"UseT4": false,
|
||||
"UseT4Split": false,
|
||||
"UseTypedTvpParameters": true
|
||||
}
|
||||
70
Events.GraphQL/Events.EF/efpt.postgres.config.json
Normal file
70
Events.GraphQL/Events.EF/efpt.postgres.config.json
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"CodeGenerationMode": 6,
|
||||
"ContextClassName": "EventsContext",
|
||||
"ContextNamespace": null,
|
||||
"FilterSchemas": false,
|
||||
"IncludeConnectionString": false,
|
||||
"IrregularWords": null,
|
||||
"MinimumProductVersion": "2.6.1465",
|
||||
"ModelNamespace": null,
|
||||
"OutputContextPath": "Data\/Postgres",
|
||||
"OutputPath": "Models",
|
||||
"PluralRules": null,
|
||||
"PreserveCasingWithRegex": true,
|
||||
"ProjectRootNamespace": "Events.EF",
|
||||
"Schemas": null,
|
||||
"SelectedHandlebarsLanguage": 2,
|
||||
"SelectedToBeGenerated": 0,
|
||||
"SingularRules": null,
|
||||
"T4TemplatePath": null,
|
||||
"Tables": [
|
||||
{
|
||||
"Name": "public.country",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "public.event",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "public.person",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "public.registration",
|
||||
"ObjectType": 0
|
||||
},
|
||||
{
|
||||
"Name": "public.sport",
|
||||
"ObjectType": 0
|
||||
}
|
||||
],
|
||||
"UiHint": null,
|
||||
"UncountableWords": null,
|
||||
"UseAsyncStoredProcedureCalls": true,
|
||||
"UseBoolPropertiesWithoutDefaultSql": false,
|
||||
"UseDatabaseNames": false,
|
||||
"UseDatabaseNamesForRoutines": true,
|
||||
"UseDateOnlyTimeOnly": true,
|
||||
"UseDbContextSplitting": false,
|
||||
"UseDecimalDataAnnotationForSprocResult": true,
|
||||
"UseFluentApiOnly": true,
|
||||
"UseHandleBars": false,
|
||||
"UseHierarchyId": false,
|
||||
"UseInflector": true,
|
||||
"UseInternalAccessModifiersForSprocsAndFunctions": false,
|
||||
"UseLegacyPluralizer": false,
|
||||
"UseManyToManyEntity": false,
|
||||
"UseNoDefaultConstructor": true,
|
||||
"UseNoNavigations": false,
|
||||
"UseNoObjectFilter": false,
|
||||
"UseNodaTime": false,
|
||||
"UseNullableReferences": true,
|
||||
"UsePrefixNavigationNaming": false,
|
||||
"UseSchemaFolders": false,
|
||||
"UseSchemaNamespaces": false,
|
||||
"UseSpatial": false,
|
||||
"UseT4": false,
|
||||
"UseT4Split": false,
|
||||
"UseTypedTvpParameters": true
|
||||
}
|
||||
4
Events.GraphQL/Events.GraphQL.slnx
Normal file
4
Events.GraphQL/Events.GraphQL.slnx
Normal file
@@ -0,0 +1,4 @@
|
||||
<Solution>
|
||||
<Project Path="Events.EF/Events.EF.csproj" />
|
||||
<Project Path="Events.GraphQLServer/Events.GraphQLServer.csproj" />
|
||||
</Solution>
|
||||
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>PI</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="8.3.3" />
|
||||
<PackageReference Include="GraphQL.Server.Ui.Voyager" Version="8.3.3" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore" Version="16.0.0" />
|
||||
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="16.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\\Events.EF\\Events.EF.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
53
Events.GraphQL/Events.GraphQLServer/Program.cs
Normal file
53
Events.GraphQL/Events.GraphQLServer/Program.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Events.EF.Data.Postgres;
|
||||
using GraphQL.Server.Ui.Voyager;
|
||||
using GraphQLServer.SetupGraphQL;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
#region Configure services
|
||||
|
||||
builder.Services.AddDbContext<EventsContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("EventsPostgres")));
|
||||
|
||||
builder.Services.AddGraphQLServer()
|
||||
.ModifyRequestOptions(opt => opt.IncludeExceptionDetails = builder.Environment.IsDevelopment())
|
||||
.ModifyPagingOptions(options =>
|
||||
{
|
||||
options.DefaultPageSize = 20;
|
||||
options.MaxPageSize = 1000;
|
||||
options.IncludeTotalCount = true;
|
||||
})
|
||||
.AddProjections()
|
||||
.AddFiltering()
|
||||
.AddSorting()
|
||||
.AddQueryType<Queries>()
|
||||
.AddMutationType<Mutations>();
|
||||
#endregion
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
#region Configure middleware pipeline.
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.UseGraphQLVoyager("/voyager", new VoyagerOptions() { GraphQLEndPoint = "graphql" });
|
||||
app.UseGraphQLGraphiQL(
|
||||
"/",
|
||||
new GraphQL.Server.Ui.GraphiQL.GraphiQLOptions
|
||||
{
|
||||
GraphQLEndPoint = "/graphql",
|
||||
SubscriptionsEndPoint = "/graphql",
|
||||
});
|
||||
#endregion
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:50440",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace GraphQLServer.SetupGraphQL;
|
||||
|
||||
public record EventInput(
|
||||
string Name,
|
||||
DateOnly EventDate);
|
||||
@@ -0,0 +1,50 @@
|
||||
using Events.EF.Data.MSSQL;
|
||||
using Events.EF.Models;
|
||||
|
||||
namespace GraphQLServer.SetupGraphQL;
|
||||
|
||||
public partial class Mutations
|
||||
{
|
||||
public async Task<Event> AddEvent([Service] EventsContext ctx, EventInput input)
|
||||
{
|
||||
var item = new Event
|
||||
{
|
||||
Name = input.Name,
|
||||
EventDate = input.EventDate
|
||||
};
|
||||
|
||||
ctx.Events.Add(item);
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public async Task<Event?> UpdateEvent([Service] EventsContext ctx, int id, EventInput input)
|
||||
{
|
||||
var item = await ctx.Events.FindAsync(id);
|
||||
if (item is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
item.Name = input.Name;
|
||||
item.EventDate = input.EventDate;
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteEvent([Service] EventsContext ctx, int id)
|
||||
{
|
||||
var item = await ctx.Events.FindAsync(id);
|
||||
if (item is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ctx.Events.Remove(item);
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace GraphQLServer.SetupGraphQL;
|
||||
|
||||
public partial class Mutations
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Events.EF.Models;
|
||||
|
||||
namespace GraphQLServer.SetupGraphQL;
|
||||
|
||||
public class PeoplePage
|
||||
{
|
||||
public required int TotalCount { get; init; }
|
||||
|
||||
public required int PageNumber { get; init; }
|
||||
|
||||
public required int PageSize { get; init; }
|
||||
|
||||
public required IReadOnlyList<Person> Items { get; init; }
|
||||
}
|
||||
74
Events.GraphQL/Events.GraphQLServer/SetupGraphQL/Queries.cs
Normal file
74
Events.GraphQL/Events.GraphQLServer/SetupGraphQL/Queries.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Events.EF.Data.MSSQL;
|
||||
using Events.EF.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GraphQLServer.SetupGraphQL;
|
||||
|
||||
public class Queries
|
||||
{
|
||||
[UsePaging]
|
||||
[UseProjection]
|
||||
[UseFiltering]
|
||||
[UseSorting]
|
||||
public IQueryable<Country> GetCountries([Service] EventsContext ctx) => ctx.Countries.AsNoTracking();
|
||||
|
||||
[UsePaging]
|
||||
[UseProjection]
|
||||
[UseFiltering]
|
||||
[UseSorting]
|
||||
public IQueryable<Sport> GetSports([Service] EventsContext ctx) => ctx.Sports.AsNoTracking();
|
||||
|
||||
[UsePaging]
|
||||
[UseProjection]
|
||||
[UseFiltering]
|
||||
[UseSorting]
|
||||
public IQueryable<Person> GetPeople([Service] EventsContext ctx) => ctx.People.AsNoTracking();
|
||||
|
||||
public async Task<PeoplePage> GetPeoplePage(
|
||||
[Service] EventsContext ctx,
|
||||
int pageNumber = 1,
|
||||
int pageSize = 10)
|
||||
{
|
||||
pageNumber = Math.Max(1, pageNumber);
|
||||
pageSize = Math.Clamp(pageSize, 1, 100);
|
||||
|
||||
var baseQuery = ctx.People
|
||||
.AsNoTracking()
|
||||
.OrderBy(p => p.Id);
|
||||
|
||||
var totalCount = await baseQuery.CountAsync();
|
||||
|
||||
var items = await baseQuery
|
||||
.Skip((pageNumber - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
|
||||
return new PeoplePage
|
||||
{
|
||||
TotalCount = totalCount,
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
Items = items
|
||||
};
|
||||
}
|
||||
|
||||
[UsePaging]
|
||||
[UseProjection]
|
||||
[UseFiltering]
|
||||
[UseSorting]
|
||||
public IQueryable<Event> GetEvents([Service] EventsContext ctx) => ctx.Events.AsNoTracking();
|
||||
|
||||
[UsePaging]
|
||||
[UseProjection]
|
||||
[UseFiltering]
|
||||
[UseSorting]
|
||||
public IQueryable<Event> GetEventsForDate([Service] EventsContext ctx, DateOnly date) =>
|
||||
ctx.Events.AsNoTracking()
|
||||
.Where(e => e.EventDate == date);
|
||||
|
||||
[UsePaging]
|
||||
[UseProjection]
|
||||
[UseFiltering]
|
||||
[UseSorting]
|
||||
public IQueryable<Registration> GetRegistrations([Service] EventsContext ctx) => ctx.Registrations.AsNoTracking();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Events.GraphQL/Events.GraphQLServer/appsettings.json
Normal file
12
Events.GraphQL/Events.GraphQLServer/appsettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"EventsMssql": "Data Source=.,1433;Initial Catalog=Events;User Id=sport;Password=go and look in the secrets file;TrustServerCertificate=True"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user