mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 00:55:25 +00:00
* feat(labrinth): initial preferences structure * feat(labrinth): use partially to derive partial structs * feat(labrinth): preference defaults * fix(labrinth): derive debug * feat(labrinth): user preferences db setup * feat(labrinth): user preferences routes * fix(labrinth): nested partial structs * fix(labrinth): serialize enums as snake case * refactor(labrinth-derive): rename to component-derive * feat(component-derive): nested components * refactor(component-derive): change suffixes to prefixes * refactor(component-derive): rename edit to partial * feat(component-derive): skip serializing empty option * refactor(labrinth): wrap errors * feat(component-derive): diff function * style(labrinth): fmt * refactor(labrinth): use component derive and only store overrides * chore: update query cache * docs(labrinth): add preferences to openapi * fix(labrinth): lock row for update * remove: partially * refactor(component-derive): split impls to separate functions * feat(component-derive): wrap impls to isolate naming * refactor(labrinth): split out auth conditions * feat(labrinth): store auto * feat(labrinth): store hosting privacy * style(labrinth): cargo fmt
124 lines
2.9 KiB
Rust
124 lines
2.9 KiB
Rust
use component_derive::Component;
|
|
use serde::{Deserialize, Serialize};
|
|
use utoipa::ToSchema;
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema, Default, Component)]
|
|
pub struct UserPreferences {
|
|
#[component(nested)]
|
|
pub appearance: AppearancePreferences,
|
|
#[component(nested)]
|
|
pub localization: LocalizationPreferences,
|
|
#[component(nested)]
|
|
pub layouts: LayoutPreferences,
|
|
#[component(nested)]
|
|
pub sidebars: SidebarPreferences,
|
|
#[component(nested)]
|
|
pub social: SocialPreferences,
|
|
}
|
|
|
|
#[derive(
|
|
Debug, Serialize, Deserialize, ToSchema, Default, PartialEq, Component,
|
|
)]
|
|
pub struct AppearancePreferences {
|
|
pub auto: bool,
|
|
pub theme: Theme,
|
|
}
|
|
|
|
#[derive(
|
|
Debug, Serialize, Deserialize, ToSchema, Default, Clone, PartialEq,
|
|
)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum Theme {
|
|
Light,
|
|
#[default]
|
|
Dark,
|
|
Oled,
|
|
Retro,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Component)]
|
|
pub struct LocalizationPreferences {
|
|
pub locale: String,
|
|
}
|
|
|
|
impl Default for LocalizationPreferences {
|
|
fn default() -> Self {
|
|
Self {
|
|
locale: "en-US".to_owned(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Component)]
|
|
pub struct LayoutPreferences {
|
|
pub mods: LayoutOption,
|
|
pub plugins: LayoutOption,
|
|
pub datapacks: LayoutOption,
|
|
pub shaders: LayoutOption,
|
|
pub resourcepacks: LayoutOption,
|
|
pub modpacks: LayoutOption,
|
|
pub servers: LayoutOption,
|
|
pub users: LayoutOption,
|
|
}
|
|
|
|
impl Default for LayoutPreferences {
|
|
fn default() -> Self {
|
|
Self {
|
|
mods: LayoutOption::Rows,
|
|
plugins: LayoutOption::Rows,
|
|
datapacks: LayoutOption::Rows,
|
|
shaders: LayoutOption::Grid,
|
|
resourcepacks: LayoutOption::Grid,
|
|
modpacks: LayoutOption::Rows,
|
|
servers: LayoutOption::Rows,
|
|
users: LayoutOption::Rows,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone, PartialEq)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum LayoutOption {
|
|
Grid,
|
|
Rows,
|
|
}
|
|
|
|
#[derive(
|
|
Debug, Serialize, Deserialize, ToSchema, Default, PartialEq, Component,
|
|
)]
|
|
pub struct SidebarPreferences {
|
|
pub right_aligned_search: bool,
|
|
pub left_aligned_content: bool,
|
|
}
|
|
|
|
#[derive(
|
|
Debug, Serialize, Deserialize, ToSchema, Default, PartialEq, Component,
|
|
)]
|
|
pub struct SocialPreferences {
|
|
pub friend_privacy: FriendPrivacy,
|
|
pub shared_instances_privacy: InvitePrivacy,
|
|
pub hosting_access_privacy: InvitePrivacy,
|
|
}
|
|
|
|
#[derive(
|
|
Debug, Serialize, Deserialize, ToSchema, Default, Clone, PartialEq,
|
|
)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum FriendPrivacy {
|
|
None,
|
|
Mutual,
|
|
#[default]
|
|
Everyone,
|
|
}
|
|
|
|
#[derive(
|
|
Debug, Serialize, Deserialize, ToSchema, Default, Clone, PartialEq,
|
|
)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum InvitePrivacy {
|
|
None,
|
|
Friends,
|
|
#[default]
|
|
Everyone,
|
|
}
|