feat: separate service image endpoint
This commit is contained in:
parent
6c70966a21
commit
aa8dcdaf86
1 changed files with 18 additions and 1 deletions
|
|
@ -59,14 +59,15 @@ function imageLocation(id: string) {
|
|||
|
||||
@Route("api/v1/service")
|
||||
@Tags("Service")
|
||||
@Security("keycloak")
|
||||
export class ServiceController extends Controller {
|
||||
@Get("stats")
|
||||
@Security("keycloak")
|
||||
async getServiceStats() {
|
||||
return await prisma.service.count();
|
||||
}
|
||||
|
||||
@Get()
|
||||
@Security("keycloak")
|
||||
async getService(
|
||||
@Query() query: string = "",
|
||||
@Query() page: number = 1,
|
||||
|
|
@ -107,6 +108,7 @@ export class ServiceController extends Controller {
|
|||
}
|
||||
|
||||
@Get("{serviceId}")
|
||||
@Security("keycloak")
|
||||
async getServiceById(@Path() serviceId: string) {
|
||||
const record = await prisma.service.findFirst({
|
||||
include: {
|
||||
|
|
@ -133,6 +135,7 @@ export class ServiceController extends Controller {
|
|||
}
|
||||
|
||||
@Get("{serviceId}/work")
|
||||
@Security("keycloak")
|
||||
async getWorkOfService(
|
||||
@Path() serviceId: string,
|
||||
@Query() page: number = 1,
|
||||
|
|
@ -161,7 +164,19 @@ export class ServiceController extends Controller {
|
|||
return { result, page, pageSize, total };
|
||||
}
|
||||
|
||||
@Get("{serviceId}/image")
|
||||
async getServiceImageById(@Request() req: RequestWithUser, @Path() serviceId: string) {
|
||||
const url = await presignedGetObjectIfExist(MINIO_BUCKET, imageLocation(serviceId), 60 * 60);
|
||||
|
||||
if (!url) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Image cannot be found", "imageNotFound");
|
||||
}
|
||||
|
||||
return req.res?.redirect(url);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Security("keycloak")
|
||||
async createService(@Request() req: RequestWithUser, @Body() body: ServiceCreate) {
|
||||
const { work, ...payload } = body;
|
||||
|
||||
|
|
@ -239,6 +254,7 @@ export class ServiceController extends Controller {
|
|||
}
|
||||
|
||||
@Put("{serviceId}")
|
||||
@Security("keycloak")
|
||||
async editService(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: ServiceUpdate,
|
||||
|
|
@ -297,6 +313,7 @@ export class ServiceController extends Controller {
|
|||
}
|
||||
|
||||
@Delete("{serviceId}")
|
||||
@Security("keycloak")
|
||||
async deleteService(@Path() serviceId: string) {
|
||||
const record = await prisma.service.findFirst({ where: { id: serviceId } });
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue