From c3557a7d5f54d7a9cb7fb2ece9487332c264236e Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sat, 6 Dec 2025 17:55:58 +0100 Subject: Update model contracts. Great use of my new modules to factor out common model contract logic! --- models/crop-rotation.rkt | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'models/crop-rotation.rkt') diff --git a/models/crop-rotation.rkt b/models/crop-rotation.rkt index 630e493..cb6832e 100644 --- a/models/crop-rotation.rkt +++ b/models/crop-rotation.rkt @@ -5,30 +5,28 @@ crop-rotation-id (rename-out [crop-rotation-rotation-date crop-rotation-date] [crop-rotation-requirement-proportions crop-rotation-requirements]) - (contract-out [create-crop-rotation! - (-> string? requirement-proportion-hash/c crop-rotation?)] - [get-crop-rotations (-> (listof crop-rotation?))] - [get-crop-rotation - (->* () (#:id crop-rotation-id? #:date string?) (or/c crop-rotation? #f))] - [get-latest-crop-rotation (-> (or/c crop-rotation? #f))] - [delete-crop-rotation! (-> crop-rotation-or-id/c void?)])) + (contract-out + [create-crop-rotation! (-> string? requirement-proportion-hash/c crop-rotation?)] + [get-crop-rotations (-> (listof crop-rotation?))] + [get-crop-rotation (->* () (#:id db-id? #:date string?) (or/c crop-rotation? #f))] + [get-latest-crop-rotation (-> (or/c crop-rotation? #f))] + [delete-crop-rotation! (-> crop-rotation-or-id/c void?)])) (require racket/contract db sql "../db/conn.rkt" - "nutrient.rkt" - "crop-requirement.rkt") + "crop-requirement.rkt" + "utils.rkt") (struct crop-rotation (id rotation-date requirement-proportions) #:transparent) -(define crop-rotation-id? exact-nonnegative-integer?) -(define crop-rotation-or-id/c (or/c crop-rotation? crop-rotation-id?)) +(define crop-rotation-or-id/c (or/c crop-rotation? db-id?)) (define requirement-proportion-hash/c (hash/c crop-requirement? (between/c 0 100) #:immutable #t)) (define (->cr-id cr-or-id) (match cr-or-id - [(? crop-rotation-id? id) id] + [(? db-id? id) id] [(crop-rotation id _ _) id] [#f (error '->nt-id "#f can not be converted to an id")])) -- cgit v1.2.3