mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
chore: re-order backend file structure
This commit is contained in:
50
apps/server/src/modules/volumes/volume.controller.ts
Normal file
50
apps/server/src/modules/volumes/volume.controller.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Hono } from "hono";
|
||||
import { validator } from "hono-openapi/arktype";
|
||||
import { handleServiceError } from "../../utils/errors";
|
||||
import {
|
||||
createVolumeBody,
|
||||
createVolumeDto,
|
||||
type ListVolumesResponseDto,
|
||||
listVolumesDto,
|
||||
} from "./volume.dto";
|
||||
import { volumeService } from "./volume.service";
|
||||
|
||||
export const volumeController = new Hono()
|
||||
.get("/", listVolumesDto, async (c) => {
|
||||
const volumes = await volumeService.listVolumes();
|
||||
|
||||
const response = {
|
||||
volumes: volumes.map((volume) => ({
|
||||
name: volume.name,
|
||||
mountpoint: volume.path,
|
||||
createdAt: volume.createdAt,
|
||||
})),
|
||||
} satisfies ListVolumesResponseDto;
|
||||
|
||||
return c.json(response, 200);
|
||||
})
|
||||
.post(
|
||||
"/",
|
||||
createVolumeDto,
|
||||
validator("json", createVolumeBody),
|
||||
async (c) => {
|
||||
const body = c.req.valid("json");
|
||||
const res = await volumeService.createVolume(body.name, body.config);
|
||||
|
||||
if (res.error) {
|
||||
const { message, status } = handleServiceError(res.error);
|
||||
return c.json(message, status);
|
||||
}
|
||||
|
||||
return c.json({ message: "Volume created", volume: res.volume });
|
||||
},
|
||||
)
|
||||
.get("/:name", (c) => {
|
||||
return c.json({ message: `Details of volume ${c.req.param("name")}` });
|
||||
})
|
||||
.put("/:name", (c) => {
|
||||
return c.json({ message: `Update volume ${c.req.param("name")}` });
|
||||
})
|
||||
.delete("/:name", (c) => {
|
||||
return c.json({ message: `Delete volume ${c.req.param("name")}` });
|
||||
});
|
||||
Reference in New Issue
Block a user