-
Notifications
You must be signed in to change notification settings - Fork 2
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
Update paste.rs #2
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your attention and time. I believe this code serves educational purposes, and it would be beneficial to include comments. I understand that for production-grade code, this may slightly reduce code readability. so i prefer to don't remove this comments.
@@ -4,15 +4,15 @@ use serde::{Deserialize, Serialize}; | |||
use std::borrow::Cow; | |||
|
|||
pub const MAX_PASTE_VALUE_SIZE: u32 = 16 * 1024; | |||
pub const DELETE_TEPMLATE: &str = "DELETE"; | |||
pub const DELETE_TEMPLATE: &str = "DELETE"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😉
impl PasteData { | ||
pub fn create(id: u64, user_id: Option<Principal>, info: PasteDataCreator) -> Self { | ||
PasteData { | ||
id: id.to_string(), | ||
name: info.name, | ||
creator: user_id, | ||
description: info.description, | ||
expire_date: info.expire_date, | ||
content: info.content, | ||
tags: _create_tags(info.tags), | ||
version: 1, | ||
} | ||
} | ||
|
||
pub fn update(&mut self, info: PasteDataUpdater) { | ||
if let Some(name) = info.name { | ||
self.name = name; | ||
} | ||
if let Some(desc) = info.description { | ||
self.description = desc; | ||
} | ||
if let Some(content) = info.content { | ||
self.content = content; | ||
} | ||
if let Some(tags) = info.tags { | ||
self.tags = _create_tags(tags); | ||
} | ||
|
||
// Increase the number of changes | ||
self.version += 1; | ||
} | ||
|
||
// Clear the content of the paste | ||
pub fn clear(&mut self) { | ||
self.name = DELETE_TEMPLATE.to_string(); | ||
self.content = DELETE_TEMPLATE.to_string(); | ||
self.tags = Vec::new(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand what is your changes. is it git diff problem?
.split_whitespace() | ||
.filter(|v| !v.is_empty()) | ||
.map(String::from) | ||
.collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is much nice and cleaner. thanks
Hello @setbap
This pull request addresses various improvements and fixes in two canisters, namely
lib
andpaste
. The changes aim to enhance code clarity, error handling, and overall maintainability.Changes in
paste
CanisterRefactored PasteData Logic: Restructured the logic for managing PasteData, improving code structure and modularity.
Improved Error Messages: Enhanced error messages for paste-related queries and updates, providing clearer information about the encountered issues.
Simplified Code for Finding Pastes: Simplified the code for finding pastes by tags, extension, name, and short URL, making it more readable and maintainable.
Optimized Paste Retrieval: Optimized the retrieval of pastes by user, last N pastes, and other queries for better performance.
General Improvements
Consistent Naming Conventions: Ensured consistent naming conventions throughout the codebase for better code readability.
Enhanced Code Comments: Improved code comments to provide better documentation and understanding of the code.
Fixed Minor Typos: Corrected minor typos in comments and variable names.