@@ -14,7 +14,13 @@ use crate::state::AppState;
1414#[ derive( Debug , Serialize ) ]
1515#[ serde( rename_all = "camelCase" ) ]
1616pub struct ProjectsListResponse {
17+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
18+ pub mode : Option < String > ,
1719 pub projects : Vec < ProjectResponse > ,
20+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
21+ pub recent_projects : Option < Vec < String > > ,
22+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
23+ pub favorite_projects : Option < Vec < String > > ,
1824 pub current_project_id : Option < String > ,
1925}
2026
@@ -32,6 +38,13 @@ pub struct ProjectResponse {
3238 pub added_at : String ,
3339}
3440
41+ /// Project detail wrapper response
42+ #[ derive( Debug , Serialize ) ]
43+ #[ serde( rename_all = "camelCase" ) ]
44+ pub struct SingleProjectResponse {
45+ pub project : ProjectResponse ,
46+ }
47+
3548impl From < & Project > for ProjectResponse {
3649 fn from ( p : & Project ) -> Self {
3750 Self {
@@ -52,9 +65,19 @@ pub async fn list_projects(State(state): State<AppState>) -> Json<ProjectsListRe
5265 let registry = state. registry . read ( ) . await ;
5366 let projects: Vec < ProjectResponse > = registry. all ( ) . iter ( ) . map ( |p| ( * p) . into ( ) ) . collect ( ) ;
5467 let current_project_id = registry. current_id ( ) . map ( |s| s. to_string ( ) ) ;
68+ let mode = if projects. len ( ) > 1 {
69+ Some ( "multi-project" . to_string ( ) )
70+ } else {
71+ Some ( "single-project" . to_string ( ) )
72+ } ;
73+ let recent_projects = Some ( registry. recent ( 5 ) . iter ( ) . map ( |p| p. id . clone ( ) ) . collect ( ) ) ;
74+ let favorite_projects = Some ( registry. favorites ( ) . iter ( ) . map ( |p| p. id . clone ( ) ) . collect ( ) ) ;
5575
5676 Json ( ProjectsListResponse {
5777 projects,
78+ mode,
79+ recent_projects,
80+ favorite_projects,
5881 current_project_id,
5982 } )
6083}
@@ -88,7 +111,7 @@ pub async fn add_project(
88111pub async fn get_project (
89112 State ( state) : State < AppState > ,
90113 Path ( id) : Path < String > ,
91- ) -> ApiResult < Json < ProjectResponse > > {
114+ ) -> ApiResult < Json < SingleProjectResponse > > {
92115 let registry = state. registry . read ( ) . await ;
93116 let project = registry. get ( & id) . ok_or_else ( || {
94117 (
@@ -97,7 +120,9 @@ pub async fn get_project(
97120 )
98121 } ) ?;
99122
100- Ok ( Json ( project. into ( ) ) )
123+ Ok ( Json ( SingleProjectResponse {
124+ project : project. into ( ) ,
125+ } ) )
101126}
102127
103128/// PATCH /api/projects/:id - Update a project
0 commit comments