Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
wakeful-kitten committed Aug 10, 2023
1 parent 6a054fd commit 0ec9b7f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/app/endpoint/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
API_VERSION,
},
authz::AuthzObject,
client::{mqtt_gateway::MqttGatewayClient},
client::mqtt_gateway::MqttGatewayClient,
db::{
self,
group_agent::{GroupItem, Groups},
Expand Down
52 changes: 30 additions & 22 deletions src/app/stage/video_group/intent_event.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use chrono::Utc;
use std::sync::Arc;
use svc_agent::AgentId;
use chrono::Utc;
use svc_events::{
EventV1,
EventId,
VideoGroupCreateIntentEventV1 as VideoGroupCreateIntentEvent,
EventId, EventV1, VideoGroupCreateIntentEventV1 as VideoGroupCreateIntentEvent,
VideoGroupDeleteIntentEventV1 as VideoGroupDeleteIntentEvent,
VideoGroupUpdateIntentEventV1 as VideoGroupUpdateIntentEvent,
};
Expand All @@ -29,15 +27,19 @@ pub async fn save_create_intent(
backend_id: AgentId,
) -> Result<EventId, Error> {
let secuence_id = get_next_secuence_id(ctx.clone()).await?;
let event_id = EventId::from((ENTITY_TYPE.to_string(), CREATE_INTENT_OP.to_string(), secuence_id));
let event_id = EventId::from((
ENTITY_TYPE.to_string(),
CREATE_INTENT_OP.to_string(),
secuence_id,
));

let created_at = Utc::now().timestamp_nanos();
let event = svc_events::Event::from(
EventV1::VideoGroupCreateIntent(VideoGroupCreateIntentEvent {
let event = svc_events::Event::from(EventV1::VideoGroupCreateIntent(
VideoGroupCreateIntentEvent {
created_at,
backend_id,
})
);
},
));

nats::publish_event(ctx.clone(), room.classroom_id(), &event_id, event).await?;

Expand All @@ -50,15 +52,19 @@ pub async fn save_delete_intent(
backend_id: AgentId,
) -> Result<EventId, Error> {
let secuence_id = get_next_secuence_id(ctx.clone()).await?;
let event_id = EventId::from((ENTITY_TYPE.to_string(), DELETE_INTENT_OP.to_string(), secuence_id));
let event_id = EventId::from((
ENTITY_TYPE.to_string(),
DELETE_INTENT_OP.to_string(),
secuence_id,
));

let created_at = Utc::now().timestamp_nanos();
let event = svc_events::Event::from(
EventV1::VideoGroupDeleteIntent(VideoGroupDeleteIntentEvent {
let event = svc_events::Event::from(EventV1::VideoGroupDeleteIntent(
VideoGroupDeleteIntentEvent {
created_at,
backend_id,
})
);
},
));

nats::publish_event(ctx.clone(), room.classroom_id(), &event_id, event).await?;

Expand All @@ -71,24 +77,26 @@ pub async fn save_update_intent(
backend_id: AgentId,
) -> Result<EventId, Error> {
let secuence_id = get_next_secuence_id(ctx.clone()).await?;
let event_id = EventId::from((ENTITY_TYPE.to_string(), UPDATE_INTENT_OP.to_string(), secuence_id));
let event_id = EventId::from((
ENTITY_TYPE.to_string(),
UPDATE_INTENT_OP.to_string(),
secuence_id,
));

let created_at = Utc::now().timestamp_nanos();
let event = svc_events::Event::from(
EventV1::VideoGroupUpdateIntent(VideoGroupUpdateIntentEvent {
let event = svc_events::Event::from(EventV1::VideoGroupUpdateIntent(
VideoGroupUpdateIntentEvent {
created_at,
backend_id,
})
);
},
));

nats::publish_event(ctx.clone(), room.classroom_id(), &event_id, event).await?;

Ok(event_id)
}

async fn get_next_secuence_id(
ctx: Arc<dyn GlobalContext + Sync + Send>,
) -> Result<i64, Error> {
async fn get_next_secuence_id(ctx: Arc<dyn GlobalContext + Sync + Send>) -> Result<i64, Error> {
let mut conn = ctx.get_conn().await?;
let value = db::nats_id::get_next_seq_id(&mut conn)
.await
Expand Down

0 comments on commit 0ec9b7f

Please sign in to comment.