completed most of 05 ticket v2

This commit is contained in:
2025-03-17 06:39:58 +05:30
parent 8d1342c831
commit 8413518a84
14 changed files with 132 additions and 27 deletions

View File

@@ -7,15 +7,18 @@
struct Ticket {
title: String,
description: String,
status: String,
status: Status,
}
#[derive(Debug, PartialEq, Clone, Copy)]
enum Status {
// TODO: add the missing variants
ToDo,
InProgress,
Done,
}
impl Ticket {
pub fn new(title: String, description: String, status: String) -> Ticket {
pub fn new(title: String, description: String, status: Status) -> Ticket {
if title.is_empty() {
panic!("Title cannot be empty");
}
@@ -28,7 +31,7 @@ impl Ticket {
if description.len() > 500 {
panic!("Description cannot be longer than 500 bytes");
}
if status != "To-Do" && status != "In Progress" && status != "Done" {
if status != Status::ToDo && status != Status::InProgress && status != Status::Done {
panic!("Only `To-Do`, `In Progress`, and `Done` statuses are allowed");
}
@@ -47,7 +50,7 @@ impl Ticket {
&self.description
}
pub fn status(&self) -> &String {
pub fn status(&self) -> &Status {
&self.status
}
}