shared/api/endpoints/
animation.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! routes for the global animation library

use super::ApiEndpoint;
use crate::{
    api::Method,
    domain::{
        animation::{
            AnimationCreatePath, AnimationCreateRequest, AnimationDeletePath, AnimationGetPath,
            AnimationId, AnimationResponse, AnimationUploadPath, AnimationUploadRequest,
            AnimationUploadResponse,
        },
        CreateResponse,
    },
    error::EmptyError,
};

/// Get an animation by ID.
pub struct Get;
impl ApiEndpoint for Get {
    type Path = AnimationGetPath;
    type Req = ();
    type Res = AnimationResponse;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}
/// Create an animation.
pub struct Create;
impl ApiEndpoint for Create {
    type Path = AnimationCreatePath;
    type Req = AnimationCreateRequest;
    type Res = CreateResponse<AnimationId>;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Upload an animation
///
/// # Flow:
///
/// 1. User requests an upload session URI directly to Google Cloud Storage
///     a. User uploads to processing bucket
/// 2. Firestore is notified of `processing = true, ready = false` status at document `uploads/media/global/{id}`
/// 3. Animation is processed and uploaded to the final bucket
/// 4. Firestore is notified of `processing = true, ready = true` status at document `uploads/media/global/{id}`
///
/// # Notes:
///
/// * Can be used to update the raw data associated with the animation.
/// * If the client wants to re-upload an image after it has been successfully processed, it must repeat
/// the entire flow instead of uploading to the same session URI.
///
/// Errors:
/// * [`401 - Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
/// * [`403 - Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
/// * [`501 - NotImplemented`](http::StatusCode::NOT_IMPLEMENTED) when the s3/gcs service is disabled.
pub struct Upload;
impl ApiEndpoint for Upload {
    type Path = AnimationUploadPath;
    // raw bytes
    type Req = AnimationUploadRequest;
    type Res = AnimationUploadResponse;
    type Err = EmptyError;
    const METHOD: Method = Method::Put;
}

/// Delete an animation.
pub struct Delete;
impl ApiEndpoint for Delete {
    type Path = AnimationDeletePath;
    type Req = ();
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Delete;
}