Commit graph

1641 commits

Author SHA1 Message Date
William Carroll
16f50e33bc Prefer deleting sessions by their UUID
Instead of deleting them by usernames.
2020-07-29 20:21:29 +01:00
William Carroll
c4a090e558 Support reading / writing cookies in API
Update my API type and handler types to reflect which handlers read and write
cookies.

TODO:
- Actually read from and write to Set-Cookie header
- Returning `pure NoContent` breaks my types, so I'm returning `undefined` now
2020-07-29 14:14:47 +01:00
William Carroll
9f70cb2c61 Add boilerplate for Google sign-in
For more information, read:
https://developers.google.com/identity/sign-in/web/sign-in?authuser=1

TODO: Use Elm ports or something similar to properly interop with the onSignIn
and signOn functions defined in index.html.
2020-07-29 10:13:19 +01:00
William Carroll
289cae2528 Add Elm boilerplate to project
Create a top-level client directory to store my Elm boilerplate.
2020-07-29 09:51:18 +01:00
William Carroll
cf6c8799ab Restrict users from multiple failed login attempts
I'm not resetting the failed LoginAttempt count, which is a low priority for
now, but necessary eventually.
2020-07-28 21:33:58 +01:00
William Carroll
f051b0be0b Check passwords in /login
TL;DR:
- Since POST /login is more rigorous, our accounts.csv needs to contain validly
  hashed passwords; you can use tests/create-accounts.sh to create dummy
  accounts

I still need to test the login flow and support:
- Tracking failed attempts (three maximum)
- Verifying accounts by sending emails to the users
2020-07-28 18:48:38 +01:00
William Carroll
90a521c78f Create Utils module for (|>) operator
For the past 3-4 Haskell projects on which I've worked, I've tried to habituate
the usage of the (&) operator, but I find that -- as petty as it may sound -- I
don't like the way that it looks, and I end up avoiding using it as a result.

This time around, I'm aliasing it to (|>) (i.e. Elixir style), and I'm hoping to
use it more.
2020-07-28 18:47:40 +01:00
William Carroll
191205acac Create populate.sqlite3 to simplify README
To make my life easier, I created a small sqlite3 script to populate our
database.
2020-07-28 18:47:40 +01:00
William Carroll
36a2fea686 Create Sessions table
TL;DR:
- Create Sessions SQL schema
- Create Sessions module
- Introduce UUID dependency
2020-07-28 18:40:17 +01:00
William Carroll
012296f156 Move SQL out of API and into separate modules
Create modules for each Table in our SQL database. This cleans up the handler
bodies at the expense of introducing more files and indirection.
2020-07-28 18:38:30 +01:00
William Carroll
b355664858 Support /login
Support basic authentication.

Note the TODOs that this commit introduces to track some of the remaining work.
2020-07-28 14:15:41 +01:00
William Carroll
b170be9375 Hash passwords when creating accounts
TL;DR:
- introduce the Cryptonite library
- Remove the redundant language extensions, imports, deps from Persistent
- Prefer NoContent return type for POST /accounts
- Define custom {To,From}JSON instances for Role
2020-07-28 12:51:17 +01:00
William Carroll
bb36dd1f9e Define bespoke impls for {To,From}JSON instances
Instead of sending and receiving JSON like "accountUsername", which leaks
implementation details and is a bit unwieldy, define custom instances that
prefer the shorter, more user-friendly "username" version.
2020-07-28 11:20:15 +01:00
William Carroll
502126243d Prefer name ClearTextPassword to Password
I expect my application to have two types for passwords:
- ClearTextPassword
- CipherTextPassword
2020-07-28 11:19:47 +01:00
William Carroll
2398f1bd40 Distinguish b/w Account and User
Additionally: supporting more CRUDL methods for the Accounts and Trips tables.
2020-07-28 10:57:15 +01:00
William Carroll
6d9e76313d Partially support DELETE /trips
Allow a user to delete a trip entry from the Trips table using the Primary
Key. While this type-checks and compiles, it doesn't appear to be working as
intended. Perhaps I should use an auto-incrementing integer as the Primary
Key. I'm not sure how I want to handle this, so I'm punting for now.
2020-07-28 10:14:33 +01:00
William Carroll
0637da36cc Support GET /trips
In the spirit of support CRUDL, I added a GET /trips, which lists all of the
trips in the Trips table.
2020-07-28 10:13:38 +01:00
William Carroll
2f73d1db6c Prefer NoContent response to Bool
When I first wrote this handler I wasn't aware of the NoContent response
option.
2020-07-28 10:12:25 +01:00
William Carroll
52ac4d79bd Allow API users to create Trip entries
Next up:
- list trips
- update existing trip entries
- delete existing trip entries
2020-07-28 09:12:55 +01:00
William Carroll
475f62fb16 Prefer SQLite.Simple to Persistent
In the spirit of walking crawling before I walk, I'm preferring the less
powerful SQLite.Simple library to the more powerful (but mystifying) Persistent
library.
2020-07-27 15:22:22 +01:00
William Carroll
c38814d7a1 Add CHECK constraints to schema
I believe data should be validated at each level of the stack:
- database
- server
- client

