2021-04-25 11:31:52 +02:00
|
|
|
use diesel::prelude::*;
|
2023-03-31 23:25:20 +02:00
|
|
|
use bitque_data::{TextEditorMode, UserId, UserSetting};
|
2021-04-25 11:31:52 +02:00
|
|
|
|
|
|
|
use crate::{db_find, db_update};
|
|
|
|
|
|
|
|
db_find! {
|
|
|
|
FindUserSetting,
|
|
|
|
msg => user_settings => user_settings
|
|
|
|
.distinct_on(id)
|
|
|
|
.filter(user_id.eq(msg.user_id))
|
|
|
|
.limit(1),
|
|
|
|
UserSetting,
|
|
|
|
user_id => UserId
|
|
|
|
}
|
|
|
|
|
|
|
|
db_update! {
|
|
|
|
UpdateUserSetting,
|
|
|
|
msg => conn => user_settings => {
|
|
|
|
inner::Update { user_id: msg.user_id, mode: msg.mode }
|
|
|
|
.execute(conn).or_else(|_|
|
|
|
|
inner::Create { user_id: msg.user_id, mode: msg.mode }
|
|
|
|
.execute(conn)
|
|
|
|
)?;
|
|
|
|
user_settings.filter(user_id.eq(msg.user_id))
|
|
|
|
},
|
|
|
|
UserSetting,
|
|
|
|
user_id => UserId,
|
|
|
|
mode => TextEditorMode
|
|
|
|
}
|
|
|
|
|
|
|
|
mod inner {
|
|
|
|
use diesel::prelude::*;
|
2023-03-31 23:25:20 +02:00
|
|
|
use bitque_data::{TextEditorMode, UserId, UserSetting};
|
2021-04-25 11:31:52 +02:00
|
|
|
|
|
|
|
use crate::{db_create, db_update};
|
|
|
|
|
|
|
|
db_update! {
|
|
|
|
Update,
|
|
|
|
msg => user_settings => {
|
|
|
|
diesel::update(user_settings.filter(user_id.eq(msg.user_id))).set(text_editor_mode.eq(msg.mode))
|
|
|
|
},
|
|
|
|
UserSetting,
|
|
|
|
user_id => UserId,
|
|
|
|
mode => TextEditorMode
|
|
|
|
}
|
|
|
|
|
|
|
|
db_create! {
|
|
|
|
Create,
|
|
|
|
msg => user_settings => diesel::insert_into(user_settings).values((
|
|
|
|
user_id.eq(msg.user_id),
|
|
|
|
text_editor_mode.eq(msg.mode)
|
|
|
|
)),
|
|
|
|
UserSetting,
|
|
|
|
user_id => UserId,
|
|
|
|
mode => TextEditorMode
|
|
|
|
}
|
|
|
|
}
|