-
Notifications
You must be signed in to change notification settings - Fork 0
feat(domain): SQLite repo for Package aggregate (task 26) #130
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b6be4c6
feat(domain): SQLite repo for Package aggregate (task 26)
mpiton b387f39
fix(domain): address PR #130 review comments
mpiton 94558cf
fix(domain): reject negative created_at on package load
mpiton f13c1b2
fix(sqlite): use SQLite '?' placeholder in list_downloads query
mpiton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| use sea_orm::entity::prelude::*; | ||
|
|
||
| use crate::domain::error::DomainError; | ||
| use crate::domain::model::package::{Package, PackageId, PackageSourceType}; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] | ||
| #[sea_orm(table_name = "packages")] | ||
| pub struct Model { | ||
| #[sea_orm(primary_key, auto_increment = false)] | ||
| pub id: String, | ||
| pub name: String, | ||
| pub source_type: String, | ||
| pub folder_path: Option<String>, | ||
| pub password: Option<String>, | ||
| pub auto_extract: i32, | ||
| pub priority: i32, | ||
| pub created_at: i64, | ||
| } | ||
|
|
||
| #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
| pub enum Relation {} | ||
|
|
||
| impl ActiveModelBehavior for ActiveModel {} | ||
|
|
||
| impl Model { | ||
| pub fn into_domain(self) -> Result<Package, DomainError> { | ||
| let source_type: PackageSourceType = self.source_type.parse()?; | ||
| let auto_extract = match self.auto_extract { | ||
| 0 => false, | ||
| 1 => true, | ||
| other => { | ||
| return Err(DomainError::ValidationError(format!( | ||
| "package {}: auto_extract {other} out of bool range", | ||
| self.id | ||
| ))); | ||
| } | ||
| }; | ||
| let priority = u8::try_from(self.priority).map_err(|_| { | ||
| DomainError::ValidationError(format!( | ||
| "package {}: priority {} out of u8 range", | ||
| self.id, self.priority | ||
| )) | ||
| })?; | ||
| let created_at = u64::try_from(self.created_at).map_err(|_| { | ||
| DomainError::ValidationError(format!( | ||
| "package {}: created_at {} out of u64 range", | ||
| self.id, self.created_at | ||
| )) | ||
| })?; | ||
| Package::reconstruct( | ||
| PackageId::new(self.id), | ||
| self.name, | ||
| source_type, | ||
| self.folder_path, | ||
| self.password, | ||
| auto_extract, | ||
| priority, | ||
| created_at, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl ActiveModel { | ||
| pub fn from_domain(package: &Package) -> Result<Self, DomainError> { | ||
| use sea_orm::ActiveValue::Set; | ||
|
|
||
| let id_str = package.id().as_str().to_string(); | ||
| let created_at = i64::try_from(package.created_at()).map_err(|_| { | ||
| DomainError::ValidationError(format!("package {id_str}: created_at exceeds i64::MAX")) | ||
| })?; | ||
|
|
||
| Ok(Self { | ||
| id: Set(id_str), | ||
| name: Set(package.name().to_string()), | ||
| source_type: Set(package.source_type().to_string()), | ||
| folder_path: Set(package.folder_path().map(str::to_string)), | ||
| password: Set(package.password().map(str::to_string)), | ||
| auto_extract: Set(if package.auto_extract() { 1 } else { 0 }), | ||
| priority: Set(i32::from(package.priority())), | ||
| created_at: Set(created_at), | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.