Skip to content

Commit 5d2be0e

Browse files
committed
Added session 7
1 parent 20328c2 commit 5d2be0e

File tree

96 files changed

+1407
-2300
lines changed

Some content is hidden

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

96 files changed

+1407
-2300
lines changed

code/session-7/.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-7/.vscode/launch.json

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

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

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

code/session-7/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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace ConferencePlanner.GraphQL.Attendees;
2+
3+
public sealed class AttendeeNotFoundException() : Exception("Attendee not found.");
Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,56 @@
1-
using System.Threading;
2-
using System.Threading.Tasks;
3-
using Microsoft.EntityFrameworkCore;
4-
using ConferencePlanner.GraphQL.Common;
51
using ConferencePlanner.GraphQL.Data;
6-
using HotChocolate;
7-
using HotChocolate.Types;
82
using HotChocolate.Subscriptions;
3+
using Microsoft.EntityFrameworkCore;
4+
5+
namespace ConferencePlanner.GraphQL.Attendees;
96

10-
namespace ConferencePlanner.GraphQL.Attendees
7+
[MutationType]
8+
public static class AttendeeMutations
119
{
12-
[ExtendObjectType(Name = "Mutation")]
13-
public class AttendeeMutations
10+
public static async Task<Attendee> RegisterAttendeeAsync(
11+
RegisterAttendeeInput input,
12+
ApplicationDbContext dbContext,
13+
CancellationToken cancellationToken)
1414
{
15-
[UseApplicationDbContext]
16-
public async Task<RegisterAttendeePayload> RegisterAttendeeAsync(
17-
RegisterAttendeeInput input,
18-
[ScopedService] ApplicationDbContext context,
19-
CancellationToken cancellationToken)
15+
var attendee = new Attendee
2016
{
21-
var attendee = new Attendee
22-
{
23-
FirstName = input.FirstName,
24-
LastName = input.LastName,
25-
UserName = input.UserName,
26-
EmailAddress = input.EmailAddress
27-
};
17+
FirstName = input.FirstName,
18+
LastName = input.LastName,
19+
Username = input.Username,
20+
EmailAddress = input.EmailAddress
21+
};
2822

29-
context.Attendees.Add(attendee);
23+
dbContext.Attendees.Add(attendee);
3024

31-
await context.SaveChangesAsync(cancellationToken);
25+
await dbContext.SaveChangesAsync(cancellationToken);
3226

33-
return new RegisterAttendeePayload(attendee);
34-
}
27+
return attendee;
28+
}
3529

36-
[UseApplicationDbContext]
37-
public async Task<CheckInAttendeePayload> CheckInAttendeeAsync(
38-
CheckInAttendeeInput input,
39-
[ScopedService] ApplicationDbContext context,
40-
[Service] ITopicEventSender eventSender,
41-
CancellationToken cancellationToken)
42-
{
43-
Attendee attendee = await context.Attendees.FirstOrDefaultAsync(
44-
t => t.Id == input.AttendeeId, cancellationToken);
30+
public static async Task<Attendee> CheckInAttendeeAsync(
31+
CheckInAttendeeInput input,
32+
ApplicationDbContext dbContext,
33+
ITopicEventSender eventSender,
34+
CancellationToken cancellationToken)
35+
{
36+
var attendee = await dbContext.Attendees.FirstOrDefaultAsync(
37+
a => a.Id == input.AttendeeId,
38+
cancellationToken);
4539

46-
if (attendee is null)
47-
{
48-
return new CheckInAttendeePayload(
49-
new UserError("Attendee not found.", "ATTENDEE_NOT_FOUND"));
50-
}
40+
if (attendee is null)
41+
{
42+
throw new AttendeeNotFoundException();
43+
}
5144

52-
attendee.SessionsAttendees.Add(
53-
new SessionAttendee
54-
{
55-
SessionId = input.SessionId
56-
});
45+
attendee.SessionsAttendees.Add(new SessionAttendee { SessionId = input.SessionId });
5746

58-
await context.SaveChangesAsync(cancellationToken);
47+
await dbContext.SaveChangesAsync(cancellationToken);
5948

60-
await eventSender.SendAsync(
61-
"OnAttendeeCheckedIn_" + input.SessionId,
62-
input.AttendeeId,
63-
cancellationToken);
49+
await eventSender.SendAsync(
50+
$"OnAttendeeCheckedIn_{input.SessionId}",
51+
input.AttendeeId,
52+
cancellationToken);
6453

65-
return new CheckInAttendeePayload(attendee, input.SessionId);
66-
}
54+
return attendee;
6755
}
68-
}
56+
}

code/session-7/GraphQL/Attendees/AttendeePayloadBase.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
3-
using System.Threading;
4-
using System.Threading.Tasks;
51
using ConferencePlanner.GraphQL.Data;
6-
using ConferencePlanner.GraphQL.DataLoader;
7-
using HotChocolate;
8-
using HotChocolate.Types;
9-
using HotChocolate.Types.Relay;
102

11-
namespace ConferencePlanner.GraphQL.Attendees
3+
namespace ConferencePlanner.GraphQL.Attendees;
4+
5+
[QueryType]
6+
public static class AttendeeQueries
127
{
13-
[ExtendObjectType(Name = "Query")]
14-
public class AttendeeQueries
8+
[UsePaging]
9+
public static IQueryable<Attendee> GetAttendees(ApplicationDbContext dbContext)
1510
{
16-
[UseApplicationDbContext]
17-
[UsePaging]
18-
public IQueryable<Attendee> GetAttendees(
19-
[ScopedService] ApplicationDbContext context) =>
20-
context.Attendees;
11+
return dbContext.Attendees.OrderBy(a => a.Username);
12+
}
2113

22-
public Task<Attendee> GetAttendeeByIdAsync(
23-
[ID(nameof(Attendee))] int id,
24-
AttendeeByIdDataLoader attendeeById,
25-
CancellationToken cancellationToken) =>
26-
attendeeById.LoadAsync(id, cancellationToken);
14+
[NodeResolver]
15+
public static async Task<Attendee> GetAttendeeByIdAsync(
16+
int id,
17+
AttendeeByIdDataLoader attendeeById,
18+
CancellationToken cancellationToken)
19+
{
20+
return await attendeeById.LoadAsync(id, cancellationToken);
21+
}
2722

28-
public async Task<IEnumerable<Attendee>> GetAttendeesByIdAsync(
29-
[ID(nameof(Attendee))] int[] ids,
30-
AttendeeByIdDataLoader attendeeById,
31-
CancellationToken cancellationToken) =>
32-
await attendeeById.LoadAsync(ids, cancellationToken);
23+
public static async Task<IEnumerable<Attendee>> GetAttendeesByIdAsync(
24+
[ID<Attendee>] int[] ids,
25+
AttendeeByIdDataLoader attendeeById,
26+
CancellationToken cancellationToken)
27+
{
28+
return await attendeeById.LoadAsync(ids, cancellationToken);
3329
}
34-
}
30+
}

0 commit comments

Comments
 (0)