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")
|
@Route("api/v1/service")
|
||||||
@Tags("Service")
|
@Tags("Service")
|
||||||
@Security("keycloak")
|
|
||||||
export class ServiceController extends Controller {
|
export class ServiceController extends Controller {
|
||||||
@Get("stats")
|
@Get("stats")
|
||||||
|
@Security("keycloak")
|
||||||
async getServiceStats() {
|
async getServiceStats() {
|
||||||
return await prisma.service.count();
|
return await prisma.service.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
@Security("keycloak")
|
||||||
async getService(
|
async getService(
|
||||||
@Query() query: string = "",
|
@Query() query: string = "",
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
|
|
@ -107,6 +108,7 @@ export class ServiceController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("{serviceId}")
|
@Get("{serviceId}")
|
||||||
|
@Security("keycloak")
|
||||||
async getServiceById(@Path() serviceId: string) {
|
async getServiceById(@Path() serviceId: string) {
|
||||||
const record = await prisma.service.findFirst({
|
const record = await prisma.service.findFirst({
|
||||||
include: {
|
include: {
|
||||||
|
|
@ -133,6 +135,7 @@ export class ServiceController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("{serviceId}/work")
|
@Get("{serviceId}/work")
|
||||||
|
@Security("keycloak")
|
||||||
async getWorkOfService(
|
async getWorkOfService(
|
||||||
@Path() serviceId: string,
|
@Path() serviceId: string,
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
|
|
@ -161,7 +164,19 @@ export class ServiceController extends Controller {
|
||||||
return { result, page, pageSize, total };
|
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()
|
@Post()
|
||||||
|
@Security("keycloak")
|
||||||
async createService(@Request() req: RequestWithUser, @Body() body: ServiceCreate) {
|
async createService(@Request() req: RequestWithUser, @Body() body: ServiceCreate) {
|
||||||
const { work, ...payload } = body;
|
const { work, ...payload } = body;
|
||||||
|
|
||||||
|
|
@ -239,6 +254,7 @@ export class ServiceController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("{serviceId}")
|
@Put("{serviceId}")
|
||||||
|
@Security("keycloak")
|
||||||
async editService(
|
async editService(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Body() body: ServiceUpdate,
|
@Body() body: ServiceUpdate,
|
||||||
|
|
@ -297,6 +313,7 @@ export class ServiceController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("{serviceId}")
|
@Delete("{serviceId}")
|
||||||
|
@Security("keycloak")
|
||||||
async deleteService(@Path() serviceId: string) {
|
async deleteService(@Path() serviceId: string) {
|
||||||
const record = await prisma.service.findFirst({ where: { id: serviceId } });
|
const record = await prisma.service.findFirst({ where: { id: serviceId } });
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue