updating flake to make shell.nix work and updating server
This commit is contained in:
		
							parent
							
								
									d6d809d5d4
								
							
						
					
					
						commit
						78eb9da780
					
				
					 5 changed files with 70 additions and 36 deletions
				
			
		| 
						 | 
				
			
			@ -28,10 +28,5 @@ Camp Joy in Republican City, NE
 | 
			
		|||
<!-- http://umap.openstreetmap.fr/en/map/anonymous-edit/888075:134YBQNTmQ2pkJ76ur0PJ8KPuAc -->
 | 
			
		||||
 | 
			
		||||
{{< map mapName="campmap_888075" >}}
 | 
			
		||||
<!-- {{< leaflet-map mapLat="27.66995" mapLon="85.43249" >}} -->
 | 
			
		||||
<!-- {{< leaflet-map mapHeight="300px" mapWidth="100%" mapLat="27.66995" mapLon="85.43249" >}} -->
 | 
			
		||||
<!--     {{< leaflet-marker markerLat="27.66995" markerLon="85.43249" >}} -->
 | 
			
		||||
<!-- {{< /leaflet-map >}} -->
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{{< camp-form >}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										30
									
								
								flake.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										30
									
								
								flake.lock
									
										
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -1,12 +1,15 @@
 | 
			
		|||
{
 | 
			
		||||
  "nodes": {
 | 
			
		||||
    "flake-utils": {
 | 
			
		||||
      "inputs": {
 | 
			
		||||
        "systems": "systems"
 | 
			
		||||
      },
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1667395993,
 | 
			
		||||
        "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
 | 
			
		||||
        "lastModified": 1685518550,
 | 
			
		||||
        "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
 | 
			
		||||
        "owner": "numtide",
 | 
			
		||||
        "repo": "flake-utils",
 | 
			
		||||
        "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
 | 
			
		||||
        "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
| 
						 | 
				
			
			@ -17,11 +20,11 @@
 | 
			
		|||
    },
 | 
			
		||||
    "nixpkgs": {
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1671359686,
 | 
			
		||||
        "narHash": "sha256-3MpC6yZo+Xn9cPordGz2/ii6IJpP2n8LE8e/ebUXLrs=",
 | 
			
		||||
        "lastModified": 1685383865,
 | 
			
		||||
        "narHash": "sha256-3uQytfnotO6QJv3r04ajSXbEFMII0dUtw0uqYlZ4dbk=",
 | 
			
		||||
        "owner": "nixos",
 | 
			
		||||
        "repo": "nixpkgs",
 | 
			
		||||
        "rev": "04f574a1c0fde90b51bf68198e2297ca4e7cccf4",
 | 
			
		||||
        "rev": "5e871d8aa6f57cc8e0dc087d1c5013f6e212b4ce",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
| 
						 | 
				
			
			@ -36,6 +39,21 @@
 | 
			
		|||
        "flake-utils": "flake-utils",
 | 
			
		||||
        "nixpkgs": "nixpkgs"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "systems": {
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1681028828,
 | 
			
		||||
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
 | 
			
		||||
        "owner": "nix-systems",
 | 
			
		||||
        "repo": "default",
 | 
			
		||||
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "owner": "nix-systems",
 | 
			
		||||
        "repo": "default",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "root": "root",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,3 @@
 | 
			
		|||
{{- partial "partials/functions/warnings.html" .Site -}}
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html
 | 
			
		||||
  lang="{{ with .Site.Params.isoCode | default (.Site.LanguageCode | default "en") }}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								shell.nix
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								shell.nix
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,6 +1,17 @@
 | 
			
		|||
{ pkgs ? import <nixpkgs> { } }:
 | 
			
		||||
with pkgs;
 | 
			
		||||
mkShell rec {
 | 
			
		||||
let
 | 
			
		||||
  sbcl' = sbcl.withPackages (ps: with ps; [
 | 
			
		||||
    hunchentoot
 | 
			
		||||
    dexador
 | 
			
		||||
    clack
 | 
			
		||||
    jzon
 | 
			
		||||
    serapeum
 | 
			
		||||
    pkgs.openssl
 | 
			
		||||
    pkgs.openssl.out
 | 
			
		||||
    pkgs.openssl.dev
 | 
			
		||||
  ]);
 | 
			
		||||
in mkShell rec {
 | 
			
		||||
  name = "tfc-env";
 | 
			
		||||
 | 
			
		||||
  nativeBuildInputs = [
 | 
			
		||||
| 
						 | 
				
			
			@ -19,8 +30,7 @@ mkShell rec {
 | 
			
		|||
    clojure
 | 
			
		||||
    clojure-lsp
 | 
			
		||||
    clj-kondo
 | 
			
		||||
    sbcl
 | 
			
		||||
    openssl
 | 
			
		||||
    sbcl'
 | 
			
		||||
 | 
			
		||||
    clippy
 | 
			
		||||
    rustc
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,12 @@
 | 
			
		|||
(load "~/quicklisp/setup.lisp")
 | 
			
		||||
(ql:quickload '(hunchentoot clack dexador com.inuoe.jzon serapeum))
 | 
			
		||||
(require :asdf)
 | 
			
		||||
(require :hunchentoot)
 | 
			
		||||
(require :dexador)
 | 
			
		||||
(require :serapeum)
 | 
			
		||||
(require :clack)
 | 
			
		||||
(require :com.inuoe.jzon)
 | 
			
		||||
;; (load "~/quicklisp/setup.lisp")
 | 
			
		||||
;; (ql:quickload :cffi :silent t)
 | 
			
		||||
;; (ql:quickload '(hunchentoot clack dexador com.inuoe.jzon serapeum))
 | 
			
		||||
 | 
			
		||||
(uiop:define-package tfc-server
 | 
			
		||||
  (:use :cl :uiop :com.inuoe.jzon :clack))
 | 
			
		||||
| 
						 | 
				
			
			@ -10,16 +17,10 @@
 | 
			
		|||
(defvar *last-data*)
 | 
			
		||||
(defvar *last-list-data*)
 | 
			
		||||
(defvar *stream*)
 | 
			
		||||
(defvar *token* "boFFRM68vvXbO-DO7S9YDg86lHX027-hd07mn0dh")
 | 
			
		||||
 | 
			
		||||
(setf hunchentoot:*default-connection-timeout* 240)
 | 
			
		||||
(defvar *auth-token* "boFFRM68vvXbO-DO7S9YDg86lHX027-hd07mn0dh")
 | 
			
		||||
 | 
			
		||||
(defvar *server* (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 4242)))
 | 
			
		||||
 | 
			
		||||
(hunchentoot:define-easy-handler (say-yo :uri "/yo") (name)
 | 
			
		||||
  (setf (hunchentoot:content-type*) "text/plain")
 | 
			
		||||
  (format nil "Hey~@[ ~A~]!" name))
 | 
			
		||||
 | 
			
		||||
(hunchentoot:define-easy-handler (respond :uri "/health-form") ()
 | 
			
		||||
  (setf (hunchentoot:content-type*) "application/json")
 | 
			
		||||
  (let ((request-type (hunchentoot:request-method hunchentoot:*request*)))
 | 
			
		||||
| 
						 | 
				
			
			@ -28,8 +29,7 @@
 | 
			
		|||
           (uiop:println hunchentoot:*request*)
 | 
			
		||||
           (setq *last* hunchentoot:*request*)
 | 
			
		||||
           (setq *stream* (hunchentoot::content-stream hunchentoot:*request*))
 | 
			
		||||
           (let* ((stream (hunchentoot::content-stream hunchentoot:*request*))
 | 
			
		||||
                  (data (hunchentoot::get-post-data :request *last*))
 | 
			
		||||
           (let* ((data (hunchentoot::get-post-data :request *last*))
 | 
			
		||||
                  (content-type (hunchentoot:header-in "content-type" hunchentoot:*request*))
 | 
			
		||||
                  (boundary (let ((position (position #\= content-type)))
 | 
			
		||||
                              (when position
 | 
			
		||||
| 
						 | 
				
			
			@ -61,26 +61,42 @@
 | 
			
		|||
                              (image-file-name (if (string= name "image")
 | 
			
		||||
                                                   (subseq content-disposition
 | 
			
		||||
                                                           (1+ file-start) file-end) nil))
 | 
			
		||||
                              (form-list '()))
 | 
			
		||||
                              (form-list nil))
 | 
			
		||||
 | 
			
		||||
                         ;; This gets rid of beginning and ending NIL values
 | 
			
		||||
                         (if name (if (string/= name "image") (progn
 | 
			
		||||
                                                                (format t "~&~A: ~A" name content)
 | 
			
		||||
                                                                (setq form-list (list (cons name content))))) nil)
 | 
			
		||||
                                                                (setq form-list (acons name content form-list)))) nil)
 | 
			
		||||
                         (if (string= name "image") (setq content (butlast content)))
 | 
			
		||||
 | 
			
		||||
                         (if (string= "image" name)
 | 
			
		||||
                             (progn (format t "~&~A: ~A" name image-file-name)
 | 
			
		||||
                                    (setq form-list (list name image-file-name))
 | 
			
		||||
                                    (setq form-list (acons name image-file-name form-list))
 | 
			
		||||
                                    (save-string-file
 | 
			
		||||
                                     (apply #'concatenate 'string content) image-file-name)))
 | 
			
		||||
 | 
			
		||||
                         (setq *last-list-data* (append *last-list-data* form-list)))))))))
 | 
			
		||||
 | 
			
		||||
(defun post-health-form (data-list)
 | 
			
		||||
  "Takes the health form as an alist and posts it to nocodb"
 | 
			
		||||
  (let* ((student-name (concatenate 'string (cdr (assoc "firstname" data-list :test 'string=)) " " (cdr (assoc "lastname" data-list :test 'string=))))
 | 
			
		||||
         (parent-name (concatenate 'string (cdr (assoc "parentfirstname" data-list :test 'string=)) " " (cdr (assoc "parentlastname" data-list :test 'string=))))
 | 
			
		||||
         (agreement t)
 | 
			
		||||
         (medical-coverage (string= (cdr (assoc "medical-coverage" data-list :test 'string=)) "yes"))
 | 
			
		||||
         (data nil))
 | 
			
		||||
    (setf (assoc "firstname" data-list :test 'string=) '("Student Name" . student-name))
 | 
			
		||||
    (setf (assoc "lastname" data-list :test 'string=) nil)
 | 
			
		||||
    (setf (assoc "parentfirstname" data-list :test 'string=) '("Parent Name" . parent-name))
 | 
			
		||||
    (setf (assoc "parentlastname" data-list :test 'string=) nil)
 | 
			
		||||
    (format t "~&~A" data-list)
 | 
			
		||||
    (dex:post "https://tbl.tfcconnection.org/api/v1/db/data/v1/TFC/Health%20Forms/"
 | 
			
		||||
              :headers '(("xc-auth" . *auth-token*))
 | 
			
		||||
              :content data-list)))
 | 
			
		||||
 | 
			
		||||
(defun display-stream (stream)
 | 
			
		||||
  (loop for line = (read-line stream nil)
 | 
			
		||||
        while line do (format t "~A~%" line)))
 | 
			
		||||
(defun test-car-inner (item alist)
 | 
			
		||||
  "Looks inside the inner car and tests to see if it is equal to item"
 | 
			
		||||
  (format t "~&~A" (car alist))
 | 
			
		||||
  (eql (car alist) item))
 | 
			
		||||
 | 
			
		||||
(defun print-hash-entry (key value)
 | 
			
		||||
  (format t "~S: ~S~%" key (if (hash-table-p value) (maphash 'print-hash-entry value) value)))
 | 
			
		||||
| 
						 | 
				
			
			@ -91,10 +107,6 @@
 | 
			
		|||
    (maphash 'print-hash-entry form)
 | 
			
		||||
    (uiop:println "---"))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
(defun render-json (object)
 | 
			
		||||
  (uiop:println (format nil "Json: ~A" (com.inuoe.jzon:stringify object))))
 | 
			
		||||
 | 
			
		||||
(defun save-string-file (string file-path)
 | 
			
		||||
  "save a file that is represented as a string to disk that came from a multipart/form-data"
 | 
			
		||||
  (serapeum/bundle:write-string-into-file string file-path
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue