Initial commit: standalone quiz-testing system
Full-stack F# (Domain/Server/Client via Fable+Elmish+Feliz), PostgreSQL persistence via Dapper, Docker Compose deployment. Student quiz-taking flow with time-limit enforcement and focus-loss tracking, Teacher question bank and quiz builder with results analytics, Admin user management.
This commit is contained in:
24
src/Server/Features/Teacher/CreateTopic.fs
Normal file
24
src/Server/Features/Teacher/CreateTopic.fs
Normal file
@@ -0,0 +1,24 @@
|
||||
module Server.Features.Teacher.CreateTopic
|
||||
|
||||
open Giraffe
|
||||
open Domain
|
||||
open Domain.Contracts
|
||||
open Server.Store
|
||||
|
||||
let private create (store: Store) (ownerId: UserId) (req: CreateTopicRequest) : Result<Topic, string> =
|
||||
if System.String.IsNullOrWhiteSpace req.Name then
|
||||
Error "Название темы не может быть пустым"
|
||||
else
|
||||
let topic: Topic = { Id = Id.newTopicId (); OwnerId = ownerId; Name = req.Name }
|
||||
store.AddTopic topic
|
||||
Ok topic
|
||||
|
||||
let handler (store: Store) : HttpHandler =
|
||||
bindJson<CreateTopicRequest> (fun req next ctx ->
|
||||
task {
|
||||
let result =
|
||||
Server.Auth.requireRole [ Teacher; Admin ] ctx.User
|
||||
|> Result.bind (fun uid -> create store uid req)
|
||||
|
||||
return! json result next ctx
|
||||
})
|
||||
Reference in New Issue
Block a user