@@ -53,35 +53,44 @@ func HandleAppDetailsEdits(dockerClient *dockerClient.Client, bricksIndex *brick
5353 render .EncodeResponse (w , http .StatusPreconditionFailed , models.ErrorResponse {Details : "invalid id" })
5454 return
5555 }
56- if id .IsExample () {
57- render .EncodeResponse (w , http .StatusBadRequest , models.ErrorResponse {Details : "cannot patch the example" })
58- return
59- }
60-
6156 app , err := app .Load (id .ToPath ().String ())
6257 if err != nil {
6358 slog .Error ("Unable to parse the app.yaml" , slog .String ("error" , err .Error ()), slog .String ("path" , id .String ()))
6459 render .EncodeResponse (w , http .StatusInternalServerError , models.ErrorResponse {Details : "unable to find the app" })
6560 return
6661 }
6762
63+ var appEditRequest orchestrator.AppEditRequest
6864 var editRequest EditRequest
65+
6966 if err := json .NewDecoder (r .Body ).Decode (& editRequest ); err != nil {
7067 slog .Error ("Unable to decode the request body" , slog .String ("error" , err .Error ()))
7168 render .EncodeResponse (w , http .StatusBadRequest , models.ErrorResponse {Details : "invalid request" })
7269 return
7370 }
74- err = orchestrator .EditApp (orchestrator.AppEditRequest {
75- Default : editRequest .Default ,
76- Name : editRequest .Name ,
77- Icon : editRequest .Icon ,
78- Description : editRequest .Description ,
79- }, & app )
71+ if id .IsExample () {
72+ if editRequest .Description != nil || editRequest .Icon != nil || editRequest .Name != nil {
73+ render .EncodeResponse (w , http .StatusBadRequest , models.ErrorResponse {Details : "you can patch just the default field for example apps" })
74+ return
75+ }
76+ appEditRequest = orchestrator.AppEditRequest {
77+ Default : editRequest .Default ,
78+ }
79+ } else {
80+ appEditRequest = orchestrator.AppEditRequest {
81+ Default : editRequest .Default ,
82+ Name : editRequest .Name ,
83+ Icon : editRequest .Icon ,
84+ Description : editRequest .Description ,
85+ }
86+ }
87+ err = orchestrator .EditApp (appEditRequest , & app )
8088 if err != nil {
8189 slog .Error ("Unable to edit the app" , slog .String ("error" , err .Error ()))
8290 render .EncodeResponse (w , http .StatusInternalServerError , models.ErrorResponse {Details : "unable to edit the app" })
8391 return
8492 }
93+
8594 res , err := orchestrator .AppDetails (r .Context (), dockerClient , app , bricksIndex )
8695 if err != nil {
8796 slog .Error ("Unable to parse the app.yaml" , slog .String ("error" , err .Error ()))
0 commit comments