Skip to content

Commit 32e3287

Browse files
committed
Added session 6
1 parent 303a2b5 commit 32e3287

File tree

84 files changed

+1084
-1635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1084
-1635
lines changed

code/session-6/.config/dotnet-tools.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"isRoot": true,
44
"tools": {
55
"dotnet-ef": {
6-
"version": "5.0.0",
6+
"version": "8.0.7",
77
"commands": [
88
"dotnet-ef"
9-
]
9+
],
10+
"rollForward": false
1011
}
1112
}
1213
}

code/session-6/.vscode/launch.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

code/session-6/.vscode/tasks.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

code/session-6/ConferencePlanner.sln

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
2-
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26124.0
5-
MinimumVisualStudioVersion = 15.0.26124.0
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQL", "GraphQL\GraphQL.csproj", "{48385280-56F1-4937-9655-E6A79184740B}"
7-
EndProject
8-
Global
9-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10-
Debug|Any CPU = Debug|Any CPU
11-
Debug|x64 = Debug|x64
12-
Debug|x86 = Debug|x86
13-
Release|Any CPU = Release|Any CPU
14-
Release|x64 = Release|x64
15-
Release|x86 = Release|x86
16-
EndGlobalSection
17-
GlobalSection(SolutionProperties) = preSolution
18-
HideSolutionNode = FALSE
19-
EndGlobalSection
20-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|Any CPU.Build.0 = Debug|Any CPU
23-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|x64.ActiveCfg = Debug|Any CPU
24-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|x64.Build.0 = Debug|Any CPU
25-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|x86.ActiveCfg = Debug|Any CPU
26-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|x86.Build.0 = Debug|Any CPU
27-
{48385280-56F1-4937-9655-E6A79184740B}.Release|Any CPU.ActiveCfg = Release|Any CPU
28-
{48385280-56F1-4937-9655-E6A79184740B}.Release|Any CPU.Build.0 = Release|Any CPU
29-
{48385280-56F1-4937-9655-E6A79184740B}.Release|x64.ActiveCfg = Release|Any CPU
30-
{48385280-56F1-4937-9655-E6A79184740B}.Release|x64.Build.0 = Release|Any CPU
31-
{48385280-56F1-4937-9655-E6A79184740B}.Release|x86.ActiveCfg = Release|Any CPU
32-
{48385280-56F1-4937-9655-E6A79184740B}.Release|x86.Build.0 = Release|Any CPU
33-
EndGlobalSection
34-
EndGlobal
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQL", "GraphQL\GraphQL.csproj", "{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(SolutionProperties) = preSolution
14+
HideSolutionNode = FALSE
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using ConferencePlanner.GraphQL.Data;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace ConferencePlanner.GraphQL.Attendees;
5+
6+
public static class AttendeeDataLoaders
7+
{
8+
[DataLoader]
9+
public static async Task<IReadOnlyDictionary<int, Attendee>> AttendeeByIdAsync(
10+
IReadOnlyList<int> ids,
11+
ApplicationDbContext dbContext,
12+
CancellationToken cancellationToken)
13+
{
14+
return await dbContext.Attendees
15+
.Where(a => ids.Contains(a.Id))
16+
.ToDictionaryAsync(a => a.Id, cancellationToken);
17+
}
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using ConferencePlanner.GraphQL.Data;
2+
using ConferencePlanner.GraphQL.Sessions;
3+
using Microsoft.EntityFrameworkCore;
4+
5+
namespace ConferencePlanner.GraphQL.Attendees;
6+
7+
[ObjectType<Attendee>]
8+
public static partial class AttendeeType
9+
{
10+
static partial void Configure(IObjectTypeDescriptor<Attendee> descriptor)
11+
{
12+
descriptor
13+
.ImplementsNode()
14+
.IdField(a => a.Id)
15+
.ResolveNode(
16+
async (ctx, id)
17+
=> await ctx.DataLoader<AttendeeByIdDataLoader>()
18+
.LoadAsync(id, ctx.RequestAborted));
19+
20+
descriptor.Ignore(a => a.SessionsAttendees);
21+
}
22+
23+
public static async Task<IEnumerable<Session>> GetSessionsAsync(
24+
[Parent] Attendee attendee,
25+
ApplicationDbContext dbContext,
26+
SessionByIdDataLoader sessionById,
27+
CancellationToken cancellationToken)
28+
{
29+
var sessionIds = await dbContext.Attendees
30+
.Where(a => a.Id == attendee.Id)
31+
.Include(a => a.SessionsAttendees)
32+
.SelectMany(a => a.SessionsAttendees.Select(sa => sa.SessionId))
33+
.ToArrayAsync(cancellationToken);
34+
35+
return await sessionById.LoadAsync(sessionIds, cancellationToken);
36+
}
37+
}

code/session-6/GraphQL/Common/Payload.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

code/session-6/GraphQL/Common/UserError.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
1-
using Microsoft.EntityFrameworkCore;
2-
3-
namespace ConferencePlanner.GraphQL.Data
4-
{
5-
public class ApplicationDbContext : DbContext
6-
{
7-
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
8-
: base(options)
9-
{
10-
}
11-
12-
protected override void OnModelCreating(ModelBuilder modelBuilder)
13-
{
14-
modelBuilder
15-
.Entity<Attendee>()
16-
.HasIndex(a => a.UserName)
17-
.IsUnique();
18-
19-
// Many-to-many: Session <-> Attendee
20-
modelBuilder
21-
.Entity<SessionAttendee>()
22-
.HasKey(ca => new { ca.SessionId, ca.AttendeeId });
23-
24-
// Many-to-many: Speaker <-> Session
25-
modelBuilder
26-
.Entity<SessionSpeaker>()
27-
.HasKey(ss => new { ss.SessionId, ss.SpeakerId });
28-
}
29-
30-
public DbSet<Session> Sessions { get; set; } = default!;
31-
32-
public DbSet<Track> Tracks { get; set; } = default!;
33-
34-
public DbSet<Speaker> Speakers { get; set; } = default!;
35-
36-
public DbSet<Attendee> Attendees { get; set; } = default!;
37-
}
38-
}
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace ConferencePlanner.GraphQL.Data;
4+
5+
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
6+
: DbContext(options)
7+
{
8+
public DbSet<Attendee> Attendees { get; set; }
9+
10+
public DbSet<Session> Sessions { get; set; }
11+
12+
public DbSet<Speaker> Speakers { get; set; }
13+
14+
public DbSet<Track> Tracks { get; set; } = default!;
15+
16+
protected override void OnModelCreating(ModelBuilder modelBuilder)
17+
{
18+
modelBuilder
19+
.Entity<Attendee>()
20+
.HasIndex(a => a.Username)
21+
.IsUnique();
22+
23+
// Many-to-many: Session <-> Attendee
24+
modelBuilder
25+
.Entity<SessionAttendee>()
26+
.HasKey(sa => new { sa.SessionId, sa.AttendeeId });
27+
28+
// Many-to-many: Speaker <-> Session
29+
modelBuilder
30+
.Entity<SessionSpeaker>()
31+
.HasKey(ss => new { ss.SessionId, ss.SpeakerId });
32+
}
33+
}
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
using System.Collections.Generic;
21
using System.ComponentModel.DataAnnotations;
32

4-
namespace ConferencePlanner.GraphQL.Data
3+
namespace ConferencePlanner.GraphQL.Data;
4+
5+
public sealed class Attendee
56
{
6-
public class Attendee
7-
{
8-
public int Id { get; set; }
7+
public int Id { get; set; }
98

10-
[Required]
11-
[StringLength(200)]
12-
public string? FirstName { get; set; }
9+
[StringLength(200)]
10+
public required string FirstName { get; set; }
1311

14-
[Required]
15-
[StringLength(200)]
16-
public string? LastName { get; set; }
12+
[StringLength(200)]
13+
public required string LastName { get; set; }
1714

18-
[Required]
19-
[StringLength(200)]
20-
public string? UserName { get; set; }
15+
[StringLength(200)]
16+
public required string Username { get; set; }
2117

22-
[StringLength(256)]
23-
public string? EmailAddress { get; set; }
18+
[StringLength(256)]
19+
public string? EmailAddress { get; set; }
2420

25-
public ICollection<SessionAttendee> SessionsAttendees { get; set; } =
26-
new List<SessionAttendee>();
27-
}
28-
}
21+
public ICollection<SessionAttendee> SessionsAttendees { get; set; } =
22+
new List<SessionAttendee>();
23+
}

0 commit comments

Comments
 (0)