diff --git a/registrations/jonathan.txt b/registrations/jonathan.txt new file mode 100644 index 0000000..17a962e --- /dev/null +++ b/registrations/jonathan.txt @@ -0,0 +1 @@ +{"name":"Jonathan","email":"jonathanouwerx@me.com","org_website":"","plus_one":"","receive_communication":"on"} \ No newline at end of file diff --git a/ticket.v b/ticket.v index 0d49ba5..1af975e 100644 --- a/ticket.v +++ b/ticket.v @@ -17,8 +17,9 @@ pub fn new_app() &App { } pub fn main() { - mut app := new_app() - vweb.run(app, 8000) + // mut app := new_app() + // vweb.run(app, 8000) + get_emails_from_dir('registrations')? } @@ -27,12 +28,12 @@ pub fn (mut app App) index() vweb.Result { } pub struct Registration { - name string - email string - org_website string - plus_one string + name string + email string + org_website string + plus_one string receive_communication string - timestamp time.Time + timestamp i64 } pub fn (mut app App) exists() vweb.Result { @@ -70,7 +71,7 @@ pub fn (mut app App) register(name string, email string, org_website string, plu org_website: org_website, plus_one: plus_one, receive_communication: receive_communication, - timestamp: time.now() + timestamp: time.now().unix_time() } path := 'registrations/${email}.txt' if os.exists(path) { return app.exists()} @@ -96,4 +97,26 @@ pub fn (mut app App) registrations() vweb.Result { resp += content } return app.html(resp) -} \ No newline at end of file +} + + +pub fn get_emails_from_dir (path string) ?string { + + mut emails := []string + + mut files := os.ls(path)?// returns an array of strings + + for file in files { + mut content := os.read_file('registrations/$file') or {'error'} + registration := json.decode(Registration, content)? + emails << registration.email + } + + emails_string := emails.join(', ') + + println(emails_string) + + return emails_string + +} +