-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update editor api's, and generate static types for all
- Loading branch information
1 parent
1280ad1
commit 5f20d40
Showing
30 changed files
with
618 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ContentMgmtController } from './content_mgmt.controller'; | ||
import { ContentMgmtService } from './content_mgmt.service'; | ||
import { PrismaModule } from 'libs/prisma/prisma.module'; | ||
import { EditorModule } from './editor/editor.module'; | ||
import { EditorService } from './editor/editor.service'; | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [ContentMgmtController], | ||
providers: [ContentMgmtService], | ||
imports: [PrismaModule], | ||
controllers: [ContentMgmtController, EditorModule], | ||
providers: [ContentMgmtService, EditorService], | ||
}) | ||
export class ContentMgmtModule {} |
70 changes: 70 additions & 0 deletions
70
apps/backend/apps/content_mgmt/src/editor/editor.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Param, | ||
Patch, | ||
Delete, | ||
} from '@nestjs/common'; | ||
import { EditorService } from './editor.service'; | ||
import { | ||
CreateBlockDto, | ||
CreateNoteDto, | ||
UpdateBlockDto, | ||
UpdateNoteDto, | ||
} from 'libs/types'; | ||
|
||
@Controller('editor') | ||
export class EditorController { | ||
constructor(private readonly editorService: EditorService) {} | ||
|
||
// POST /api/documents - Create a new document | ||
@Post('note/new') | ||
createDocument(@Body() createDocumentDto: CreateNoteDto) { | ||
return this.editorService.createDocument(createDocumentDto); | ||
} | ||
|
||
// GET /api/documents/:id - Retrieve a document | ||
@Get('note/:id') | ||
getDocument(@Param('id') id: string) { | ||
return this.editorService.getDocument(id); | ||
} | ||
|
||
// PATCH /api/documents/:id - Update a document | ||
@Patch('note/:id') | ||
updateDocument( | ||
@Param('id') id: string, | ||
@Body() updateDocumentDto: UpdateNoteDto, | ||
) { | ||
return this.editorService.updateDocument(id, updateDocumentDto); | ||
} | ||
|
||
// DELETE /api/documents/:id - Delete a document | ||
@Delete('note/:id') | ||
deleteDocument(@Param('id') id: string) { | ||
return this.editorService.deleteDocument(id); | ||
} | ||
|
||
// POST /api/documents/:id/blocks - Add a new block to a document | ||
@Post('note/:id/block/new') | ||
addBlock(@Param('id') id: string, @Body() createBlockDto: CreateBlockDto) { | ||
return this.editorService.addBlock(id, createBlockDto); | ||
} | ||
|
||
// PATCH /api/documents/:id/blocks/:blockId - Update a block | ||
@Patch('note/:id/block/:blockId') | ||
updateBlock( | ||
@Param('id') id: string, | ||
@Param('blockId') blockId: string, | ||
@Body() updateBlockDto: UpdateBlockDto, | ||
) { | ||
return this.editorService.updateBlock(id, blockId, updateBlockDto); | ||
} | ||
|
||
// DELETE /api/documents/:id/blocks/:blockId - Delete a block | ||
@Delete('note/:id/block/:blockId') | ||
deleteBlock(@Param('id') id: string, @Param('blockId') blockId: string) { | ||
return this.editorService.deleteBlock(id, blockId); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/backend/apps/content_mgmt/src/editor/editor.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { EditorController } from './editor.controller'; | ||
import { PrismaService } from 'libs/prisma/prisma.service'; | ||
import { EditorService } from './editor.service'; | ||
|
||
@Module({ | ||
controllers: [EditorController], | ||
providers: [EditorService, PrismaService], | ||
}) | ||
export class EditorModule {} |
99 changes: 99 additions & 0 deletions
99
apps/backend/apps/content_mgmt/src/editor/editor.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { PrismaService } from 'libs/prisma/prisma.service'; | ||
import { | ||
CreateBlockDto, | ||
CreateNoteDto, | ||
UpdateBlockDto, | ||
UpdateNoteDto, | ||
} from 'libs/types'; | ||
|
||
@Injectable() | ||
export class EditorService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async createDocument(createDocumentDto: CreateNoteDto) { | ||
return `TODO ${createDocumentDto}`; | ||
// return this.prisma.note.create({ | ||
// data: { | ||
// title: createDocumentDto.title, | ||
// blocks: { | ||
// create: createDocumentDto.blocks, | ||
// }, | ||
// }, | ||
// }); | ||
} | ||
|
||
async getDocument(id: string) { | ||
const document = await this.prisma.note.findUnique({ | ||
where: { id }, | ||
include: { blocks: true }, | ||
}); | ||
if (!document) { | ||
throw new NotFoundException(`Document with ID "${id}" not found`); | ||
} | ||
return document; | ||
} | ||
|
||
async updateDocument(id: string, DocumentDto: UpdateNoteDto) { | ||
const document = await this.getDocument(id); | ||
return `TODO ${document} ${DocumentDto}`; | ||
// return this.prisma.note.update({ | ||
// where: { id }, | ||
// data: { | ||
// title: DocumentDto.title ?? document.title, | ||
// blocks: { | ||
// update: DocumentDto.blocks, | ||
// }, | ||
// }, | ||
// }); | ||
} | ||
|
||
async deleteDocument(id: string) { | ||
const result = await this.prisma.note.delete({ | ||
where: { id }, | ||
}); | ||
if (!result) { | ||
throw new NotFoundException(`Document with ID "${id}" not found`); | ||
} | ||
} | ||
|
||
async addBlock(id: string, createBlockDto: CreateBlockDto) { | ||
return `TODO ${id} ${createBlockDto}`; | ||
// return this.prisma.block.create({ | ||
// data: { | ||
// ...createBlockDto, | ||
// id: id, | ||
// }, | ||
// }); | ||
} | ||
|
||
async updateBlock( | ||
id: string, | ||
blockId: string, | ||
updateBlockDto: UpdateBlockDto, | ||
) { | ||
const document = await this.getDocument(id); | ||
const block = document.blocks.find((b) => b.id === blockId); | ||
if (!block) { | ||
throw new NotFoundException( | ||
`Block with ID "${blockId}" not found in document "${id}"`, | ||
); | ||
} | ||
// return this.prisma.block.update({ | ||
// where: { id: blockId }, | ||
// data: updateBlockDto, | ||
// }); | ||
return `TODO ${updateBlockDto}`; | ||
} | ||
|
||
async deleteBlock(id: string, blockId: string) { | ||
const document = await this.getDocument(id); | ||
const block = document.blocks.find((b) => b.id === blockId); | ||
if (!block) { | ||
throw new NotFoundException( | ||
`Block with ID "${blockId}" not found in document "${id}"`, | ||
); | ||
} | ||
await this.prisma.block.delete({ where: { id: blockId } }); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum BlockTypeEnum { | ||
TEXT = 'TEXT', | ||
IMAGE = 'IMAGE', | ||
LINK = 'LINK', | ||
INTERNAL_LINK = 'INTERNAL_LINK', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { IsDate, IsEnum, IsNotEmpty, IsString } from 'class-validator'; | ||
import { BlockTypeEnum } from './block-type.enum'; | ||
|
||
export class BlockDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
id: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
noteId: string; | ||
|
||
@IsEnum(BlockTypeEnum) | ||
@IsNotEmpty() | ||
type: BlockTypeEnum; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
content: string; | ||
|
||
@IsDate() | ||
createdAt: Date; | ||
|
||
@IsDate() | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { IsDate, IsNotEmpty, IsString, ValidateNested } from 'class-validator'; | ||
import { Type } from 'class-transformer'; | ||
import { SectionDto } from './section.dto'; | ||
|
||
export class BookDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
id: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
title: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
userId: string; | ||
|
||
@ValidateNested({ each: true }) | ||
@Type(() => SectionDto) | ||
sections: SectionDto[]; | ||
|
||
@IsDate() | ||
createdAt: Date; | ||
|
||
@IsDate() | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IsEnum, IsNotEmpty, IsString } from 'class-validator'; | ||
import { BlockTypeEnum } from './block-type.enum'; | ||
|
||
export class CreateBlockDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
noteId: string; | ||
|
||
@IsEnum(BlockTypeEnum) | ||
@IsNotEmpty() | ||
type: BlockTypeEnum; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
content: string; | ||
} |
6 changes: 5 additions & 1 deletion
6
...apps/backend/src/api/user/dto/book.dto.ts → ...kend/libs/types/editor/create.book.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
export class BookDto { | ||
export class CreateBookDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
title: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
userId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { IsNotEmpty, IsString, ValidateNested } from 'class-validator'; | ||
import { Type } from 'class-transformer'; | ||
import { CreateBlockDto } from './create.block'; | ||
|
||
export class CreateNoteDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
title: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
sectionId: string; | ||
|
||
@ValidateNested({ each: true }) | ||
@Type(() => CreateBlockDto) | ||
blocks: CreateBlockDto[]; | ||
} |
Oops, something went wrong.