My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: color DTO

+85 -10
+10
Cargo.lock
··· 3267 3267 dependencies = [ 3268 3268 "async-std", 3269 3269 "nanoid", 3270 + "rgb", 3270 3271 "sea-orm", 3271 3272 "sea-orm-migration", 3272 3273 ] ··· 4162 4163 checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" 4163 4164 dependencies = [ 4164 4165 "bytecheck", 4166 + ] 4167 + 4168 + [[package]] 4169 + name = "rgb" 4170 + version = "0.8.53" 4171 + source = "registry+https://github.com/rust-lang/crates.io-index" 4172 + checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4" 4173 + dependencies = [ 4174 + "bytemuck", 4165 4175 ] 4166 4176 4167 4177 [[package]]
+1
crates/dto/migration/Cargo.toml
··· 12 12 async-std = { version = "1", features = ["attributes", "tokio1"] } 13 13 nanoid = "0.4.0" 14 14 sea-orm = "2.0.0-rc" 15 + rgb = "0.8.53" 15 16 16 17 [dependencies.sea-orm-migration] 17 18 version = "2.0.0-rc"
+1 -1
crates/dto/migration/src/m20260318_233726_group_table.rs
··· 25 25 ) 26 26 .col(string(Group::Name).not_null()) 27 27 //Note: Color is a hex color with the leading # 28 - .col(string(Group::Color).not_null()) 28 + .col(integer(Group::Color).not_null()) 29 29 .col( 30 30 string(Group::Priority) 31 31 .not_null()
+1 -1
crates/dto/migration/src/m20260327_175853_tag_table.rs
··· 21 21 .not_null(), 22 22 ) 23 23 .col(string(Tag::Name).not_null()) 24 - .col(string(Tag::Color).not_null()) 24 + .col(integer(Tag::Color).not_null()) 25 25 .to_owned(), 26 26 ) 27 27 .await
+51
crates/dto/migration/src/types/color.rs
··· 1 + use rgb::RGB8; 2 + use sea_orm::DeriveValueType; 3 + use std::fmt::{Debug, Display}; 4 + 5 + /// Color type 6 + /// 7 + /// We store it as a u32, but its actually 00000000rrrrrrrrggggggggbbbbbbbb 8 + #[derive(Clone, Copy, PartialEq, Eq, DeriveValueType)] 9 + pub struct Color(u32); 10 + 11 + impl Color { 12 + /// create a new color 13 + pub fn new(r: u8, g: u8, b: u8) -> Self { 14 + Self(((r as u32) << 16) | ((g as u32) << 8) | (b as u32)) 15 + } 16 + 17 + /// to convert it into a rbg8 type 18 + pub fn to_rgb8(self) -> RGB8 { 19 + RGB8 { 20 + r: ((self.0 >> 16) & 0xFF) as u8, 21 + g: ((self.0 >> 8) & 0xFF) as u8, 22 + b: (self.0 & 0xFF) as u8, 23 + } 24 + } 25 + } 26 + 27 + impl Debug for Color { 28 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 29 + let rgb = self.to_rgb8(); 30 + write!(f, "Color(#{:02X}{:02X}{:02X})", rgb.r, rgb.g, rgb.b) 31 + } 32 + } 33 + 34 + impl Display for Color { 35 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 36 + let rgb = self.to_rgb8(); 37 + write!(f, "#{:02X}{:02X}{:02X}", rgb.r, rgb.g, rgb.b) 38 + } 39 + } 40 + 41 + impl From<RGB8> for Color { 42 + fn from(c: RGB8) -> Self { 43 + Self::new(c.r, c.g, c.b) 44 + } 45 + } 46 + 47 + impl From<Color> for RGB8 { 48 + fn from(c: Color) -> Self { 49 + c.to_rgb8() 50 + } 51 + }
+3
crates/dto/migration/src/types/mod.rs
··· 4 4 mod nano_id; 5 5 pub(crate) use nano_id::NANO_ID_LEN; 6 6 pub use nano_id::NanoId; 7 + 8 + mod color; 9 + pub use color::Color;
+1 -1
crates/dto/src/entity/group.rs
··· 15 15 #[sea_orm(unique)] 16 16 pub nano_id: NanoId, 17 17 pub name: String, 18 - pub color: String, 18 + pub color: Color, 19 19 pub priority: Priority, 20 20 pub created_at: DateTimeUtc, 21 21 pub modified_at: DateTimeUtc,
+3 -2
crates/dto/src/entity/tag.rs
··· 1 1 //! `SeaORM` Entity, @generated by sea-orm-codegen 2.0 2 2 3 3 use migration::types::*; 4 - use sea_orm::{ActiveValue::Set, entity::prelude::*}; 4 + use sea_orm::ActiveValue::Set; 5 + use sea_orm::entity::prelude::*; 5 6 use std::{future::ready, pin::Pin}; 6 7 7 8 #[sea_orm::model] ··· 13 14 #[sea_orm(unique)] 14 15 pub nano_id: NanoId, 15 16 pub name: String, 16 - pub color: String, 17 + pub color: Color, 17 18 #[sea_orm(has_many, via = "zettel_tag")] 18 19 pub zettels: HasMany<super::zettel::Entity>, 19 20 }
+2 -1
crates/dto/src/entity/zettel.rs
··· 1 1 //! `SeaORM` Entity, @generated by sea-orm-codegen 2.0 2 2 3 3 use migration::types::*; 4 - use sea_orm::{ActiveValue::Set, entity::prelude::*}; 4 + use sea_orm::ActiveValue::Set; 5 + use sea_orm::entity::prelude::*; 5 6 use std::{future::ready, pin::Pin}; 6 7 7 8 #[sea_orm::model]
+5
crates/dto/src/lib.rs
··· 15 15 /// and add additional functionality to it. 16 16 pub use migration::types::Priority as PriorityDTO; 17 17 18 + /// Color type, exporting as DTO because I might 19 + /// want to newtype wrap this, might not have to, depending 20 + /// on how I end up using it in the application. 21 + pub use migration::types::Color as ColorDTO; 22 + 18 23 mod entity; 19 24 20 25 /// Everything related to groups.
+3 -1
crates/dto/tests/task.rs
··· 4 4 ActiveModelTrait as _, ActiveValue::Set, GroupActiveModel, GroupEntity, GroupModel, 5 5 TaskActiveModel, TaskEntity, TaskModel, ZettelActiveModel, ZettelEntity, ZettelModel, 6 6 }; 7 + use migration::types::Color; 7 8 mod common; 8 9 9 10 #[tokio::test] ··· 21 22 22 23 let group: GroupModel = GroupActiveModel { 23 24 name: Set("something".to_owned()), 24 - color: Set("color".to_owned()), 25 + color: Set(Color::new(255, 0, 0)), 25 26 zettel_id: Set(group_zettel.nano_id.clone()), 26 27 ..Default::default() 27 28 } ··· 69 70 70 71 println!("group: {group:#?}"); 71 72 println!("task: {task:#?}"); 73 + panic!() 72 74 }
+3 -3
crates/dto/tests/zettel.rs
··· 1 1 use dto::{ 2 - ActiveModelTrait, ActiveValue::Set, TagActiveModel, TagEntity, TagModel, ZettelActiveModel, 3 - ZettelEntity, ZettelModel, 2 + ActiveModelTrait, ActiveValue::Set, ColorDTO, TagActiveModel, TagEntity, TagModel, 3 + ZettelActiveModel, ZettelEntity, ZettelModel, 4 4 }; 5 5 use sea_orm::IntoActiveModel; 6 6 ··· 12 12 13 13 let tag: TagModel = TagActiveModel { 14 14 name: Set("Penis".to_owned()), 15 - color: Set("Some Color".to_owned()), 15 + color: Set(ColorDTO::new(255, 0, 0)), 16 16 ..Default::default() 17 17 } 18 18 .insert(&*db)
+1
justfile
··· 46 46 # replace elementary types with specific ones 47 47 sed -i 's/pub nano_id: String/pub nano_id: NanoId/g' ./src/entity/*.rs 48 48 sed -i 's/pub priority: String/pub priority: Priority/g' ./src/entity/*.rs 49 + sed -i 's/pub color: i64/pub color: Color/g' ./src/entity/*.rs 49 50 50 51 # replace parent_group_id with proper nano_id 51 52 sed -i 's/pub parent_group_id: Option<String>/pub parent_group_id: Option<NanoId>/g' ./src/entity/*.rs