Files
RuvdsTest/src/Server/Features/Teacher/DeleteQuiz.fs
danamir 942dfc9c1a 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.
2026-08-06 12:36:16 +03:00

28 lines
944 B
Forth

module Server.Features.Teacher.DeleteQuiz
open Giraffe
open Domain
open Domain.Contracts
open Server.Store
let private delete (store: Store) (ownerId: UserId) (req: DeleteQuizRequest) : Result<unit, string> =
match store.TryGetQuiz req.QuizId with
| None -> Error "Тест не найден"
| Some quiz when quiz.OwnerId <> ownerId -> Error "Доступ запрещён"
| Some _ ->
if store.AnyAttemptsForQuiz req.QuizId then
Error "Тест уже проходили, удаление невозможно"
else
store.RemoveQuiz req.QuizId
Ok()
let handler (store: Store) : HttpHandler =
bindJson<DeleteQuizRequest> (fun req next ctx ->
task {
let result =
Server.Auth.requireRole [ Teacher; Admin ] ctx.User
|> Result.bind (fun uid -> delete store uid req)
return! json result next ctx
})