feat: with updated deps

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-06-04 14:42:38 +02:00
parent 534b2e4a23
commit 2604c5e301
21 changed files with 509 additions and 396 deletions

View File

View File

@@ -0,0 +1,9 @@
fn main() {
println!("cargo:rustc-env=SQLX_OFFLINE_DIR='./.sqlx'");
// When building in docs.rs, we want to set SQLX_OFFLINE mode to true
if std::env::var_os("DOCS_RS").is_some() {
println!("cargo:rustc-env=SQLX_OFFLINE=true");
} else if std::env::var_os("DOCKER_BUILD").is_some() {
println!("cargo:rustc-env=SQLX_OFFLINE=true");
}
}

View File

@@ -0,0 +1,346 @@
{
"db": "PostgreSQL",
"05d0a7901f0481d7443f125655df26eeacd63f2b023723a0c09c662617e0baf5": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "title",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "description",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "state",
"ordinal": 3,
"type_info": "Varchar"
},
{
"name": "project_id",
"ordinal": 4,
"type_info": "Uuid"
}
],
"nullable": [
false,
false,
true,
false,
false
],
"parameters": {
"Left": [
"Uuid",
"Text"
]
}
},
"query": "\n SELECT id, title, description, state, project_id\n FROM items\n WHERE id = $1 AND user_id = $2\n "
},
"3b4484c5ccfd4dcb887c4e978fe6e45d4c9ecc2a73909be207dced79ddf17d87": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
}
],
"nullable": [
false
],
"parameters": {
"Left": [
"Varchar",
"Varchar"
]
}
},
"query": "\n INSERT INTO users (username, password_hash) \n VALUES ( $1, $2 ) \n RETURNING id\n "
},
"4ec32ebd0ee991cec625d9de51de0d3e0ddfc8afda0568327fa9c818bde08e1f": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
}
],
"nullable": [
false
],
"parameters": {
"Left": [
"Uuid",
"Varchar",
"Varchar",
"Varchar",
"Timestamp",
"Timestamp"
]
}
},
"query": "\n INSERT INTO projects (id, name, description, user_id, created_at, updated_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id\n "
},
"7901e81b1f1f08f0c7e72a967a8116efb62f40d99f80900f1e56cd13ad4f6bb2": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "title",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "description",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "state",
"ordinal": 3,
"type_info": "Varchar"
},
{
"name": "project_id",
"ordinal": 4,
"type_info": "Uuid"
}
],
"nullable": [
false,
false,
true,
false,
false
],
"parameters": {
"Left": [
"Uuid",
"Varchar",
"Varchar",
"Varchar",
"Uuid",
"Varchar"
]
}
},
"query": "\n INSERT INTO items (id, title, description, state, project_id, user_id, created_at, updated_at)\n VALUES ($1, $2, $3, $4, $5, $6, now(), now())\n RETURNING id, title, description, state, project_id\n "
},
"a188dc748025cf3311820d16002b111a75f571d18f44f54b730ac14e9b2e10ea": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "name",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "description",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "user_id",
"ordinal": 3,
"type_info": "Varchar"
}
],
"nullable": [
false,
false,
true,
false
],
"parameters": {
"Left": [
"Uuid",
"Text"
]
}
},
"query": "\n SELECT id, name, description, user_id\n FROM projects\n WHERE id = $1 and user_id = $2\n "
},
"b930a7123d22d543e4d8ed70a1bc10477362127969ceca9653e445f26670003a": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "name",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "description",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "user_id",
"ordinal": 3,
"type_info": "Varchar"
}
],
"nullable": [
false,
false,
true,
false
],
"parameters": {
"Left": [
"Text"
]
}
},
"query": "\n SELECT id, name, description, user_id\n FROM projects\n WHERE user_id = $1\n LIMIT 500\n "
},
"bacf3c8a2f302d50991483fa36a06965c3536c2ef3837c19c6e6361eff312848": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "title",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "description",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "state",
"ordinal": 3,
"type_info": "Varchar"
},
{
"name": "project_id",
"ordinal": 4,
"type_info": "Uuid"
}
],
"nullable": [
false,
false,
true,
false,
false
],
"parameters": {
"Left": [
"Varchar",
"Varchar",
"Varchar",
"Uuid",
"Uuid",
"Text"
]
}
},
"query": "\n UPDATE items\n SET \n title = COALESCE($1, title), \n description = COALESCE($2, description), \n state = COALESCE($3, state), \n project_id = COALESCE($4, project_id), \n updated_at = now()\n WHERE id = $5 AND user_id = $6\n RETURNING id, title, description, state, project_id\n "
},
"bd2407ffb9637afcff3ffe1101e7c1920b8cf0be423ab0313d14acc9c76e0f93": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "title",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "description",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "state",
"ordinal": 3,
"type_info": "Varchar"
},
{
"name": "project_id",
"ordinal": 4,
"type_info": "Uuid"
}
],
"nullable": [
false,
false,
true,
false,
false
],
"parameters": {
"Left": [
"Text",
"Uuid"
]
}
},
"query": "\n SELECT id, title, description, state, project_id\n FROM items\n WHERE user_id = $1 and project_id = $2\n LIMIT 500\n "
},
"d3f222cf6c3d9816705426fdbed3b13cb575bb432eb1f33676c0b414e67aecaf": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "username",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "password_hash",
"ordinal": 2,
"type_info": "Varchar"
}
],
"nullable": [
false,
false,
false
],
"parameters": {
"Left": [
"Text"
]
}
},
"query": "\n SELECT * from users\n where username=$1\n "
}
}

