-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import "@typespec/http"; | ||
import "../../models/errors.tsp"; | ||
import "../types/id.tsp"; | ||
|
||
using TypeSpec.Http; | ||
|
||
interface GeneralCRUD<T> { | ||
@post | ||
create( | ||
@header | ||
contentType: "application/json", | ||
|
||
@body body: { | ||
value: T; | ||
}, | ||
): { | ||
@statusCode statusCode: 201; | ||
@header Location: string; | ||
} | { | ||
@statusCode statusCode: 400 | 401 | 403 | 500; | ||
@body body: Error; | ||
}; | ||
|
||
@get | ||
get( | ||
@header | ||
contentType: "application/json", | ||
|
||
@body body: { | ||
id: ID<T>; | ||
}, | ||
): { | ||
@statusCode statusCode: 200; | ||
@body body: T; | ||
} | { | ||
@statusCode statusCode: 400 | 401 | 403 | 404 | 500; | ||
@body body: Error; | ||
}; | ||
|
||
@get | ||
list(): { | ||
@statusCode statusCode: 200; | ||
@body body: T[]; | ||
} | { | ||
@statusCode statusCode: 400 | 401 | 403 | 500; | ||
@body body: Error; | ||
}; | ||
|
||
@patch | ||
update( | ||
@header | ||
contentType: "application/json", | ||
|
||
@body body: T, | ||
): { | ||
@statusCode statusCode: 200; | ||
@body body: T; | ||
} | { | ||
@statusCode statusCode: 400 | 401 | 403 | 404 | 500; | ||
@body body: Error; | ||
}; | ||
|
||
@delete | ||
delete( | ||
@header | ||
contentType: "application/json", | ||
|
||
@body body: ID<T>, | ||
): { | ||
@statusCode statusCode: 204; | ||
} | { | ||
@statusCode statusCode: 400 | 401 | 403 | 500; | ||
@body body: Error; | ||
}; | ||
} |