SetLastSeenUpdate

This commit is contained in:
mbecker20
2023-08-08 03:52:50 -04:00
parent 2dbce8f695
commit fe1376a70c
5 changed files with 50 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ enum WriteRequest {
// ==== USER ====
PushRecentlyViewed(PushRecentlyViewed),
SetLastSeenUpdate(SetLastSeenUpdate),
// ==== PERMISSIONS ====
UpdateUserPerimissions(UpdateUserPermissions),

View File

@@ -2,7 +2,13 @@ use std::collections::VecDeque;
use anyhow::Context;
use async_trait::async_trait;
use monitor_types::requests::write::{PushRecentlyViewed, PushRecentlyViewedResponse};
use monitor_types::{
monitor_timestamp,
requests::write::{
PushRecentlyViewed, PushRecentlyViewedResponse, SetLastSeenUpdate,
SetLastSeenUpdateResponse,
},
};
use mungos::mongodb::bson::{doc, to_bson};
use resolver_api::Resolve;
@@ -49,3 +55,24 @@ impl Resolve<PushRecentlyViewed, RequestUser> for State {
Ok(PushRecentlyViewedResponse {})
}
}
#[async_trait]
impl Resolve<SetLastSeenUpdate, RequestUser> for State {
async fn resolve(
&self,
SetLastSeenUpdate {}: SetLastSeenUpdate,
user: RequestUser,
) -> anyhow::Result<SetLastSeenUpdateResponse> {
self.db
.users
.update_one(
&user.id,
mungos::Update::Set(doc! {
"last_update_view": monitor_timestamp()
}),
)
.await
.context("failed to update user last_update_view")?;
Ok(SetLastSeenUpdateResponse {})
}
}

View File

@@ -90,6 +90,7 @@ export type WriteResponses = {
// ==== USER ====
PushRecentlyViewed: Types.PushRecentlyViewedResponse;
SetLastSeenUpdate: Types.SetLastSeenUpdateResponse;
// ==== PERMISSIONS ====
UpdateUserPerimissions: Types.Update;

View File

@@ -1279,6 +1279,12 @@ export interface PushRecentlyViewed {
export interface PushRecentlyViewedResponse {
}
export interface SetLastSeenUpdate {
}
export interface SetLastSeenUpdateResponse {
}
export type AuthRequest =
| { type: "GetLoginOptions", params: GetLoginOptions }
| { type: "CreateLocalUser", params: CreateLocalUser }
@@ -1356,6 +1362,7 @@ export type WriteRequest =
| { type: "CreateLoginSecret", params: CreateLoginSecret }
| { type: "DeleteLoginSecret", params: DeleteLoginSecret }
| { type: "PushRecentlyViewed", params: PushRecentlyViewed }
| { type: "SetLastSeenUpdate", params: SetLastSeenUpdate }
| { type: "UpdateUserPerimissions", params: UpdateUserPermissions }
| { type: "UpdateUserPermissionsOnTarget", params: UpdateUserPermissionsOnTarget }
| { type: "UpdateDescription", params: UpdateDescription }

View File

@@ -4,6 +4,8 @@ use typeshare::typeshare;
use crate::entities::update::ResourceTarget;
//
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
#[response(PushRecentlyViewedResponse)]
@@ -14,3 +16,14 @@ pub struct PushRecentlyViewed {
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PushRecentlyViewedResponse {}
//
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
#[response(SetLastSeenUpdateResponse)]
pub struct SetLastSeenUpdate {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SetLastSeenUpdateResponse {}