Skip to content

Commit 19eb475

Browse files
committed
Add support for specifying a custom model in AskQuestion
1 parent 7eecedc commit 19eb475

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

MyApp.ServiceInterface/QuestionServices.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using MyApp.ServiceInterface.App;
77
using ServiceStack;
88
using MyApp.ServiceModel;
9+
using ServiceStack.Configuration;
910
using ServiceStack.IO;
1011
using ServiceStack.Jobs;
1112
using ServiceStack.OrmLite;
@@ -114,9 +115,12 @@ public async Task<object> Any(AskQuestion request)
114115
var dbPost = createPost();
115116

116117
jobs.RunCommand<CreatePostCommand>(dbPost);
118+
117119
jobs.RunCommand<CreateAnswerTasksCommand>(new CreateAnswerTasks {
118120
Post = post,
119-
ModelUsers = appConfig.GetAnswerModelUsersFor(userName),
121+
ModelUsers = request.Model != null && Request.GetClaimsPrincipal().HasRole(RoleNames.Admin)
122+
? [request.Model]
123+
: appConfig.GetAnswerModelUsersFor(userName),
120124
});
121125

122126
jobs.RunCommand<DiskTasksCommand>(new DiskTasks

MyApp.ServiceModel/Posts.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ public class AskQuestion : IPost, IReturn<AskQuestionResponse>
224224
[ValidateNotEmpty, ValidateMinimumLength(2, Message = "At least 1 tag required"), ValidateMaximumLength(130)]
225225
[Input(Type = "tag", Help = "Up to 5 tags relevant to your question"), FieldCss(Field="col-span-12")]
226226
public required List<string> Tags { get; set; }
227+
228+
[Input(Type="hidden")]
229+
public string? Model { get; set; }
227230

228231
[Input(Type="hidden")]
229232
public string? RefId { get; set; }

MyApp.Tests/R2Tests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Collections.Concurrent;
22
using Amazon.S3;
3+
using Amazon.S3.Model;
34
using NUnit.Framework;
45
using ServiceStack;
6+
using ServiceStack.Aws;
57
using ServiceStack.IO;
68
using ServiceStack.Text;
79

@@ -46,4 +48,28 @@ public async Task Can_list_and_download_all_question_files()
4648
Console.WriteLine();
4749
});
4850
}
51+
52+
[Test]
53+
public async Task Can_write_to_R2()
54+
{
55+
var s3 = CreateS3Client();
56+
57+
var request = new PutObjectRequest
58+
{
59+
BucketName = "stackoverflow-shootout",
60+
Key = "test.txt",
61+
ContentBody = "test",
62+
DisablePayloadSigning = true,
63+
};
64+
65+
s3.PutObject(request);
66+
67+
// await s3.PutObjectAsync(request);
68+
69+
// await r2.WriteFileAsync("/test.txt", "test");
70+
71+
// var file = await r2.GetFileAsync("/test.txt");
72+
73+
// Console.WriteLine(await file.ReadAllTextAsync());
74+
}
4975
}

0 commit comments

Comments
 (0)