Skip to content

Commit

Permalink
feat: addition to previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MendyBerger committed Mar 22, 2024
1 parent 03afd00 commit 36fb425
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 14 deletions.
62 changes: 62 additions & 0 deletions backend/api/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6773,6 +6773,68 @@
},
"query": "update global_animation_upload set uploaded_at = now(), processing_result = null where animation_id = $1"
},
"6accac3a867ccf3a5c988181e3dadc39c6b5406e8cb47160d60d3d0303382862": {
"describe": {
"columns": [
{
"name": "code!: i32",
"ordinal": 0,
"type_info": "Int4"
},
{
"name": "jig_id: JigId",
"ordinal": 1,
"type_info": "Uuid"
},
{
"name": "direction: TextDirection",
"ordinal": 2,
"type_info": "Int2"
},
{
"name": "scoring",
"ordinal": 3,
"type_info": "Bool"
},
{
"name": "drag_assist",
"ordinal": 4,
"type_info": "Bool"
},
{
"name": "name?",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "created_at: DateTime<Utc>",
"ordinal": 6,
"type_info": "Timestamptz"
},
{
"name": "expires_at: DateTime<Utc>",
"ordinal": 7,
"type_info": "Timestamptz"
}
],
"nullable": [
false,
false,
false,
false,
false,
true,
false,
false
],
"parameters": {
"Left": [
"Int4"
]
}
},
"query": "\n select code as \"code!: i32\",\n jig_id as \"jig_id: JigId\",\n direction as \"direction: TextDirection\",\n scoring,\n drag_assist,\n name as \"name?\",\n created_at as \"created_at: DateTime<Utc>\",\n expires_at as \"expires_at: DateTime<Utc>\"\n from jig_code\n where code = $1\n "
},
"6ad4df2298dcd688eb035ff09918b592e3be2dac06b5ffb13012fb166daa814b": {
"describe": {
"columns": [
Expand Down
4 changes: 2 additions & 2 deletions backend/api/src/http/endpoints/jig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ pub fn configure(cfg: &mut ServiceConfig) {
jig::codes::Update::METHOD.route().to(codes::update),
)
.route(
<jig::codes::JigCode as ApiEndpoint>::Path::PATH,
jig::codes::JigCode::METHOD.route().to(codes::get_code),
<jig::codes::GetJigCode as ApiEndpoint>::Path::PATH,
jig::codes::GetJigCode::METHOD.route().to(codes::get_code),
)
.route(
<jig::codes::JigCodeList as ApiEndpoint>::Path::PATH,
Expand Down
2 changes: 1 addition & 1 deletion backend/api/src/http/endpoints/jig/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn get_code(
db: Data<PgPool>,
claims: TokenUser,
path: web::Path<JigCode>,
) -> Result<Json<<codes::JigCode as ApiEndpoint>::Res>, error::JigCode> {
) -> Result<Json<<codes::GetJigCode as ApiEndpoint>::Res>, error::JigCode> {
let code = path.into_inner();
let user_id = claims.user_id();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use shared::{
asset::AssetType,
jig::{
codes::{
JigCodeSessionsPath, JigPlaySessionModule, JigPlaySessionModuleGetPointsEarned,
JigCodePath, JigCodeSessionsPath, JigPlaySessionModule,
JigPlaySessionModuleGetPointsEarned,
},
JigGetLivePath,
},
Expand All @@ -34,12 +35,22 @@ impl CodeSessions {
let state = self;
spawn_local(clone!(state => async move {
join!(
state.load_code(),
state.load_jig(),
state.load_report(),
);
}));
}

async fn load_code(self: &Rc<Self>) {
let code_response =
endpoints::jig::codes::GetJigCode::api_with_auth(JigCodePath(self.code), None)
.await
.toast_on_err();
let code_response = bail_on_err!(code_response);
self.code_response.set(Some(code_response));
}

async fn load_jig(self: &Rc<Self>) {
let jig = endpoints::jig::GetLive::api_with_auth(JigGetLivePath(self.jig_id.clone()), None)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use components::qr_dialog::QrDialog;
use futures_signals::signal::Mutable;
use shared::domain::{
jig::{
codes::{JigCode, JigCodeSessionResponse},
codes::{JigCode, JigCodeResponse, JigCodeSessionResponse},
JigId, JigResponse,
},
module::{ModuleResponse, StableModuleId},
};

pub struct CodeSessions {
pub(super) code: JigCode,
pub(super) code_response: Mutable<Option<JigCodeResponse>>,
pub(super) jig_id: JigId,
pub(super) jig: Mutable<Option<JigWithModules>>,
pub(super) infos: Mutable<Vec<JigCodeSessionResponse>>,
Expand All @@ -23,6 +24,7 @@ impl CodeSessions {
pub fn new(jig_id: JigId, code: JigCode) -> Rc<Self> {
Rc::new(Self {
code,
code_response: Default::default(),
jig_id,
jig: Default::default(),
infos: Default::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use futures::join;
use shared::{
api::endpoints,
domain::jig::{
codes::{
JigCode, JigCodeListPath, JigCodeListRequest, JigCodeUpdatePath, JigCodeUpdateRequest,
},
codes::{JigCode, JigCodeListPath, JigCodeListRequest, JigCodePath, JigCodeUpdateRequest},
JigGetLivePath,
},
};
Expand Down Expand Up @@ -50,10 +48,9 @@ impl JigCodes {
name: Some(Some(new_name)),
settings: None,
};
let _ =
endpoints::jig::codes::Update::api_with_auth(JigCodeUpdatePath(code), Some(req))
.await
.toast_on_err();
let _ = endpoints::jig::codes::Update::api_with_auth(JigCodePath(code), Some(req))
.await
.toast_on_err();
});
}
}
4 changes: 2 additions & 2 deletions shared/rust/src/api/endpoints/jig/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl ApiEndpoint for Update {
}

/// List codes creator by user.
pub struct JigCode;
impl ApiEndpoint for JigCode {
pub struct GetJigCode;
impl ApiEndpoint for GetJigCode {
type Path = JigCodePath;
type Req = ();
type Res = JigCodeResponse;
Expand Down

0 comments on commit 36fb425

Please sign in to comment.