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

feat: Versions API #38

Closed
wants to merge 104 commits into from
Closed

feat: Versions API #38

wants to merge 104 commits into from

Conversation

n-dusan
Copy link
Contributor

@n-dusan n-dusan commented May 15, 2024

Closes #24

Introduce the /_api/versions endpoint. Idea being we query the database and, depending on the url request, return either all document or collection changes. The changes are mapped onto a response::Versions json response.

We'll need to update the insert changes logic again, so I vote to defer this and this issue at that point.

This pr builds on top of the pr already in review. So once merged, I'll update/rebase this PR to contain fewer commits.

@tombh only these 6 new commits are added:

Intended for serving historical documents and loading data from Postgres or SQlite
- Introduce a `db` module responsible for managing database
- Add `connect` function that's generic over SQLite and Postgres
Defaults to local SQLite database if `DATABASE_URL` is missing.
After connecting, run any/all migrations that are necessary.
To manage migrations, it's first necessary to install `sqlx-cli`.

- `cargo install sqlx-cli`.

Then, `sqlx migrate add <name>` to add a new migration.
Adding new migrations won't trigger cargo recompilation, so sqlx
strongly suggests we trigger a recompilation on new migrations.
After adding another field to the `AppState` struct the integration
tests started failing. However, for the archive tests we don't really
care about having database connection. To resolve, introduce a trait
`GlobalState` that `init_app` implements and initializes the archive.
This way we're flexibile in our testing framework and can use different
structs to initialize the global app state.
This abstracts away the concrete database pool that's used by underlying sqlx. Trade-off is that we need the database-url to differentiate between databases
The purpose of the submodule is to store any/all functions that work
with rdf. Currently the underlying implementation relies on `sophia` to
parse the graph and retrieve triples.

Add `namespaces.rs` module that stores rdf namespaces. Currently stores
the `oll` and `dcterms` ontology. I expected the `dcterms` to be
supported out-of-the-box, but `sophia` supports only the most frequently
used namespaces.
Set a boolean revoked to True for publications that exist on same date. Revoked publications aren't accounted for when querying for versions for a publication.
Used for partially inserting changes by finding the last inserted pub, then the last inserted version
Re-use the existing insert function, as most of the code is the same.
The only difference is that we skip parsing/loading publications which
are already inserted in the db. For publication directories which aren't
in the DB, we continue inserting changes.
- Introduce a `routing` module, intended as a central place
to map all routing in stelae app. Introduced the `_api` scope
with the versions endpoint
- feat(api): initial versions endpoint
- feat(app): call register_api routing function
- feat(api): extract stele name from request
This commit introduces a new endpoint in stelae to get all the
meaningful dates on which a document or a collection changed.

Below is a summary of significant changes:

- Add a new `api` module as a centralized place to look at all the endpoints stelae
  has.
- refact: rename publish to app
- feat(db): add Manager traits for model

  The reasoning being it's easier visually figure out which database queries work with which data structure.

- feat(db): add version struct
- feat(db): implement document and collection version queries

 Idea being we query for all the versions in which document or a collection changed.

- feat(api): get all versions for a publication

 Executes the database query for document or library versions.

- feat(api): map request/response body to structs

 Idea being it's more legibile to reason about the structure of the api.
 Rely on serde to serialize/deserialize values from and into json.

- Introduce the `requests` and `response` modules for mapping the
  endpoint response to historical data for presentation
- feat(api): support for historical messages

 In addition to the versions, we also display HTML messages that: i)
 show on which historical publication the user is currently on, ii)
 through which dates the currently viewed version was valid from
 (start and end date). If comparing versions, we show how many
 changes happened between the compare and version date.
- fix(api): assign Current value to variable after historical messages
- refact: separate formatting logic into associated function
  `format_display_date`
- lots of clippy lints
For the API, move the `versions.rs` into `versions/mod.rs`. The two
modules for request and response are now in `request/mod.rs` and
`response/mod.rs`. Historical messages are in the `response/messages.rs`
module
@n-dusan n-dusan added the enhancement New feature or request label May 15, 2024
@n-dusan n-dusan requested a review from tombh May 15, 2024 10:21
@n-dusan n-dusan self-assigned this May 15, 2024
@tombh tombh changed the base branch from main to ndusan/add-database-access May 15, 2024 14:47
@tombh tombh changed the base branch from ndusan/add-database-access to main May 15, 2024 14:48
These modules should make the code base more legibile.

These changes include:
- Moving `serve` current documents endpoint into `server/api/serve`
  module.

  This way we'll centralize all future endpoint logic in the `api` module

- Centralize routing into `routes` mod.

 We'll expect to add new 'static' routing, while also keeping our
 dynamic logic in the same place.

- Centralize global app state into `state` mod.

- Small updates following the re-org of current codebase

refact: rename structs in `state.rs` module to fix linting issues

Address clippy lint warnings/pedantic errors related to generics in function arguments
@n-dusan n-dusan marked this pull request as ready for review May 16, 2024 11:41
@tombh
Copy link
Contributor

tombh commented May 19, 2024

I've made a new PR to isolate the commits #40

@n-dusan
Copy link
Contributor Author

n-dusan commented May 20, 2024

Closing in favor of #40

@n-dusan n-dusan closed this May 20, 2024
@n-dusan n-dusan deleted the ndusan/versions-api branch May 21, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serve historical documents
2 participants