Skip to content

Commit

Permalink
/
Browse files Browse the repository at this point in the history
  • Loading branch information
keinsell committed Dec 5, 2024
1 parent abb1d91 commit 37bd6b3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 109 deletions.
11 changes: 11 additions & 0 deletions CODE_OF_CONDUCT
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Code of Conflict
----------------

Effort in this project is a personal matter and it never meant to be build with community. Contributions from people out of founder's circle are highly unwelcomed and it's strongly disadvised to contribute into this project.

If however, anyone feels personally abused, threatened, or otherwise
uncomfortable due to this process, that is not acceptable and right actions will be taken on such behaviour. There's line between personal abuse and criticism (even if said in unexpected way).

We are all humans, and frustrations can happen. Always remember there's human on the other side which may have bad day or other problems over the head. Try to keep in mind the immortal words of Bill and Ted, "Be excellent to each other.

~ Inspired by Linus Torvald's Code of Conflict
74 changes: 7 additions & 67 deletions cli/src/ingestion/list_ingestions.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
use tracing::Level;
use crate::database;
use crate::database::prelude::Ingestion;
use crate::ingestion::ViewModel;
use crate::lib::CommandHandler;
use clap::Parser;
use sea_orm::DatabaseConnection;
use sea_orm::{DatabaseConnection, QuerySelect};
use sea_orm::EntityTrait;
use sea_orm::QueryOrder;
use sea_orm_migration::MigratorTrait;
use smol::block_on;
use tabled::Table;
use tabled::Tabled;
use tracing_attributes::instrument;

#[derive(Parser, Debug)]
#[command(version, about = "List all ingestions", long_about)]
pub struct ListIngestions
{
/// Defines the number of ingestions to display
/// Defines the amount of ingestion to display
#[arg(short = 'l', long, default_value_t = 10)]
pub linit: i32,
pub limit: u64,
// TODO: Query order by field
// TODO: Return format (JSON/Pretty)
}

