satellite/admin: update geofence endpoints to follow response conventions

Change-Id: Ieff91c16f91f9720e9c3d8ead0e13c47651d23f5
This commit is contained in:
Mya 2021-12-01 09:33:41 -06:00
parent 6bbe2fc692
commit cf462fcf92
3 changed files with 19 additions and 15 deletions

View File

@ -8,6 +8,7 @@ Requires setting `Authorization` header for requests.
<!-- toc --> <!-- toc -->
- [satellite/admin](#satelliteadmin) - [satellite/admin](#satelliteadmin)
* [API design](#api-design) * [API design](#api-design)
* [Successful responses](#successful-responses)
* [Error responses](#error-responses) * [Error responses](#error-responses)
* [API Endpoints](#api-endpoints) * [API Endpoints](#api-endpoints)
* [User Management](#user-management) * [User Management](#user-management)
@ -42,6 +43,11 @@ Requires setting `Authorization` header for requests.
## API design ## API design
### Successful responses
For non-get requests (`PUT`, `POST`, `DELETE`), endpoints should return an empty response body on success. `GET`
requests can return a non-empty body for the resource that we're interacting with.
### Error responses ### Error responses
When an API endpoint returns a client error (status code 4XX) it returns a JSON error response which contains 2 fields: When an API endpoint returns a client error (status code 4XX) it returns a JSON error response which contains 2 fields:

View File

@ -74,7 +74,7 @@ func (server *Server) updateBucket(w http.ResponseWriter, r *http.Request, place
b.Placement = placement b.Placement = placement
b, err = server.buckets.UpdateBucket(ctx, b) _, err = server.buckets.UpdateBucket(ctx, b)
if err != nil { if err != nil {
switch { switch {
case storj.ErrBucketNotFound.Has(err): case storj.ErrBucketNotFound.Has(err):
@ -87,12 +87,7 @@ func (server *Server) updateBucket(w http.ResponseWriter, r *http.Request, place
return return
} }
data, err := json.Marshal(b) w.WriteHeader(http.StatusOK)
if err != nil {
sendJSONError(w, "failed to marshal bucket", err.Error(), http.StatusInternalServerError)
} else {
sendJSONData(w, http.StatusOK, data)
}
} }
func (server *Server) createGeofenceForBucket(w http.ResponseWriter, r *http.Request) { func (server *Server) createGeofenceForBucket(w http.ResponseWriter, r *http.Request) {

View File

@ -49,8 +49,11 @@ export class Admin {
['Project ID', new InputText('text', true)], ['Project ID', new InputText('text', true)],
['Bucket name', new InputText('text', true)] ['Bucket name', new InputText('text', true)]
], ],
func: async (projectId: string, bucketName: string): Promise<Record<string, unknown>> => { func: async (projectId: string, bucketName: string): Promise<null> => {
return this.fetch('DELETE', `projects/${projectId}/buckets/${bucketName}/geofence`); return this.fetch(
'DELETE',
`projects/${projectId}/buckets/${bucketName}/geofence`
) as Promise<null>;
} }
}, },
{ {
@ -69,17 +72,17 @@ export class Admin {
]) ])
] ]
], ],
func: async ( func: async (projectId: string, bucketName: string, region: string): Promise<null> => {
projectId: string,
bucketName: string,
region: string
): Promise<Record<string, unknown>> => {
const query = this.urlQueryFromObject({ region }); const query = this.urlQueryFromObject({ region });
if (query === '') { if (query === '') {
throw new APIError('region cannot be empty'); throw new APIError('region cannot be empty');
} }
return this.fetch('POST', `projects/${projectId}/buckets/${bucketName}/geofence`, query); return this.fetch(
'POST',
`projects/${projectId}/buckets/${bucketName}/geofence`,
query
) as Promise<null>;
} }
} }
], ],