Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up project #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Set up project #4

wants to merge 13 commits into from

Conversation

liza-pizza
Copy link

This solves #1

@danySam danySam self-assigned this Sep 19, 2022

To start and stop server for development use `(mount/start)` and `(mount/stop)` respectively. Mount will setup the state including config and db datastore

Carry out a health check at `\api\ping` . A pong will be returned if everything is healthy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Carry out a health check at `\api\ping` . A pong will be returned if everything is healthy
Carry out a health check at `/api/ping`. A pong will be returned if everything is healthy

@@ -0,0 +1,21 @@
(defproject practitioner "0.1.0-SNAPSHOT"
:description "FIXME: write description"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a small description

(defn -main
[]
(mount/start)
(migrations/migrate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need your migration to run every time you start your application?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I don't need to. Will use practitioner.migrations/migrate-with-command to make it optional when starting. Migrating each time I start the application might cost time.

(:require
[aero.core :as aero]
[clojure.java.io :as io]
[mount.core :refer [defstate]]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you used mount before? Was there a need to use mount in practitioner?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not used mount before. Used mount in practitioner to allow the state to be reloaded in the REPL and I don't have to restart the REPL.

(when (try
(jdbc/execute! ds/datasource ["select now()"])
(catch Exception e
(res/response (.getMessage e))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exceptions are usually very verbose, they may provide valuable information to someone debugging an error. However, they may leak information about the system. In this case, when there is an issue with the database, it will leak unnecessary information to the user. This is both a security risk and a bad interface for a user.

You could

  1. Log the error to be debugged later
  2. Respond with a more meaningful error message to the user
  3. Add HTTP status codes to your responses. Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

There is more to error handling, but you can start from here

Comment on lines +1 to +2
(ns practitioner.models.user)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this file, if there is nothing in it?

Comment on lines +1 to +3
# Introduction to practitioner

TODO: write [great documentation](http://jacobian.org/writing/what-to-write/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe delete this file if this is not necessary?

Comment on lines +13 to +17
(testing "Returns pong when healthy"
(is (= (health-check (mock/request :get "/api/ping"))
{:status 200
:headers {}
:body "pong"}))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(testing "Returns pong when healthy"
(is (= (health-check (mock/request :get "/api/ping"))
{:status 200
:headers {}
:body "pong"}))))
(testing "Returns pong when healthy"
(is (= (health-check (mock/request :get "/api/ping"))
{:status 200
:headers {}
:body "pong"})))
(testing "Returns error when healthy"
(is (= (health-check (mock/request :get "/api/ping"))
{:status 500
:headers {}
:body "Server down"}))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants