Skip to content

Commit

Permalink
Add Update and Delete Ingestion Command Handlers
Browse files Browse the repository at this point in the history
Introduced two new command handlers for updating and deleting ingestion processes. These handlers are defined but not yet implemented. Additionally, a print statement was added to log ingestion confirmation in the log_ingestion module.
  • Loading branch information
keinsell committed Dec 4, 2024
1 parent f0040ef commit a095529
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 96 deletions.
4 changes: 1 addition & 3 deletions .archive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@

<br>

<p align="center">
Neuronek is an application that provides essential tools for people who want to use psychoactive
substances in a safe and healthy way, regardless of their personal goals or usage patterns. The app offers personalized
dosing recommendations, insights into usage patterns, a comprehensive database of substances, and a community of users
who are also interested in promoting responsible usage of these substances.

<p align="center">
Special thanks for current >10 ⭐ stargazzers, somehow this revived project.
</p>


Expand Down
1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions cli/src/ingestion/delete_ingestion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::CommandHandler;
use clap::Parser;
use sea_orm::DatabaseConnection;

#[derive(Parser, Debug)]
#[command(version, about = "Update ingestion", long_about)]
pub struct DeleteIngestion {}

impl CommandHandler for DeleteIngestion
{
fn handle(&self, database_connection: &DatabaseConnection) -> Result<(), String> { todo!() }
}
14 changes: 11 additions & 3 deletions cli/src/ingestion/log_ingestion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{CommandHandler, database::{self, ingestion::Entity as Ingestion}};
use crate::CommandHandler;
use crate::database::ingestion::Entity as Ingestion;
use crate::database::{self};
use crate::ingestion::ViewModel;
use crate::route_of_administration::RouteOfAdministrationClassification;
use anyhow::Context;
use anyhow::Result;
Expand All @@ -9,8 +12,11 @@ use chrono_english::parse_date_string;
use clap::Error;
use clap::Parser;
use sea_orm::ActiveValue;
use sea_orm::{DatabaseConnection, EntityTrait, QueryOrder};
use sea_orm::DatabaseConnection;
use sea_orm::EntityTrait;
use sea_orm::QueryOrder;
use smol::block_on;
use std::fmt::Display;
use thiserror::Error;
use tracing::Level;
use tracing::event;
Expand All @@ -19,7 +25,7 @@ use tracing_attributes::instrument;

#[derive(Parser, Debug)]
#[command(version, about = "Store information about new ingestion", long_about)]
pub struct LogIngestion
pub struct LogIngestion
{
#[arg(short = 's', long)]
pub substance_name: String,
Expand Down Expand Up @@ -89,6 +95,8 @@ impl CommandHandler for LogIngestion
event!(Level::INFO, "Ingestion Logged {:?}", &ingestion);
info!("Ingestion successfully logged. {:?}", ingestion);

println!("Ingestion Logged {:?}", &ingestion);

Ok(())
}
}
Expand Down
47 changes: 29 additions & 18 deletions cli/src/ingestion/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
use crate::database::ingestion;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use chrono::DateTime;
use chrono::Utc;
use serde::Deserialize;
use serde::Serialize;
use tabled::Tabled;

mod log_ingestion;
mod delete_ingestion;
mod list_ingestions;
mod log_ingestion;
mod update_ingestion;

pub use delete_ingestion::DeleteIngestion;
pub use list_ingestions::ListIngestions;
pub use log_ingestion::LogIngestion;
pub use update_ingestion::UpdateIngestion;

pub use log_ingestion::{LogIngestion};
pub use list_ingestions::ListIngestions;#[derive(Debug, Serialize, Deserialize, Tabled)]
pub struct ViewModel {
#[derive(Debug, Serialize, Deserialize, Tabled)]
pub struct ViewModel
{
pub id: i32,
pub substance_name: String,
pub route: String,
Expand All @@ -17,21 +26,22 @@ pub struct ViewModel {
pub taken_at: DateTime<Utc>,
}

impl std::fmt::Display for ViewModel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} {} {} {} {} {}",
self.id,
self.substance_name,
self.route,
self.amount,
self.notes,
self.taken_at
impl std::fmt::Display for ViewModel
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
{
write!(
f,
"{} {} {} {} {} {}",
self.id, self.substance_name, self.route, self.amount, self.notes, self.taken_at
)
}
}