impl CommandHandler for crate::ingestion::list_ingestions::ListIngestions
impl CommandHandler for ListIngestions
{
#[instrument(name = "list_ingestions", level = Level::INFO)]
fn handle(&self, database_connection: &DatabaseConnection) -> anyhow::Result<(), String>
{
let ingestions = block_on(async {
Ingestion::find()
.order_by_desc(database::ingestion::Column::IngestedAt)
.limit(Some(self.limit))
.all(database_connection)
.await
.map_err(|e| e.to_string())
Expand All @@ -50,64 +50,4 @@ impl CommandHandler for crate::ingestion::list_ingestions::ListIngestions

Ok(())
}
}

#[cfg(test)]
mod tests
{
use super::*;
use crate::database::ingestion::ActiveModel;
use chrono::TimeZone;
use chrono::Utc;
use sea_orm::ActiveModelTrait;
use sea_orm::Database;
use sea_orm::Set;

#[test]
fn test_list_ingestions()
{
// Create database connection with in-memory SQLite for testing
let conn = block_on(async { Database::connect("sqlite::memory:").await.unwrap() });

// Run migrations
block_on(async {
crate::database::Migrator::up(&conn, None)
.await
.expect("Failed to run migrations");
});

// Insert test data
let test_date = Utc.with_ymd_and_hms(2023, 1, 1, 12, 0, 0).unwrap();
let test_ingestion = ActiveModel {
substance_name: Set("Test Substance".to_string()),
route_of_administration: Set("oral".to_string()),
dosage: Set(100.0),
dosage_unit: Set("mg".to_string()),
ingested_at: Set(test_date),
notes: Set(None),
updated_at: Set(test_date),
created_at: Set(test_date),
..Default::default()
};

block_on(async {
test_ingestion.insert(&conn).await.unwrap();
});

// Test listing ingestions
let list_command = ListIngestions;
let result = list_command.handle(&conn);
assert!(result.is_ok());

// Verify the ingestion exists in database
let ingestions = block_on(async { Ingestion::find().all(&conn).await.unwrap() });

assert_eq!(ingestions.len(), 1);
let ingestion = &ingestions[0];
assert_eq!(ingestion.substance_name, "Test Substance");
assert_eq!(ingestion.dosage, 100.0);
assert_eq!(ingestion.dosage_unit, "mg");
assert_eq!(ingestion.route_of_administration, "oral");
assert_eq!(ingestion.ingested_at, test_date);
}
}
}
2 changes: 1 addition & 1 deletion cli/src/ingestion/log_ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct LogIngestion
/// Name of the substance ingested.
#[arg(short = 's', long)]
pub substance_name: String,
/// Unit in which the substance is ingested (default is "mg).
/// Unit in which the substance is ingested (default is "mg").
#[arg(short = 'u', long, default_value_t=String::from("mg"))]
pub dosage_unit: String,
/// Volume of substance ingested.
Expand Down
7 changes: 7 additions & 0 deletions cli/src/ingestion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ pub enum IngestionError
NotFound(#[from] sea_orm::DbErr),
}

pub enum IngestionCommands {
LogIngestion(LogIngestion),
UpdateIngestion(UpdateIngestion),
DeleteIngestion(DeleteIngestion),
ListIngestions(ListIngestions),
}

impl std::fmt::Display for ViewModel
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
Expand Down
29 changes: 28 additions & 1 deletion cli/src/ingestion/update_ingestion.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
use chrono::{DateTime, Local};
use crate::lib::CommandHandler;
use clap::Parser;
use sea_orm::DatabaseConnection;
use crate::route_of_administration::RouteOfAdministrationClassification;

#[derive(Parser, Debug)]
#[command(version, about = "Update ingestion", long_about)]
pub struct UpdateIngestion {}
pub struct UpdateIngestion {
///.Identifier of the ingestion to update
#[clap(short, long="id")]
pub ingestion_id: String,
/// Name of the substance ingested.
#[arg(short = 's', long)]
pub substance_name: Option<String>,
/// Unit in which the substance is ingested (default is "mg").
#[arg(short = 'u', long)]
pub dosage_unit: Option<String>,
/// Volume of substance ingested.
#[arg(short = 'v', long)]
pub dosage_amount: Option<u64>,
/// Date of ingestion, by default current date is used if not provided.
///
/// Date can be provided as timestamp and in human-readable format such as
/// "today 10:00", "yesterday 13:00", "monday 15:34" which will be later
/// parsed into proper timestamp.
#[arg(
short='t',
long,
)]
pub ingestion_date: Option<DateTime<Local>>,
#[arg(short = 'r', long = "roa")]
pub route_of_administration: RouteOfAdministrationClassification,
}

impl CommandHandler for UpdateIngestion
{
Expand Down
45 changes: 5 additions & 40 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<h1 align="center">neuronek</h1>

<p align="center">
Expand All @@ -21,49 +20,15 @@ who are also interested in promoting responsible usage of these substances.

## Getting Started

Start by not writing any code.

```
```

This is just an example application, but imagine it doing anything you want. Adding new features is easy too:

```
```

The possibilities are endless.

### Building the Application

Now that you have not done anything it's time to build your application:

```
```

Yep. That's it. You should see the following output:

```
```

### Deploying

While you still have not done anything it's time to deploy your application. By running the following command you can deploy your application absolutely nowhere.

```
```
### Installation

It's that simple. And when it comes time to scale the application, all you have to do is:
Application will be distributed in multiple forms, currently we mainly focus on [`cli`](./cli/README.md) which is available for every platform (you can download compiled binary from CI/CD artifacts)

```
#### Compile from source

```
### Usage

I know right?
- `neuronek log -s caffeine -v 80`, logs 80mg ingestion of caffeine

## Contributing

Expand Down

0 comments on commit 37bd6b3

Please sign in to comment.