completed 03/[00-07]

This commit is contained in:
2025-02-24 15:53:03 +05:30
parent 7910a25928
commit 9161d08b1c
8 changed files with 116 additions and 25 deletions

View File

@@ -10,23 +10,62 @@ pub struct Ticket {
}
impl Ticket {
pub fn new(title: String, description: String, status: String) -> Ticket {
if title.is_empty() {
fn cTitleEmpty(newString: &String) -> bool {
if newString.is_empty() {
panic!("Title cannot be empty");
}
if title.len() > 50 {
false
}
fn cTitleTooLong(newString: &String) -> bool {
if newString.len() > 50 {
panic!("Title cannot be longer than 50 bytes");
}
if description.is_empty() {
panic!("Description cannot be empty");
}
if description.len() > 500 {
false
}
fn cDescTooLong(newDesc: &String) -> bool {
if newDesc.len() > 500 {
panic!("Description cannot be longer than 500 bytes");
}
if status != "To-Do" && status != "In Progress" && status != "Done" {
false
}
fn cDescEmpty(newDesc: &String) -> bool {
if newDesc.is_empty() {
panic!("Description cannot be empty");
}
false
}
fn cInvalidStatus(newStatus: &String) -> bool {
if newStatus != "To-Do" && newStatus != "In Progress" && newStatus != "Done" {
panic!("Only `To-Do`, `In Progress`, and `Done` statuses are allowed");
}
false
}
pub fn new(title: String, description: String, status: String) -> Ticket {
// if title.is_empty() {
// panic!("Title cannot be empty");
// }
// if title.len() > 50 {
// panic!("Title cannot be longer than 50 bytes");
// }
// if description.is_empty() {
// panic!("Description cannot be empty");
// }
// if description.len() > 500 {
// panic!("Description cannot be longer than 500 bytes");
// }
// if status != "To-Do" && status != "In Progress" && status != "Done" {
// panic!("Only `To-Do`, `In Progress`, and `Done` statuses are allowed");
// }
Ticket::cTitleTooLong(&title);
Ticket::cTitleTooLong(&title);
Ticket::cDescEmpty(&description);
Ticket::cDescTooLong(&description);
Ticket::cInvalidStatus(&status);
Ticket {
title,
description,
@@ -34,6 +73,21 @@ impl Ticket {
}
}
pub fn set_title(&mut self, newTitle: String) {
Ticket::cTitleEmpty(&newTitle);
Ticket::cTitleTooLong(&newTitle);
self.title = newTitle;
}
pub fn set_description(&mut self, newDesc: String) {
Ticket::cDescEmpty(&newDesc);
Ticket::cDescTooLong(&newDesc);
self.description = newDesc;
}
pub fn set_status(&mut self, newStatus: String) {
Ticket::cInvalidStatus(&newStatus);
self.status = newStatus;
}
pub fn title(&self) -> &String {
&self.title
}