feat: add domains, ideas, layouts, widgets API modules
- Add DomainsModule with full CRUD, search, and activity logging - Add IdeasModule with quick capture endpoint - Add LayoutsModule for user dashboard layouts - Add WidgetsModule for widget definitions (read-only) - Update ActivityService with domain/idea logging methods - Register all new modules in AppModule
This commit is contained in:
128
apps/api/src/layouts/layouts.controller.ts
Normal file
128
apps/api/src/layouts/layouts.controller.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Patch,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
UseGuards,
|
||||
Request,
|
||||
UnauthorizedException,
|
||||
} from "@nestjs/common";
|
||||
import { LayoutsService } from "./layouts.service";
|
||||
import { CreateLayoutDto, UpdateLayoutDto } from "./dto";
|
||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||
|
||||
/**
|
||||
* Controller for user layout endpoints
|
||||
* All endpoints require authentication
|
||||
*/
|
||||
@Controller("layouts")
|
||||
@UseGuards(AuthGuard)
|
||||
export class LayoutsController {
|
||||
constructor(private readonly layoutsService: LayoutsService) {}
|
||||
|
||||
/**
|
||||
* GET /api/layouts
|
||||
* Get all layouts for the authenticated user
|
||||
*/
|
||||
@Get()
|
||||
async findAll(@Request() req: any) {
|
||||
const workspaceId = req.user?.workspaceId;
|
||||
const userId = req.user?.id;
|
||||
|
||||
if (!workspaceId || !userId) {
|
||||
throw new UnauthorizedException("Authentication required");
|
||||
}
|
||||
|
||||
return this.layoutsService.findAll(workspaceId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/layouts/:id
|
||||
* Get a single layout by ID
|
||||
*/
|
||||
@Get(":id")
|
||||
async findOne(@Param("id") id: string, @Request() req: any) {
|
||||
const workspaceId = req.user?.workspaceId;
|
||||
const userId = req.user?.id;
|
||||
|
||||
if (!workspaceId || !userId) {
|
||||
throw new UnauthorizedException("Authentication required");
|
||||
}
|
||||
|
||||
return this.layoutsService.findOne(id, workspaceId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/layouts/default
|
||||
* Get the default layout for the authenticated user
|
||||
* Falls back to the most recently created layout if no default exists
|
||||
*/
|
||||
@Get("default")
|
||||
async findDefault(@Request() req: any) {
|
||||
const workspaceId = req.user?.workspaceId;
|
||||
const userId = req.user?.id;
|
||||
|
||||
if (!workspaceId || !userId) {
|
||||
throw new UnauthorizedException("Authentication required");
|
||||
}
|
||||
|
||||
return this.layoutsService.findDefault(workspaceId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/layouts
|
||||
* Create a new layout
|
||||
* If isDefault is true, any existing default layout will be unset
|
||||
*/
|
||||
@Post()
|
||||
async create(@Body() createLayoutDto: CreateLayoutDto, @Request() req: any) {
|
||||
const workspaceId = req.user?.workspaceId;
|
||||
const userId = req.user?.id;
|
||||
|
||||
if (!workspaceId || !userId) {
|
||||
throw new UnauthorizedException("Authentication required");
|
||||
}
|
||||
|
||||
return this.layoutsService.create(workspaceId, userId, createLayoutDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* PATCH /api/layouts/:id
|
||||
* Update a layout
|
||||
* If isDefault is set to true, any existing default layout will be unset
|
||||
*/
|
||||
@Patch(":id")
|
||||
async update(
|
||||
@Param("id") id: string,
|
||||
@Body() updateLayoutDto: UpdateLayoutDto,
|
||||
@Request() req: any
|
||||
) {
|
||||
const workspaceId = req.user?.workspaceId;
|
||||
const userId = req.user?.id;
|
||||
|
||||
if (!workspaceId || !userId) {
|
||||
throw new UnauthorizedException("Authentication required");
|
||||
}
|
||||
|
||||
return this.layoutsService.update(id, workspaceId, userId, updateLayoutDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /api/layouts/:id
|
||||
* Delete a layout
|
||||
*/
|
||||
@Delete(":id")
|
||||
async remove(@Param("id") id: string, @Request() req: any) {
|
||||
const workspaceId = req.user?.workspaceId;
|
||||
const userId = req.user?.id;
|
||||
|
||||
if (!workspaceId || !userId) {
|
||||
throw new UnauthorizedException("Authentication required");
|
||||
}
|
||||
|
||||
return this.layoutsService.remove(id, workspaceId, userId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user