The database, in my opinion, is the most important layer at which to validate
because you can eliminate entire classes of bugs. However, the CHECK constraint
is limited, and the more complex the predicates are, the more expensive database
operations become.

At the server and client layers, the data validations can be more sophisticated
and return more useful error messages to help users better understand the shape
of the data that our application expects.
2020-07-27 14:23:34 +01:00
William Carroll
dfe23e3b63 Add instruction for operating the server
Add some basic commands for working with the server from within `ghci`, which is
helpful when developing.
2020-07-27 11:36:09 +01:00
William Carroll
974c63a679 Remove unnecessary language extensions
Attempting to abide by the Principle of Least Power. Also: the smaller the
headers in each module are, the happier I am.
2020-07-27 11:35:10 +01:00
William Carroll
df13b761ff Define table schema and CSVs to populate the database
TL;DR:
- Created src/init.sql, which defines the tables
- Created a data/ directory to house .csv data to populate our db
- Updated the README with usage instructions
2020-07-27 11:16:26 +01:00
William Carroll
8042c1e216 Watch "Hacksaw Ridge"
I don't plan on writing movie reviews in my Git commit message.
2020-07-26 23:00:33 +01:00
William Carroll
32e9f7f56d Add query for the productive directors
Show the movies from directors that appear more than once in the list.
2020-07-26 15:53:07 +01:00
William Carroll
6ca531116f Create a scratch buffer for common queries
Defining some commonly used criteria for selecting movies as SQL queries.
2020-07-26 15:52:59 +01:00
William Carroll
c36ae072d2 Mark Andhadhun as watched
What a confusing movie this was... I may need to watch it a second time to
better understand what happened, but I found watching it once already so
exhausting that I'm not sure I'll ever watch it again.
2020-07-26 12:23:36 +01:00
William Carroll
445763b5d9 Update schema for Movies table
Added the following fields (would be cool if `git` could show this):
- rating
- haveWatched
- director
- isCartoon
- requiresSubtitles
2020-07-26 12:22:17 +01:00
William Carroll
6981db2439 Create //playbooks/sqlite3.md
Write a playbook for using SQLite to capture some trivia that I often forget in
between my ~infrequent uses of SQLite.
2020-07-26 12:21:12 +01:00
William Carroll
a29ed22a83 Create //playbooks/shell.md
Taken from the overview:
> I'm making this as an offline reference for some of the commands that I use
> often enough to need to remember but not often enough to *actually* remember.
2020-07-26 11:26:05 +01:00
William Carroll
cf6d181f7c Add .sqliterc to //configs
Prefer these more human-readable defaults to SQLite.
2020-07-26 10:32:16 +01:00
William Carroll
d3a337199a Create SQLite database from unwatched movies in imdb-top-250.org
The astute observer may notice that the number of entries in db.sqlite3 is fewer
than the number of unwatched movies in imdb-top-250.org. I'm at a lake in
Germany with Mimi and Cullen, so we took the intersection of my unwatched
movies, Mimi's unwatched movies, and Cullen's unwatched movies.
2020-07-26 10:23:36 +01:00
William Carroll
722205b081 Remodel Account type
Remove unnecessary fields:
- name
- age

Add domain-specific fields:
- username
- password
- email
- role
2020-07-25 18:32:17 +01:00
William Carroll
d011616564 Change the name User to Account
Next I'll need to add / remove fields from the Account type.
2020-07-25 18:18:59 +01:00
William Carroll
718152ec14 Return a Session
Define the Session type and return it for the POST /user endpoint
2020-07-24 23:35:49 +01:00
William Carroll
1d47e94bbe Integrate Persistent with Servant
Query my SQLite database from within my Servant handlers. Nothing I've written
is domain-specific to the business logic yet -- I'm just making sure everything
integrates.
2020-07-24 22:48:08 +01:00
William Carroll
660b8d43e5 Support a basic API
Use Servant to create a REST API supporting the following routes:
- GET /number
- POST /other

