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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(declaim (optimize (speed 0) (safety 3) (debug 3)))
(in-package :resume)
;; shared
(eval-when (:compile-toplevel :load-toplevel :execute)
(defun state-options (states)
(mapcar (lambda (state)
`(:label ,(format nil "~a ~a" (abbr state) (state state)) :value ,(id state)))
states))
(defun visastatus-options (visastatuses)
(mapcar (lambda (visastatus)
`(:label ,(status visastatus) :value ,(id visastatus)))
visastatuses))
(defun language-options ()
(mapcar (lambda (level)
`(:label ,level :value ,level))
'("A1" "A2" "B1" "B2" "C1" "C2")))
(defclass resume-service (auth-service)
((title :initarg :title
:initform nil
:accessor title))
(:documentation ""))
(defclass resume-component/view-service (resume-service)
((components :initarg components
:initform nil
:accessor components)
(location-p :initform nil))
(:documentation ""))
(defclass resume-component/modify-service (resume-component/view-service)
((form :initarg :form
:initform nil
:accessor form))
(:documentation ""))
;; resume
(defun resume-json ()
(with-auth (instance resume-service "resume-view")
(setf (title instance) "Resumes")))
(defclass resume/view-service (resume-service resume)
((resumes :initarg :resumes
:initform nil
:accessor resumes)
(location-p :initform nil))
(:documentation ""))
(defun resume-view-json ()
(with-auth (instance resume/view-service "resume-view")
(with-resume-database
(let ((resume-pkg (make-instance 'resume-pkg))
(user (get-user)))
(setf (resumes instance) (get-records resume-pkg (make-instance 'resume :user_id (id user)) "name asc"))))
(sanitize-rest-json instance)
(loop for resume in (resumes instance)
do (sanitize-json resume))))
(defclass resume/add-service (resume/view-service)
((form :initarg :form
:initform nil
:accessor form))
(:documentation ""))
(defun resume-add-json ()
(with-auth (instance resume/add-service "resume-modify")
(setf (title instance) "Resume - Add")
(setf (form instance) (make-form "resume-add-form"
nil
t
`((:name "name" :label "Name" :field-type "text" :required "required")
(:label "Add Resume" :field-type "button" :onclick "on_resume_add_submit_clicked()"))))))
(defun resume-add-submit-json (name)
(declare (special name))
(with-auth (instance resume/add-service "resume-modify")
(with-resume-database
(handler-case
(let* ((resume-pkg (make-instance 'resume-pkg))
(user (get-user))
(resume (make-instance 'resume :user_id (id user))))
(loop for param in (remove-if (lambda (x)
(intersection `(,x) '(id)))
(sb-introspect:function-lambda-list #'resume-add-submit-json))
do (setf (slot-value resume param) (symbol-value param)))
(insert-record resume-pkg resume)
(setf (session-value :message) (format nil "Resume \"~a\" created successfully." (name resume))))
(error (e)
(setf (session-value :errormsg) (format nil "Error creating resume \"~a\". ~a" name e)))))))
(defclass resume/modify-service (resume/add-service)
()
(:documentation ""))
(defun resume-modify-json (id)
(with-auth (instance resume/modify-service "resume-modify")
(setf (title instance) "Resume - Modify")
(with-resume-database
(let* ((resume-pkg (make-instance 'resume-pkg))
(user (get-user))
(resume (get-record resume-pkg (make-instance 'resume :id id :user_id (id user)))))
(if resume
(setf (form instance) (make-form "resume-modify-form"
nil
t
`((:name "id" :field-type "hidden" :value ,(id resume) :required "required")
(:name "name" :label "Name" :field-type "text" :value ,(name resume) :required "required")
(:label "Modify Resume" :field-type "button" :onclick "on_resume_modify_submit_clicked()"))))
(setf (session-value :errormsg) "Error: could not modify resume. Not found."))))))
(defun resume-modify-submit-json (id name)
(declare (special id name))
(with-auth (instance resume/modify-service "resume-modify")
(setf (title instance) "Resume - Modify")
(with-resume-database
(handler-case
(let* ((resume-pkg (make-instance 'resume-pkg))
(user (get-user))
(resume (get-record resume-pkg (make-instance 'resume :id id :user_id (id user)))))
(loop for param in (remove-if (lambda (x)
(intersection `(,x) '(id)))
(sb-introspect:function-lambda-list #'resume-modify-submit-json))
do (setf (slot-value resume param) (symbol-value param)))
(update-record resume-pkg resume)
(setf (session-value :message) (format nil "Resume \"~a\" modified successfully." (name resume))))
(error (e)
(setf (session-value :errormsg) (format nil "Error modifying resume \"~a\". ~a" name e)))))))
(defclass resume/delete-service (resume/add-service)
()
(:documentation ""))
(defun resume-delete-json (id)
(with-auth (instance resume/delete-service "resume-modify")
(with-resume-database
(let* ((resume-pkg (make-instance 'resume-pkg))
(user (get-user))
(resume (get-record resume-pkg (make-instance 'resume :id id :user_id (id user)))))
(if resume
(progn
(delete-resume resume-pkg resume)
(setf (session-value :message) (format nil "Resume \"~a\" deleted successfully." (name resume))))
(setf (session-value :errormsg) "Error: could not delete resume: not found.")))))))
;; macros
(defmacro define-resume-component ((component-s rest-args input-add-fields input-modify-fields order-by &optional view-p))
"`component-s' is a symbol that matches the component's record object
name, i.e SKILL, JOB, EDUCATION, LANGUAGE, CONTACTINFO. This will be
used all over the place. The record name equals the component name.
`rest-args' is the list of REST API arguments for the add and modify
forms. In the form like this example: ((id :parameter-type 'integer))
`input-add-fields' and `input-modify-fields' are lists of generic form
fields that get inserted into the add and modify forms.
`view-p' is `t' if the component has a view in the database because it
needs to JOIN with other data."
(let* ((component (symbol-name component-s))
(component-lcase (string-downcase component))
(components-s (intern (format nil "~aS" component)))
(table (format nil "resume.~a~a" component-lcase (if view-p "_v" "")))
(arg-names (loop for arg in rest-args collect (car arg)))
(func-root-s (intern (format nil "~a-JSON" component)))
(func-view-s (intern (format nil "~a-VIEW-JSON" component)))
(func-add-s (intern (format nil "~a-ADD-JSON" component)))
(func-add-submit-s (intern (format nil "~a-ADD-SUBMIT-JSON" component)))
(func-modify-s (intern (format nil "~a-MODIFY-JSON" component)))
(func-modify-submit-s (intern (format nil "~a-MODIFY-SUBMIT-JSON" component)))
(func-delete-s (intern (format nil "~a-DELETE-JSON" component)))
(form-add (format nil "~a-add-form" component-lcase))
(form-modify (format nil "~a-modify-form" component-lcase)))
`(progn
(defun ,func-root-s ()
(with-auth (instance resume-service "resume-view")
(setf (title instance) ,component)))
(defun ,func-view-s ()
(with-auth (instance resume-component/view-service "resume-view")
(with-resume-database
(let ((resume-pkg (make-instance 'resume-pkg))
(user (get-user)))
(setf (components instance) (get-records resume-pkg
(make-instance ',component-s
:user_id (id user)
:*table ,table)
,order-by))))
(sanitize-rest-json instance)
(loop for component in (components instance)
do (sanitize-json component))))
(defun ,func-add-s ()
(with-auth (instance resume-component/modify-service "resume-modify")
(with-resume-database
(let ((resume-pkg (make-instance 'resume-pkg)))
(setf (title instance) (format nil "~a - Add" ,component))
(setf (form instance) (make-form ,form-add
nil
t
,input-add-fields))))))
(defun ,func-add-submit-s (,@arg-names)
(declare (special ,@arg-names))
(with-auth (instance resume-component/modify-service "resume-modify")
(with-resume-database
(handler-case
(let* ((resume-pkg (make-instance 'resume-pkg))
(user (get-user))
(,component-s (make-instance ',component-s :user_id (id user))))
(loop for param in (remove-if (lambda (x)
(intersection `(,x) '(id)))
(sb-introspect:function-lambda-list #',func-add-submit-s))
do (setf (slot-value ,component-s param) (symbol-value param)))
(insert-record resume-pkg ,component-s)
(setf (session-value :message) (format nil "~a created successfully." ,component)))
(error (e)
(setf (session-value :errormsg) (format nil "Error creating ~a. ~a" ,component e)))))))
(defun ,func-modify-s (id)
(with-auth (instance resume-component/modify-service "resume-modify")
(setf (title instance) (format nil "~a - Modify" ,component))
(with-resume-database
(let* ((resume-pkg (make-instance 'resume-pkg))
(user (get-user))
(,component-s (get-record resume-pkg (make-instance ',component-s
:id id
:user_id (id user)
:*table ,table))))
(if ,component-s
(setf (form instance) (make-form ,form-modify
nil
t
,input-modify-fields))
(setf (session-value :errormsg) (format nil "Error: could not modify ~a. Not found." ,component)))))))
(defun ,func-modify-submit-s (,@(append '(id) arg-names))
(declare (special ,@(append '(id) arg-names)))
(with-auth (instance resume-component/modify-service "resume-modify")
(setf (title instance) (format nil "~a - Modify" ,component))
(with-resume-database
(handler-case
(let* ((resume-pkg (make-instance 'resume-pkg))
(user (get-user))
(,component-s (get-record resume-pkg (make-instance ',component-s
:id id
:user_id (id user)
:*table ,table))))
(if ,component-s
(let ((new-component (make-instance ',component-s)))
(loop for param in (sb-introspect:function-lambda-list #',func-modify-submit-s)
do (setf (slot-value new-component param) (symbol-value param)))
(setf (user_id new-component) (id user))
(update-record-no-nulls resume-pkg new-component)
(setf (session-value :message) (format nil "~a modified successfully." ,component)))
(error (format nil "~a error" ,component))))
(error (e)
(setf (session-value :errormsg) (format nil "Error modifying ~a. ~a" ,component e)))))))
(defun ,func-delete-s (id)
(with-auth (instance resume-component/modify-service "resume-modify")
(with-resume-database
(let* ((resume-pkg (make-instance 'resume-pkg))
(user (get-user))
(,component-s (get-record resume-pkg (make-instance ',component-s
:id id
:user_id (id user)
:*table ,table))))
(if ,component-s
(progn
(delete-record resume-pkg (make-instance ',component-s :id id))
(setf (session-value :message) (format nil "~a deleted successfully." ,component)))
(setf (session-value :errormsg) (format nil "Error: could not delete ~a: not found." ,component)))))))
(define-endpoint (,(format nil "/resume/~a" component-lcase) :method :get) () ,func-root-s)
(define-endpoint (,(format nil "/resume/~a/view" component-lcase) :method :get) () ,func-view-s)
(define-endpoint (,(format nil "/resume/~a/add" component-lcase) :method :post) () ,func-add-s)
(define-endpoint (,(format nil "/resume/~a/add/submit" component-lcase) :method :post) (&post ,@rest-args) ,func-add-submit-s ,@arg-names)
(define-endpoint (,(format nil "/resume/~a/modify" component-lcase) :method :post) (&post (id :parameter-type 'integer)) ,func-modify-s id)
(define-endpoint (,(format nil "/resume/~a/modify/submit" component-lcase) :method :post) (&post (id :parameter-type 'integer) ,@rest-args) ,func-modify-submit-s ,@(append '(id) arg-names))
(define-endpoint (,(format nil "/resume/~a/delete/:id" component-lcase) :method :delete) (&path (id 'integer)) ,func-delete-s id))))
(define-resume-component (contactinfo
((address :parameter-type 'string) (city :parameter-type 'string) (state_id :parameter-type 'integer) (phone :parameter-type 'string) (email :parameter-type 'string) (url :parameter-type 'string) (visastatus_id :parameter-type 'integer))
`((:name "address" :label "Address" :field-type "text" :required "required")
(:name "city" :label "City" :field-type "text" :required "required")
(:name "state_id" :label "State" :field-type "select" :options ,(state-options (get-records resume-pkg (make-instance 'states) "abbr asc")) :required "required")
(:name "phone" :label "Phone" :field-type "text" :required "required")
(:name "email" :label "Email" :field-type "text" :required "required")
(:name "url" :label "URL" :field-type "text")
(:name "visastatus_id" :label "VISA Status" :field-type "select" :options ,(visastatus-options (get-records resume-pkg (make-instance 'visastatus) "visastatus asc")) :required "required")
(:label "Add CONTACTINFO" :field-type "button" :onclick "on_contactinfo_add_submit_clicked()"))
`((:name "id" :field-type "hidden" :value ,(id contactinfo) :required "required")
(:name "address" :label "Address" :field-type "text" :value ,(address contactinfo) :required "required")
(:name "city" :label "City" :field-type "text" :value ,(city contactinfo) :required "required")
(:name "state_id" :label "State" :field-type "select" :value ,(state_id contactinfo) :options ,(state-options (get-records resume-pkg (make-instance 'states) "abbr asc")) :required "required")
(:name "phone" :label "Phone" :field-type "text" :value ,(phone contactinfo) :required "required")
(:name "email" :label "Email" :field-type "text" :value ,(email contactinfo) :required "required")
(:name "url" :label "URL" :field-type "text" :value ,(url contactinfo))
(:name "visastatus_id" :label "VISA Status" :field-type "select" :value (visastatus_id contactinfo) :options ,(visastatus-options (get-records resume-pkg (make-instance 'visastatus) "visastatus asc")) :required "required")
(:label "Modify CONTACTINFO" :field-type "button" :onclick ,(format nil "on_contactinfo_modify_submit_clicked(~a)" id)))
"state_abbr asc, city asc, address asc"
t))
(define-resume-component (education
((school :parameter-type 'string) (major :parameter-type 'string) (minor :parameter-type 'string) (degree :parameter-type 'string) (progress :parameter-type 'string) (start_date :parameter-type 'string) (end_date :parameter-type 'string))
`((:name "school" :label "School" :field-type "text" :required "required")
(:name "major" :label "Major" :field-type "text" :required "required")
(:name "minor" :label "Minor" :field-type "text")
(:name "degree" :label "Degree" :field-type "text" :required "required")
(:name "progress" :label "Progress" :field-type "text" :required "required")
(:name "start_date" :label "Start Date" :field-type "text" :required "required")
(:name "end_date" :label "End Date" :field-type "text" :required "required")
(:label "Add EDUCATION" :field-type "button" :onclick "on_education_add_submit_clicked()"))
`((:name "id" :field-type "hidden" :value ,(id education) :required "required")
(:name "school" :label "School" :field-type "text" :value ,(school education) :required "required")
(:name "major" :label "Major" :field-type "text" :value ,(major education) :required "required")
(:name "minor" :label "Minor" :field-type "text" :value ,(minor education))
(:name "degree" :label "Degree" :field-type "text" :value ,(degree education) :required "required")
(:name "progress" :label "Progress" :field-type "text" :value ,(progress education) :required "required")
(:name "start_date" :label "Start Date" :field-type "text" :value ,(start_date education) :required "required")
(:name "end_date" :label "End Date" :field-type "text" :value ,(end_date education) :required "required")
(:label "Modify EDUCATION" :field-type "button" :onclick ,(format nil "on_education_modify_submit_clicked(~a)" id)))
"end_date desc, start_date desc, school asc, degree asc, major asc, minor asc"))
(define-resume-component (language
((name :parameter-type 'string) (understanding_listening :parameter-type 'string) (understanding_reading :parameter-type 'string) (speaking_interaction :parameter-type 'string) (speaking_production :parameter-type 'string) (writing :parameter-type 'string))
`((:name "name" :label "Name" :field-type "text" :required "required")
(:name "understanding_listening" :label "Understanding Listening" :field-type "select" :options ,(language-options) :required "required")
(:name "understanding_reading" :label "Understanding Reading" :field-type "select" :options ,(language-options) :required "required")
(:name "speaking_interaction" :label "Speaking Interaction" :field-type "select" :options ,(language-options) :required "required")
(:name "speaking_production" :label "Speaking Production" :field-type "select" :options ,(language-options) :required "required")
(:name "writing" :label "Writing" :field-type "select" :options ,(language-options) :required "required")
(:label "Add LANGUAGE" :field-type "button" :onclick "on_language_add_submit_clicked()"))
`((:name "id" :field-type "hidden" :value ,(id language) :required "required")
(:name "name" :label "Name" :field-type "text" :value ,(name language) :required "required")
(:name "understanding_listening" :label "Understanding Listening" :field-type "select" :options ,(language-options) :value ,(understanding_listening language) :required "required")
(:name "understanding_reading" :label "Understanding Reading" :field-type "select" :options ,(language-options) :value ,(understanding_reading language) :required "required")
(:name "speaking_interaction" :label "Speaking Interaction" :field-type "select" :options ,(language-options) :value ,(speaking_interaction language) :required "required")
(:name "speaking_production" :label "Speaking Production" :field-type "select" :options ,(language-options) :value ,(speaking_production language) :required "required")
(:name "writing" :label "Writing" :field-type "select" :options ,(language-options) :value ,(writing language) :required "required")
(:label "Modify LANGUAGE" :field-type "button" :onclick ,(format nil "on_language_modify_submit_clicked(~a)" id)))
"name asc"))
(define-resume-component (skill
((skill :parameter-type 'string))
`((:name "skill" :label "Skill" :field-type "text" :required "required")
(:label "Add Skill" :field-type "button" :onclick "on_skill_add_submit_clicked()"))
`((:name "id" :field-type "hidden" :value ,(id skill) :required "required")
(:name "skill" :label "Skill" :field-type "text" :value ,(skill skill) :required "required")
(:label "Modify SKILL" :field-type "button" :onclick ,(format nil "on_skill_modify_submit_clicked(~a)" id)))
"skill asc"))
(define-resume-component (job
((job :parameter-type 'string))
`((:name "company" :label "Company" :field-type "text" :required "required")
(:name "location" :label "Location" :field-type "text" :required "required")
(:name "start_date" :label "Start Date" :field-type "text" :required "required")
(:name "end_date" :label "End Date" :field-type "text" :required "required")
(:name "overview" :label "Overview" :field-type "textarea" :required "required")
(:label "Add Job" :field-type "button" :onclick "on_job_add_submit_clicked()"))
`((:name "id" :field-type "hidden" :value ,(id job) :required "required")
(:name "company" :label "Company" :field-type "text" :value ,(company job) :required "required")
(:name "location" :label "Location" :field-type "text" :value ,(location job) :required "required")
(:name "start_date" :label "Start Date" :field-type "text" :value ,(start_date job) :required "required")
(:name "end_date" :label "End Date" :field-type "text" :value ,(end_date job) :required "required")
(:name "overview" :label "Overview" :field-type "textarea" :value ,(overview job) :required "required")
(:label "Modify JOB" :field-type "button" :onclick ,(format nil "on_job_modify_submit_clicked(~a)" id)))
"end_date desc, start_date desc, company asc"))
|