@@ -3,11 +3,15 @@ use std::sync::Arc;
3
3
4
4
use async_trait:: async_trait;
5
5
6
- use flow_websocket_domain:: project:: { Project , ProjectEditingSession } ;
7
- use flow_websocket_domain:: repository:: { ProjectRepository , ProjectEditingSessionRepository } ;
8
-
6
+ use crate :: persistence:: gcs:: gcs_client:: GcsClient ;
9
7
use crate :: persistence:: redis:: redis_client:: RedisClient ;
10
8
9
+ use flow_websocket_domain:: project:: { Project , ProjectEditingSession } ;
10
+ use flow_websocket_domain:: repository:: {
11
+ ProjectEditingSessionRepository , ProjectRepository , ProjectSnapshotRepository ,
12
+ } ;
13
+ use flow_websocket_domain:: snapshot:: ProjectSnapshot ;
14
+
11
15
pub struct ProjectRedisRepository {
12
16
redis_client : Arc < RedisClient > ,
13
17
}
@@ -34,7 +38,10 @@ impl ProjectEditingSessionRepository for ProjectRedisRepository {
34
38
Ok ( ( ) )
35
39
}
36
40
37
- async fn get_active_session ( & self , project_id : & str ) -> Result < Option < ProjectEditingSession > , Box < dyn Error > > {
41
+ async fn get_active_session (
42
+ & self ,
43
+ project_id : & str ,
44
+ ) -> Result < Option < ProjectEditingSession > , Box < dyn Error > > {
38
45
let key = format ! ( "project:{}:active_session" , project_id) ;
39
46
self . redis_client . get ( & key) . await
40
47
}
@@ -45,3 +52,40 @@ impl ProjectEditingSessionRepository for ProjectRedisRepository {
45
52
Ok ( ( ) )
46
53
}
47
54
}
55
+
56
+ /// A `ProjectGcsRepository` is a thin wrapper of `GcsClient`.
57
+ pub struct ProjectGcsRepository {
58
+ client : GcsClient ,
59
+ }
60
+
61
+ impl ProjectGcsRepository {
62
+ /// Returns the `ProjectGcsRepository`.
63
+ fn new ( client : GcsClient ) -> Self {
64
+ Self { client }
65
+ }
66
+ }
67
+
68
+ #[ async_trait]
69
+ impl ProjectSnapshotRepository for ProjectGcsRepository {
70
+ /// Create a snapshot.
71
+ async fn create_snapshot ( & self , snapshot : ProjectSnapshot ) -> Result < ( ) , Box < dyn Error > > {
72
+ let path = format ! ( "snapshot/{}" , snapshot. id) ;
73
+ self . client . upload ( path, & snapshot) . await ?;
74
+ Ok ( ( ) )
75
+ }
76
+
77
+ /// Get the latest snapshot.
78
+ async fn get_latest_snapshot (
79
+ & self ,
80
+ project_id : & str ,
81
+ ) -> Result < Option < ProjectSnapshot > , Box < dyn Error > > {
82
+ let path = format ! ( "snapshot/{}:latest_snapshot" , project_id) ;
83
+ self . client . download ( path) . await
84
+ }
85
+
86
+ /// Get the state of the latest snapshot.
87
+ async fn get_latest_snapshot_state ( & self , project_id : & str ) -> Result < Vec < u8 > , Box < dyn Error > > {
88
+ let path = format ! ( "snapshot/{}:latest_snapshot_state" , project_id) ;
89
+ self . client . download ( path) . await
90
+ }
91
+ }
0 commit comments