lacoctelera::domain::author

Struct Author

Source
pub struct Author {
    pub shareable: Option<bool>,
    /* private fields */
}
Expand description

Object that represents an Author of the Cocktail data base.

§Description

Authors’ main role is defining recipes in the data base, and own them until they delete them or transfer the ownership. This object is a simple descriptor that includes some personal information of the authors.

All attributes are optional to allow using this struct as query object for the GET methods of the /author endpoint. Mandatory fields are defined in the description of each method of the endpoint.

Some restrictions over the struct’s members:

  • Author::id must contain a valid Uuid. Strings are parsed to Uuid. The expected format is a 128-bit value, formatted as a hex string in five groups. The first 4 groups are randomly generated, and the fifth comes from a timestamp. However, clients can freely generate this ID using other combinations as long as the length and basic format rules are honored.
  • Author::name and Author::surname shall have a minimum length of 2 and a maximum of 40 characters. These fields are allowed to repeat in the DB. Authors are identified in the DB by Author::id. Usernames are not required.
  • Author::email is validated against the HTML5 regex.
  • Author::description can’t exceed 255 characters length.
  • Author::website must contain an url format (http://... or https://...).

Authors are given the choice to share or keep private their profiles. Activate Author::shareable to allow sharing the author’s profile to the main public. Private profiles are protected from non privileged clients of the API (with no API access token): only the Author::id and Author::name is given when a unprivileged client requests the data of an author to the API.

The constructor Author::default is given to generate a new author entry using a random funny name.

Prefer AuthorBuilder rather than Author::new to build a new Author instance.

Fields§

§shareable: Option<bool>

Decide whether an author profile can be shared to the public or not.

Implementations§

Source§

impl Author

Source

pub fn new( id: Option<String>, name: Option<String>, surname: Option<String>, email: Option<String>, shareable: Option<bool>, description: Option<String>, website: Option<String>, social_profiles: Option<&[SocialProfile]>, ) -> Result<Self, DataDomainError>

Constructor of the Author struct.

§Descriptor

All fields are optional

Source

pub fn id(&self) -> Option<String>

Source

pub fn name(&self) -> Option<&str>

Source

pub fn surname(&self) -> Option<&str>

Source

pub fn email(&self) -> Option<&str>

Source

pub fn shareable(&self) -> bool

Source

pub fn description(&self) -> Option<&str>

Source

pub fn website(&self) -> Option<&str>

Source

pub fn social_profiles(&self) -> Option<&[SocialProfile]>

Source

pub fn mute_private_data(&mut self)

Source

pub fn enable_sharing(&mut self)

Source

pub fn disable_sharing(&mut self)

Source

pub fn update_from(&mut self, update: &Author)

Update the internal attributes using another Author object.

§Description

This method takes as reference another Author object, and replaces the internal values, which are also present in the given reference, using the values from the reference. This method is meant to implement a PATCH logic.

Trait Implementations§

Source§

impl Clone for Author

Source§

fn clone(&self) -> Author

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Author

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Author

Source§

fn default() -> Self

Default constructor for Author.

§Description

This constructor builds a new Author whose name is randomly generated using funny names and adjectives.

Source§

impl<'de> Deserialize<'de> for Author

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl IntoParams for Author

Source§

fn into_params( parameter_in_provider: impl Fn() -> Option<ParameterIn>, ) -> Vec<Parameter>

Provide Vec of [openapi::path::Parameter]s to caller. The result is used in utoipa-gen library to provide OpenAPI parameter information for the endpoint using the parameters.
Source§

impl PartialEq for Author

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Author

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'__s> ToSchema<'__s> for Author

Source§

fn schema() -> (&'__s str, RefOr<Schema>)

Return a tuple of name and schema or reference to a schema that can be referenced by the name or inlined directly to responses, request bodies or parameters.
§

fn aliases() -> Vec<(&'__s str, Schema)>

Optional set of alias schemas for the [ToSchema::schema]. Read more
Source§

impl Validate for Author

Source§

fn validate(&self) -> Result<(), ValidationErrors>

Source§

impl<'v_a> ValidateArgs<'v_a> for Author

Source§

type Args = ()

Source§

fn validate_args(&self, args: Self::Args) -> Result<(), ValidationErrors>

Auto Trait Implementations§

§

impl Freeze for Author

§

impl RefUnwindSafe for Author

§

impl Send for Author

§

impl Sync for Author

§

impl Unpin for Author

§

impl UnwindSafe for Author

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,