update readme
This commit is contained in:
parent
a60b11925c
commit
2468d3f0c3
25
README.md
25
README.md
@ -21,7 +21,7 @@ First install Rust. I suggest using the [rustup toolchain](https://rustup.rs/)
|
|||||||
#### Database
|
#### Database
|
||||||
A postgres database is required. At this time, the database must be setup and run manually.
|
A postgres database is required. At this time, the database must be setup and run manually.
|
||||||
|
|
||||||
It is convient to run postgres in docker with the postgres:latest docker image. This can be done in a few easy clicks on docker desktop, or as follows with the docker CLI (be sure to pick a password and update [.cargo/config.toml](.cargo/config.toml))
|
It is convient to run postgres in docker with the postgres:latest docker image. This can be done in a few easy clicks on docker desktop, or as follows with the docker CLI (be sure to pick a POSTGRES_PASSWORD and update [.cargo/config.toml](.cargo/config.toml))
|
||||||
```
|
```
|
||||||
docker pull postgres:latest
|
docker pull postgres:latest
|
||||||
docker run --name my-postgres-container -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=mypassword -e -p 5432:5432 -d postgres:latest
|
docker run --name my-postgres-container -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=mypassword -e -p 5432:5432 -d postgres:latest
|
||||||
@ -59,21 +59,30 @@ Some minor derivations were taken here from the exact routes specified in the te
|
|||||||
* PUT /question does not include the question ID in its path param, but rather just the body
|
* PUT /question does not include the question ID in its path param, but rather just the body
|
||||||
* DELETE /question/:id returns in its body the deleted content
|
* DELETE /question/:id returns in its body the deleted content
|
||||||
#### `src/question.rs`
|
#### `src/question.rs`
|
||||||
This is the definition of our `struct Question`. An interesting potential for confilct arose here, as our question struct is supposed to keep track of the question id in addition of the in-memory hashmap of our store (next section). This two-sources-of-truth situation would lead to various error cases that we would need to handle, and would cause concerns with scalability.
|
This is the definition of our `struct Question`, `NewQuestion` and `QuestionDTO`.
|
||||||
|
|
||||||
|
#### `src/pg_store.rs`
|
||||||
|
The store is responsible for the management of the questions, tags, question_tags and answers. It does this by
|
||||||
|
* Providing public functions to create, retrieve, update or delete questions, create/delete tags, update question_tag associations, and add answers
|
||||||
|
* Handling possible database interactions errors with some grace
|
||||||
|
|
||||||
To address this, I seperated the Question 'entity' from the Question 'DTO' (data transfer object) from an ORM philosophy. The result is that the Question entity does not contain a direct reference to the question ID, as it is assumed while we are in program space, the store's hashmap will manage this. `to_entity` and `to_dto` function implementions have been provided to make this easier to work with.
|
|
||||||
#### `src/store.rs`
|
|
||||||
The store is responsible for the management of the questions. It does this by
|
|
||||||
* Providing public functions to create, retrieve, update or delete questions
|
|
||||||
* Handling possible unpermitted operations by returning errors
|
|
||||||
* Handling possible file or I/O errors with some sense of grace before panicing
|
|
||||||
### `question_tag.rs`
|
### `question_tag.rs`
|
||||||
|
Definition of `QuestionTag` struct
|
||||||
### `tag.rs`
|
### `tag.rs`
|
||||||
|
Definition of `Tag` struct
|
||||||
|
|
||||||
### `answer.rs`
|
### `answer.rs`
|
||||||
|
Definition of `Answer` and `NewAnswer` structs
|
||||||
|
|
||||||
|
|
||||||
### Looking ahead
|
### Looking ahead
|
||||||
These are a few things still to be added
|
These are a few things still to be added
|
||||||
|
#### Code cleanup
|
||||||
|
There is some dept here related to code cleanup I want to address very soon
|
||||||
|
* Stop using major nested match statements in functions that return options or results. question mark operator should work better for these.
|
||||||
|
* Deal with some exceptions where I use rust string formatting on query inputs; In some places, this was difficult to avoid.
|
||||||
|
* Change URL params of ids from u8 to i32 to avoid casting later on.
|
||||||
|
|
||||||
#### Higher priority
|
#### Higher priority
|
||||||
* Add some simple API curl examples to this README
|
* Add some simple API curl examples to this README
|
||||||
* API documentation tooling (`utoipa`)
|
* API documentation tooling (`utoipa`)
|
||||||
|
Reference in New Issue
Block a user