```ts
const cats: Cat[] = [
new Cat({ id: "1aefd497-bb47-47e3-b160-cb69c5ba0ff4", name: "Kami", age: 4 }),
];
@Path("/cats")
export class CatController {
@Get
@Path("/")
public list(): Cat[] {
return cats;
}
@Get
@Path("/:id")
public getById(@PathVariable() id: UUID): Cat | null {
return cats.find((cat) => cat.id === id) ?? null;
}
@Post
@Path("/")
public create(@RequestBody(Cat) cat: Cat): Cat {
cat.id = randomUUID();
cats.push(cat);
return cat;
}
@Put
@Path("/:id")
public update(@PathVariable() id: UUID, @RequestBody(Cat) cat: Cat): Cat {
const index = cats.findIndex((c) => c.id === id);
if (index === -1) {
throw new NotFoundResponseError("Cat not found");
}
cats[index] = cat;
return cat;
}
@Delete
@Path("/:id")
public delete(@PathVariable() id: UUID): void {
const index = cats.findIndex((c) => c.id === id);
if (index === -1) {
throw new NotFoundResponseError("Cat not found");
}
cats.splice(index, 1);
}
}
```