app_store_server_library/models/
bullet_point.rs1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4const MAXIMUM_TEXT_LENGTH: usize = 66;
5const MAXIMUM_ALT_TEXT_LENGTH: usize = 150;
6
7#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)]
11#[serde(rename_all = "camelCase")]
12pub struct BulletPoint {
13 pub text: String,
17
18 pub image_identifier: Uuid,
22
23 pub alt_text: String,
27}
28
29impl BulletPoint {
30 pub fn new(text: String, image_identifier: Uuid, alt_text: String) -> Result<Self, BulletPointValidationError> {
37 if text.chars().count() > MAXIMUM_TEXT_LENGTH {
38 return Err(BulletPointValidationError::TextTooLong);
39 }
40 if alt_text.chars().count() > MAXIMUM_ALT_TEXT_LENGTH {
41 return Err(BulletPointValidationError::AltTextTooLong);
42 }
43 Ok(Self {
44 text,
45 image_identifier,
46 alt_text,
47 })
48 }
49}
50
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub enum BulletPointValidationError {
53 TextTooLong,
54 AltTextTooLong,
55}
56
57impl std::fmt::Display for BulletPointValidationError {
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 match self {
60 BulletPointValidationError::TextTooLong => write!(
61 f,
62 "Text exceeds maximum length of {} characters",
63 MAXIMUM_TEXT_LENGTH
64 ),
65 BulletPointValidationError::AltTextTooLong => write!(
66 f,
67 "Alt text exceeds maximum length of {} characters",
68 MAXIMUM_ALT_TEXT_LENGTH
69 ),
70 }
71 }
72}
73
74impl std::error::Error for BulletPointValidationError {}