The server interacts with a SQLite database.
2020-07-24 19:00:29 +01:00
William Carroll
ec90748b82 Create a shell.nix
Manage the project's dependencies using Nix.
2020-07-24 18:59:34 +01:00
William Carroll
26271ec178 Create todo.org
Create an org file with the instructions sent from TopTal as TODOs.
2020-07-24 18:58:04 +01:00
William Carroll
fd49b7f1be add README 2020-07-24 16:21:13 +01:00
William Carroll
d0c1645c16 Add two steps to finances playbook
I needed to add the first step since I dipped into my Emergency fund last month
to pay for someone to prepare my US tax return. I added the other step as a
reminder.
2020-07-24 10:07:30 +01:00
William Carroll
7f7ca4d6f5 Fix typo in finances playbook
amount -> amounts
2020-07-24 10:07:06 +01:00
William Carroll
90d22f643f Support dictionary.md
Back when I owned an iPhone -- before I switched (mistakenly and thus
temporarily) to Android -- I had a note for each year's newly learned words. As
I am condensing as many of my documents as possible into my briefcase, I decided
it is time for including a dictionary.

I can still record words on my phone, and then I can transfer them to this
document.
2020-07-21 12:58:13 +01:00
William Carroll
2a44b26630 Create //todo-lists
In the beginning there existed only a generic //org directory... This directory
was generic enough to include any .org file regardless of its purpose, but
specific enough to disallow membership of other worthy files of the Markdown
ilk.

Then came the //playbooks directory, which robbed //org of most of its
inhabitants...

In the interim various .md and .org TODO lists existed scattered across the
landscape of the monorepo... some existed in far-away, exotic lands like
"travel-histlist"... These fractious tribes shared much in common with their
distant relatives, but the superficial differences granted the simple-minded,
draconian filesystem license to prevent them from mingling.

Then one day the monorepo had a new visitor: //todo-lists.
//todo-lists restored order to the monorepo, uniting all of the fractious
documents under one roof.

.md and .org files held hands and sang Kumbaya around a blazing fire for the
first time in history. All was well, and all were happy.
2020-07-20 14:38:50 +01:00
William Carroll
c6106f7884 Create //playbooks
I'm particularly excited about this idea. As I was reading Graham's "Erase your
darlings" blog post, I had an idea: I should have playbooks at the root of my
monorepo.

I can have playbooks for the following:
- How to install NixOS
- How to build GCR images from Nix expressions
- A collection of miscellaneous shell commands (e.g. "how to kill a process by name")
- What series of steps should I follow when I receive a paycheck

I already keep README's at the root of each package, which I think is where many
of these instructions belong. Other tutorials that I write for myself that do
not belong to any package can go in //playbooks. I also will host my personal
habits in //playbooks since habits are a bit like playbooks for life. Let's see
how this idea ages as the caffeine wears off...
2020-07-20 14:38:50 +01:00
William Carroll
5add8ddc13 Move monzo_ynab into //tools
Optimizing is difficult: I like flat hierarchies because I don't like
directory-hopping, but I also would like a cleaner root for my mono-repo. Bombs
away!

Well it's that time again, folks: spring cleaning!

Here I am musing about a few things that bother me:
- Should I use kebab-case or snake_case?
- It feels ~confusing to have //tools and //utils. What a //projects? Isn't
  everything a project? *sigh*
2020-07-20 10:15:47 +01:00
William Carroll
4ed3254709 Add a README to haskell-file
Because every library/package deserves a README.
2020-07-20 10:10:04 +01:00
William Carroll
32480f1913 Move AOC into //scratch
Also rename it advent-of-code-2019 since I expect to participate this year as
well.

TODO: Should directories and files be name like-this or like_this?
2020-07-20 10:06:40 +01:00
William Carroll
a2475d2337 Partially complete IO chapter exercises
Inconveniently, I do not have the cipher code that I wrote from a previous
chapter, and I'm not eager to reimplement it.

TODO
- Implement encrypt
- Implement decrypt
- Read all characters from STDIN
2020-07-17 23:41:03 +01:00