impl From<ingestion::Model> for ViewModel {
fn from(model: ingestion::Model) -> Self {
impl From<ingestion::Model> for ViewModel
{
fn from(model: ingestion::Model) -> Self
{
Self {
id: model.id,
substance_name: model.substance_name,
Expand All @@ -43,6 +53,7 @@ impl From<ingestion::Model> for ViewModel {
}
}

fn display_option_string(opt: &Option<String>) -> String {
fn display_option_string(opt: &Option<String>) -> String
{
opt.as_deref().unwrap_or("-").to_string()
}
12 changes: 12 additions & 0 deletions cli/src/ingestion/update_ingestion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::CommandHandler;
use clap::Parser;
use sea_orm::DatabaseConnection;

#[derive(Parser, Debug)]
#[command(version, about = "Update ingestion", long_about)]
pub struct UpdateIngestion {}

impl CommandHandler for UpdateIngestion
{
fn handle(&self, database_connection: &DatabaseConnection) -> Result<(), String> { todo!() }
}
51 changes: 38 additions & 13 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,41 @@ mod ingestion;
mod logging;
mod route_of_administration;
mod state;
use crate::ingestion::{LogIngestion, ListIngestions};
use crate::ingestion::DeleteIngestion;
use crate::ingestion::ListIngestions;
use crate::ingestion::LogIngestion;
use crate::ingestion::UpdateIngestion;
use neuronek_cli::CommandHandler;
use sea_orm_migration::IntoSchemaManagerConnection;
use crate::logging::setup_logging;
use std::path::PathBuf;

#[derive(Parser)]
#[command(
version = env!("CARGO_PKG_VERSION"),
about = "Dosage journal that knows!",
long_about = "🧬 Intelligent dosage tracker application with purpose to monitor supplements, nootropics and psychoactive substances along with their long-term influence on one's mind and body."
)]
struct CommandLineInterface {
struct CommandLineInterface
{
#[command(subcommand)]
command: Option<Commands>,
}

#[derive(Subcommand)]
enum Commands {
enum Commands
{
Log(LogIngestion),
List(ListIngestions),
Delete(DeleteIngestion),
Update(UpdateIngestion),
}

fn main() {
fn main()
{
// setup_logging().expect("failed to setup logging");

// Parse CLI arguments
let cli = CommandLineInterface::parse();

// Initialize database connection
let db_connection = &DATABASE_CONNECTION;

Expand All @@ -55,7 +61,8 @@ fn main() {
.await
.expect("Failed to read pending migrations");

if !pending_migrations.is_empty() {
if !pending_migrations.is_empty()
{
println!("There are {} migrations pending.", pending_migrations.len());
println!("Applying migrations...");
database::Migrator::up(db_connection.into_schema_manager_connection(), None)
Expand All @@ -65,20 +72,38 @@ fn main() {
});

// Handle commands
match &cli.command {
Some(Commands::Log(log_ingestion)) => {
match &cli.command
{
| Some(Commands::Log(log_ingestion)) =>
{
log_ingestion.handle(db_connection).unwrap_or_else(|e| {
eprintln!("Error handling log command: {}", e);
std::process::exit(1);
});
}
Some(Commands::List(list_ingestions)) => {
| Some(Commands::List(list_ingestions)) =>
{
list_ingestions.handle(db_connection).unwrap_or_else(|e| {
eprintln!("Error handling list command: {}", e);
std::process::exit(1);
});
}
None => {
| Some(Commands::Delete(delete_ingestion)) =>
{
delete_ingestion.handle(db_connection).unwrap_or_else(|e| {
eprintln!("Error handling delete command: {}", e);
std::process::exit(1);
})
}
| Some(Commands::Update(update_ingestion)) =>
{
update_ingestion.handle(db_connection).unwrap_or_else(|e| {
eprintln!("Error handling update command: {}", e);
std::process::exit(1);
})
}
| None =>
{
println!("No command provided. Use --help for usage information.");
}
}
Expand Down
76 changes: 18 additions & 58 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,20 @@
There is a lot to be contained in documentation but I think application should be developed from it's own core which is storing user's ingestion - so let's start from this purpose.
<h1 align="center">🧬</h1>
<h2 align="center">Neuronek</h2>

```
.
|-- README.md
|-- architecture
| |-- containers
| | |-- API\ Gateway.md
| | |-- Database.md
| | `-- Web\ Application.md
| |-- context-diagram.d2
| |-- decisions
| | |-- 01-Technology-Stack.md
| | |-- 02-API-Framework.md
| | |-- 03-API-Deployment.md
| | `-- 04-Unit-Testing.md
| |-- package-architecture.d2
| `-- system-design.d2
|-- domain
| |-- aggregates
| | |-- <aggregate_name>
| | | |-- <entity_name>.md
| | | |-- <aggregate_name>.md
| |-- personas
| | |-- 10-john.md
| | |-- 20-sarah.md
| | |-- 30-lisa.md
| | |-- 40-mark.md
| | |-- 50-emily.md
| | `-- 60-max.md
| `-- stories
| |-- 1-dosage-tracking.md
| |-- 2-dosage-reminders.md
| |-- 3-stack-planning.md
| |-- 4-possesion-tracking.md
| |-- 5-mood-tracking.md
| `-- 6-substance-information.md
`-- reference
```
<p align="center">
<b>Build journal of your neurochemisty</b>
<br><br>
<a href="https://codecov.io/gh/keinsell/neuronek" >
<img src="https://codecov.io/gh/keinsell/neuronek/branch/main/graph/badge.svg?token=RCgwN04Ije"/>
</a>
<a href="https://wakatime.com/badge/user/13a02f4d-34c9-45f7-95ee-bf9d66b139fb/project/69d00351-b8a4-4431-a21e-798846120e57"><img src="https://wakatime.com/badge/user/13a02f4d-34c9-45f7-95ee-bf9d66b139fb/project/69d00351-b8a4-4431-a21e-798846120e57.svg" alt="wakatime"></a>
</p>

```
my-monorepo/ (System Context)
├── README.md (System description)
├── web-app/ (Container)
│ ├── README.md (Container description)
│ ├── authentication/ (Component)
│ │ ├── README.md (Component description)
│ │ ├── login.js
│ │ └── signup.js
│ ├── product-catalog/ (Component)
│ │ └── ...
│ └── shopping-cart/ (Component)
│ └── ...
├── api-gateway/ (Container)
│ └── ...
├── database/ (Container)
│ └── ...
└── shared-library/ (Container)
└── ...
```
<br>

<p align="center">
Neuronek is an application that provides essential tools for people who want to use psychoactive
substances in a safe and healthy way, regardless of their personal goals or usage patterns. The app offers personalized
dosing recommendations, insights into usage patterns, a comprehensive database of substances, and a community of users
who are also interested in promoting responsible usage of these substances.
</p>

0 comments on commit a095529

Please sign in to comment.