Skip to content

Commit f68bec9

Browse files
committed
Added Upload Scalar
1 parent db10cb7 commit f68bec9

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

code/complete/GraphQL/Speakers/SpeakerMutations.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using System.Threading;
23
using System.Threading.Tasks;
34
using ConferencePlanner.GraphQL.Common;
@@ -68,5 +69,22 @@ public async Task<ModifySpeakerPayload> ModifySpeakerAsync(
6869

6970
return new ModifySpeakerPayload(speaker);
7071
}
72+
73+
[UseApplicationDbContext]
74+
public async Task<UploadSpeakerPhotoPayload> UploadSpeakerPhotoAsync(
75+
UploadSpeakerPhotoInput input,
76+
[ScopedService] ApplicationDbContext context,
77+
CancellationToken cancellationToken)
78+
{
79+
Speaker? speaker = await context.Speakers.FindAsync(input.Id);
80+
81+
if (speaker is null)
82+
{
83+
return new UploadSpeakerPhotoPayload(
84+
new UserError("Speaker with id not found.", "SPEAKER_NOT_FOUND"));
85+
}
86+
87+
return new UploadSpeakerPhotoPayload(speaker);
88+
}
7189
}
7290
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using HotChocolate.Types;
2+
3+
namespace ConferencePlanner.GraphQL.Speakers
4+
{
5+
public record UploadSpeakerPhotoInput(int Id, IFile Photo);
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using ConferencePlanner.GraphQL.Common;
2+
using ConferencePlanner.GraphQL.Data;
3+
4+
namespace ConferencePlanner.GraphQL.Speakers
5+
{
6+
public class UploadSpeakerPhotoPayload : SpeakerPayloadBase
7+
{
8+
public UploadSpeakerPhotoPayload(Speaker speaker)
9+
: base(speaker)
10+
{
11+
}
12+
13+
public UploadSpeakerPhotoPayload(UserError error)
14+
: base(new[] { error })
15+
{
16+
}
17+
}
18+
}

code/complete/GraphQL/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public void ConfigureServices(IServiceCollection services)
7878
.AddTypeExtension<TrackNode>()
7979
.AddDataLoader<TrackByIdDataLoader>()
8080

81+
.AddType<UploadType>()
82+
8183
// In this section we are adding extensions like relay helpers,
8284
// filtering and sorting.
8385
.AddFiltering()
32 KB
Binary file not shown.
197 KB
Binary file not shown.

0 commit comments

Comments
 (0)