pib-service-inventory 0.13.1

Inventory interface library to be used in pib-service
Documentation
// SPDX-FileCopyrightText: Politik im Blick developers
// SPDX-FileCopyrightText: Wolfgang Silbermayr <wolfgang@silbermayr.at>
//
// SPDX-License-Identifier: AGPL-3.0-or-later OR EUPL-1.2

use uuid::Uuid;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct User {
    pub id: Uuid,
    pub sub: String,
    pub display_name: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NewUser {
    pub sub: String,
    pub display_name: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UpdateUser {
    pub id: Uuid,
    pub sub: Option<String>,
    pub display_name: Option<Option<String>>,
}

impl UpdateUser {
    pub fn new(id: Uuid) -> Self {
        Self {
            id,
            sub: None,
            display_name: None,
        }
    }

    // The naming collides with the `sub` function which is short for subtraction.
    // In the authentication domain, `sub` is a well-established and specificed
    // name for "subject", so we want to provide it under that name.
    #[allow(clippy::should_implement_trait)]
    pub fn sub(self, sub: String) -> Self {
        Self {
            sub: Some(sub),
            ..self
        }
    }

    pub fn display_name(self, display_name: String) -> Self {
        Self {
            display_name: Some(Some(display_name)),
            ..self
        }
    }
}