-
Notifications
You must be signed in to change notification settings - Fork 1
/
storage-funcs.scm
182 lines (157 loc) · 6.97 KB
/
storage-funcs.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
;;; utilities
(use srfi-19 http-session spiffy-cookies http-session spiffy-cookies mda-client)
(include "macs.scm")
(define (todays-date)
(date->string (current-date) "~Y/~m/~d"))
(define (store? test)
(if (> (length test) 0) #t #f))
;;; macros
(define-syntax with-default
(syntax-rules ()
((with-default expr default)
(let ((e expr))
(if (eq? e 'not-found)
default
e)))))
;(define-syntax define-db-func
; (syntax-rules ()
; ((define-db-func opts (procs ...))
; (define (prop opts . prop)
; (if (store? prop)
; (db-store (car prop) "nepco" procs ...)
; (db:read "nepco" procs ...))))))
(define-syntax db-user
(syntax-rules ()
((db-user prop file default)
(define (prop user . prop)
(if (store? prop)
(db:store (car prop) "users" user file)
(with-default (db:read "users" user file) default))))))
(define-syntax db-club
(syntax-rules ()
((db-club prop file default)
(define (prop club . prop)
(if (store? prop)
(db:store (car prop) "clubs" club file)
(with-default (db:read "clubs" club file) default))))))
(define-syntax db-club-auth
(syntax-rules ()
((db-club-auth prop file default)
(define (prop club url . email)
(if (store? email)
(db:store (car email) "clubs" club "auth-urls" url file)
(with-default (db:read "clubs" club "auth-urls" url file) default))))))
(define-syntax db-club-clubber
(syntax-rules ()
((db-club-clubber prop file default)
(define (prop club name . prop)
(if (store? prop)
(db:store (car prop) "clubs" club "clubbers" name file)
(with-default (db:read "clubs" club "clubbers" name file) default))))))
(define-syntax db-club-clubber-date
(syntax-rules ()
((db-club-clubber-date prop file default . no-update-points)
(define (prop club mem date . prop-v)
(if (store? prop-v)
(begin (update-points (lambda (c n d) (prop c n d)) (car prop-v) club mem date)
(if (string=? "present" file)
(update-meeting-date club date (if (present club mem date) -1 1))
#f)
(let ((d-l (string-split date (db:sep))))
(db:update-list (first d-l) "clubs" club "clubbers" mem "attendance")
(db:update-list (second d-l) "clubs" club "clubbers" mem "attendance" (first d-l))
(db:update-list (third d-l) "clubs" club "clubbers" mem "attendance" (first d-l) (second d-l))
(db:update-list file "clubs" club "clubbers" mem "attendance" date)
(db:store (car prop-v) "clubs" club "clubbers" mem "attendance" date file)))
(with-default (db:read "clubs" club "clubbers" mem "attendance" date file) default))))))
(define-syntax db-club-clubber-section
(syntax-rules ()
((db-club-clubber-section prop default)
(define (prop club mem club-level book chapter section . prop)
(if (store? prop)
(db:store (car prop) "clubs" club "clubbers" mem "sections" "club-levels" club-level "books" book "chapters" chapter section)
(with-default (db:read "clubs" club "clubbers" mem "sections" "club-levels" club-level "books" book "chapters" chapter section)
default))))))
(define-syntax db-club-par
(syntax-rules ()
((db-club-par prop file default)
(define (prop club parent . prop)
(if (store? prop)
(db:store (car prop) "clubs" club "parents" parent file)
(with-default (db:read "clubs" club "parents" parent file) default))))))
;;; clubber funcs
(define (update-points func new-val club name date)
(cond ((and (func club name date) (not new-val))
(total-points club name (- (total-points club name) 1)))
((and (not (func club name date)) new-val)
(total-points club name (+ (total-points club name) 1)))))
(define (secondary-parent club name . parent)
(if (store? parent)
(db:store (car parent) "clubs" club "parents" (primary-parent club name) "spouse-name")
(with-default (db:read "clubs" club "parents" (primary-parent club name) "spouse-name") "")))
(define (update-meeting-date club date change)
(let* ((c-meetings (club-meetings club))
(meeting (assoc date c-meetings)))
(if meeting
(club-meetings club (alist-cons date (+ (cdr meeting) change) (alist-delete date c-meetings)))
(if (> change 0)
(club-meetings club (alist-cons date 1 c-meetings))
#f))))
;(define (day-points club name date . points)
; (if (store? points)
; (db:store (car points) "clubs" club "clubbers" name "attendance" date "day-points")
; (with-default (db:read "clubs" club "clubbers" name "attendance" date "day-points") 0)))
;;; database functions
; (user-name user . name)
(db-user user-name "name" 'not-found)
(db-user user-club "club" 'not-found)
(db-user user-email "email" 'not-found)
(db-user user-phone "phone" "")
(db-user user-birthday "birthday" "")
(db-user user-address "address" "")
(db-user user-pw "pw" 'not-found)
(db-user user-pw-type "user-pw-type" 'sha512)
(db-user stripe-customer-id "stripe-customer-id" 'not-found)
; (club-address club . address)
(db-club club-name "name" 'not-found)
(db-club club-users "club-users" '())
(db-club club-meetings "club-meetings" '())
; (auth-url club url . email)
(db-club-auth auth-url "email" #f)
; (grade club clubber-name . grade)
(db-club-clubber name "name" 'not-found)
(db-club-clubber grade "grade" "")
(db-club-clubber birthday "birthday" "")
(db-club-clubber club-level "club-level" "")
(db-club-clubber notes "notes" "")
(db-club-clubber allergies "allergies" "")
(db-club-clubber primary-parent "primary-parent" "")
(db-club-clubber total-points "total-points" 0)
(db-club-clubber book "book" "")
(db-club-clubber book-index "book-index" "0")
(db-club-clubber last-section "last-section" #f)
(db-club-clubber date-registered "date-registered" "09/01/10") ; mm/dd/yy
(db-club-clubber thank-you "thank-you" #f)
(db-club-clubber miss-you "miss-you" #f)
(db-club-clubber dues-receipt "dues-receipt" #f)
; (present club clubber-name date . present)
(db-club-clubber-date present "present" #f)
(db-club-clubber-date bible "bible" #f)
(db-club-clubber-date handbook "handbook" #f)
(db-club-clubber-date uniform "uniform" #f)
(db-club-clubber-date friend "friend" #f)
(db-club-clubber-date extra "extra" #f)
(db-club-clubber-date sunday-school "sunday-school" #f)
(db-club-clubber-date dues "dues" #f)
(db-club-clubber-date on-time "on-time" #f)
; (clubber-section club clubber book chapter section . date)
(db-club-clubber-section clubber-section "")
; (parent-spouse club spouse-name . spouse-name)
(db-club-par parent-name "name" "")
(db-club-par parent-spouse "spouse" "")
(db-club-par parent-email "email" "")
(db-club-par parent-phone-1 "phone-1" "")
(db-club-par parent-phone-2 "phone-2" "")
(db-club-par parent-address "address" "")
(db-club-par parent-release-to "release-to" "")
(db-club-par parent-children "children" '())