View File

@@ -1,24 +1,22 @@
use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
use crate::database::ConnectionPool;
use async_trait::async_trait;
use como_core::items::ItemService;
use como_domain::{
item::{
queries::{GetItemQuery, GetItemsQuery},
requests::CreateItemDto,
requests::{CreateItemDto, UpdateItemDto},
responses::CreatedItemDto,
ItemDto,
},
user::ContextUserExt,
Context,
};
use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
use uuid::Uuid;
use crate::database::ConnectionPool;
pub struct DefaultItemService {
pool: ConnectionPool,
}
@@ -48,7 +46,7 @@ impl ItemService for DefaultItemService {
RETURNING id, title, description, state, project_id
"#,
Uuid::new_v4(),
item.name,
item.title,
item.description,
state,
item.project_id,
@@ -121,6 +119,41 @@ impl ItemService for DefaultItemService {
})
.collect())
}
async fn update_item(&self, context: &Context, item: UpdateItemDto) -> anyhow::Result<ItemDto> {
let state = item.state.map(|s| serde_json::to_string(&s)).transpose()?;
let user_id = context.get_user_id().ok_or(anyhow::anyhow!("no user id"))?;
let rec = sqlx::query!(
r#"
UPDATE items
SET
title = COALESCE($1, title),
description = COALESCE($2, description),
state = COALESCE($3, state),
project_id = COALESCE($4, project_id),
updated_at = now()
WHERE id = $5 AND user_id = $6
RETURNING id, title, description, state, project_id
"#,
item.title,
item.description,
state,
item.project_id,
item.id,
user_id,
)
.fetch_one(&self.pool)
.await?;
Ok(ItemDto {
id: rec.id,
title: rec.title,
description: rec.description,
state: serde_json::from_str(&rec.state)?,
project_id: rec.project_id,
})
}
}
pub struct MemoryItemService {
@@ -145,7 +178,7 @@ impl ItemService for MemoryItemService {
if let Ok(mut item_store) = self.item_store.lock() {
let item = ItemDto {
id: Uuid::new_v4(),
title: create_item.name,
title: create_item.title,
description: create_item.description,
state: como_domain::item::ItemState::Created,
project_id: create_item.project_id,
@@ -177,4 +210,8 @@ impl ItemService for MemoryItemService {
) -> anyhow::Result<Vec<ItemDto>> {
todo!()
}
async fn update_item(&self, context: &Context, item: UpdateItemDto) -> anyhow::Result<ItemDto> {
todo!()
}
}

View File

@@ -1,46 +0,0 @@
{
"query": "\n SELECT id, title, description, state, project_id\n FROM items\n WHERE user_id = $1 and project_id = $2\n LIMIT 500\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Uuid"
},
{
"ordinal": 1,
"name": "title",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "description",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "state",
"type_info": "Varchar"
},
{
"ordinal": 4,
"name": "project_id",
"type_info": "Uuid"
}
],
"parameters": {
"Left": [
"Text",
"Uuid"
]
},
"nullable": [
false,
false,
true,
false,
false
]
},
"hash": "bd2407ffb9637afcff3ffe1101e7c1920b8cf0be423ab0313d14acc9c76e0f93"
}

View File

@@ -1,33 +0,0 @@
{
"query": "\n SELECT * from users\n where username=$1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Uuid"
},
{
"ordinal": 1,
"name": "username",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "password_hash",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
false
]
},
"hash": "d3f222cf6c3d9816705426fdbed3b13cb575bb432eb1f33676c0b414e67aecaf"
}