Skip to content

Commit

Permalink
finish implementing CreateWorkerAnswer
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 25, 2024
1 parent 4bc9705 commit d281b2c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
19 changes: 18 additions & 1 deletion MyApp.ServiceInterface/BackgroundMqServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,24 @@ public async Task Any(DbWrites request)
StartedDate = DateTime.UtcNow,
Worker = startJob.Worker,
WorkerIp = startJob.WorkerIp,
});
}, x => x.PostId == startJob.Id);
}

if (request.CompleteJobIds?.Count > 0)
{
await Db.UpdateOnlyAsync(() => new PostJob {
Body = null,
CompletedDate = DateTime.UtcNow,
},
x => request.CompleteJobIds.Contains(x.PostId));
}

if (request.AnswerAddedToPost != null)
{
await Db.UpdateAddAsync(() => new Post
{
AnswerCount = 1,
}, x => x.Id == request.AnswerAddedToPost.Value);
}
}

Expand Down
17 changes: 17 additions & 0 deletions MyApp.ServiceInterface/QuestionServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ public async Task<object> Any(AskQuestion request)

public async Task Any(CreateWorkerAnswer request)
{
var json = request.Json;
if (string.IsNullOrEmpty(json))
{
var file = base.Request!.Files.FirstOrDefault();
if (file != null)
{
using var reader = new StreamReader(file.InputStream);
json = await reader.ReadToEndAsync();
}
}

json = json?.Trim();
if (string.IsNullOrEmpty(json))
throw new ArgumentException("Json is required", nameof(request.Json));
if (!json.StartsWith('{'))
throw new ArgumentException("Invalid Json", nameof(request.Json));

if (request.PostJobId != null)
{
MessageProducer.Publish(new DbWrites {
Expand Down

0 comments on commit d281b2c

Please sign in to comment.