Skip to content

Commit

Permalink
feat: rename comment subscribe table name and generate migration
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxing9 committed Sep 18, 2024
1 parent 4e350c0 commit 591b79c
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ export class CommentOpenApiController {
}

// eslint-disable-next-line sonarjs/no-duplicate-string
@Get('/:recordId/notify')
@Get('/:recordId/subscribe')
@Permissions('record|read')
async getNotifyDetail(@Param('tableId') tableId: string, @Param('recordId') recordId: string) {
return this.commentOpenApiService.getNotifyDetail(tableId, recordId);
async getSubscribeDetail(@Param('tableId') tableId: string, @Param('recordId') recordId: string) {
return this.commentOpenApiService.getSubscribeDetail(tableId, recordId);
}

@Post('/:recordId/notify')
@Post('/:recordId/subscribe')
@Permissions('record|read')
async notifyComment(@Param('tableId') tableId: string, @Param('recordId') recordId: string) {
return this.commentOpenApiService.notifyComment(tableId, recordId);
async subscribeComment(@Param('tableId') tableId: string, @Param('recordId') recordId: string) {
return this.commentOpenApiService.subscribeComment(tableId, recordId);
}

@Delete('/:recordId/notify')
@Delete('/:recordId/subscribe')
@Permissions('record|read')
async unNotifyComment(@Param('tableId') tableId: string, @Param('recordId') recordId: string) {
return this.commentOpenApiService.unNotifyComment(tableId, recordId);
async unsubscribeComment(@Param('tableId') tableId: string, @Param('recordId') recordId: string) {
return this.commentOpenApiService.unsubscribeComment(tableId, recordId);
}

@Get('/:recordId/list')
Expand Down Expand Up @@ -79,7 +79,7 @@ export class CommentOpenApiController {
// eslint-disable-next-line sonarjs/no-duplicate-string
@Get('/:recordId/:commentId')
@Permissions('record|read')
async getCommentDetail(@Param('commentId') commentId: string): Promise<ICommentVo> {
async getCommentDetail(@Param('commentId') commentId: string): Promise<ICommentVo | null> {
return this.commentOpenApiService.getCommentDetail(commentId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ CREATE TABLE "comment" (
);

-- CreateTable
CREATE TABLE "comment_notify" (
CREATE TABLE "comment_subscription" (
"table_id" TEXT NOT NULL,
"record_id" TEXT NOT NULL,
"created_by" TEXT NOT NULL,
"created_time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);

-- CreateIndex
CREATE UNIQUE INDEX "comment_notify_table_id_record_id_key" ON "comment_notify"("table_id", "record_id");
CREATE INDEX "comment_subscription_table_id_record_id_idx" ON "comment_subscription"("table_id", "record_id");

-- CreateIndex
CREATE UNIQUE INDEX "comment_subscription_table_id_record_id_key" ON "comment_subscription"("table_id", "record_id");
5 changes: 3 additions & 2 deletions packages/db-main-prisma/prisma/postgres/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,13 @@ model Comment {
@@map("comment")
}

model CommentNotify {
model CommentSubscription {
tableId String @map("table_id")
recordId String @map("record_id")
createdBy String @map("created_by")
createdTime DateTime @default(now()) @map("created_time")
@@unique([tableId, recordId])
@@map("comment_notify")
@@index([tableId, recordId])
@@map("comment_subscription")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ CREATE TABLE "comment" (
);

-- CreateTable
CREATE TABLE "comment_notify" (
CREATE TABLE "comment_subscription" (
"table_id" TEXT NOT NULL,
"record_id" TEXT NOT NULL,
"created_by" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);

-- CreateIndex
CREATE UNIQUE INDEX "comment_notify_table_id_record_id_key" ON "comment_notify"("table_id", "record_id");
CREATE INDEX "comment_subscription_table_id_record_id_idx" ON "comment_subscription"("table_id", "record_id");

-- CreateIndex
CREATE UNIQUE INDEX "comment_subscription_table_id_record_id_key" ON "comment_subscription"("table_id", "record_id");
5 changes: 3 additions & 2 deletions packages/db-main-prisma/prisma/sqlite/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,13 @@ model Comment {
@@map("comment")
}

model CommentNotify {
model CommentSubscription {
tableId String @map("table_id")
recordId String @map("record_id")
createdBy String @map("created_by")
createdTime DateTime @default(now()) @map("created_time")
@@unique([tableId, recordId])
@@map("comment_notify")
@@index([tableId, recordId])
@@map("comment_subscription")
}
5 changes: 3 additions & 2 deletions packages/db-main-prisma/prisma/template.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,13 @@ model Comment {
@@map("comment")
}

model CommentNotify {
model CommentSubscription {
tableId String @map("table_id")
recordId String @map("record_id")
createdBy String @map("created_by")
createdTime DateTime @default(now()) @map("created_time")
@@unique([tableId, recordId])
@@map("comment_notify")
@@index([tableId, recordId])
@@map("comment_subscription")
}
2 changes: 1 addition & 1 deletion packages/openapi/src/comment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export * from './update';
export * from './get';
export * from './delete';
export * from './reaction';
export * from './notify';
export * from './subscribe';
export * from './get-attachment-url';
export * from './get-count';
28 changes: 0 additions & 28 deletions packages/openapi/src/comment/notify/create-notify.ts

This file was deleted.

28 changes: 0 additions & 28 deletions packages/openapi/src/comment/notify/delete-notify.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/openapi/src/comment/notify/get-notify.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/openapi/src/comment/notify/index.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/openapi/src/comment/subscribe/create-subscribe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { RouteConfig } from '@asteasolutions/zod-to-openapi';
import { axios } from '../../axios';
import { registerRoute, urlBuilder } from '../../utils';
import { z } from '../../zod';

export const CREATE_COMMENT_SUBSCRIBE = '/comment/{tableId}/{recordId}/subscribe';

export const CreateCommentSubscribeRoute: RouteConfig = registerRoute({
method: 'post',
path: CREATE_COMMENT_SUBSCRIBE,
description: "subscribe record comment's active",
request: {
params: z.object({
tableId: z.string(),
recordId: z.string(),
}),
},
responses: {
200: {
description: 'Successfully subscribe record comment.',
},
},
tags: ['comment'],
});

export const createCommentSubscribe = async (tableId: string, recordId: string) => {
return axios.post<void>(urlBuilder(CREATE_COMMENT_SUBSCRIBE, { tableId, recordId }));
};
28 changes: 28 additions & 0 deletions packages/openapi/src/comment/subscribe/delete-subscribe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { RouteConfig } from '@asteasolutions/zod-to-openapi';
import { axios } from '../../axios';
import { registerRoute, urlBuilder } from '../../utils';
import { z } from '../../zod';

export const DELETE_COMMENT_SUBSCRIBE = '/comment/{tableId}/{recordId}/subscribe';

export const DeleteCommentSubscribeRoute: RouteConfig = registerRoute({
method: 'delete',
path: DELETE_COMMENT_SUBSCRIBE,
description: 'unsubscribe record comment',
request: {
params: z.object({
tableId: z.string(),
recordId: z.string(),
}),
},
responses: {
200: {
description: 'Successfully subscribe record comment.',
},
},
tags: ['comment'],
});

export const deleteCommentSubscribe = async (tableId: string, recordId: string) => {
return axios.delete<void>(urlBuilder(DELETE_COMMENT_SUBSCRIBE, { tableId, recordId }));
};
36 changes: 36 additions & 0 deletions packages/openapi/src/comment/subscribe/get-subscribe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { RouteConfig } from '@asteasolutions/zod-to-openapi';
import { axios } from '../../axios';
import { registerRoute, urlBuilder } from '../../utils';
import { z } from '../../zod';

export const GET_COMMENT_SUBSCRIBE = '/comment/{tableId}/{recordId}/subscribe';

export const commentSubscribeVoSchema = z.object({
tableId: z.string(),
recordId: z.string(),
createdBy: z.string(),
});

export type ICommentSubscribeVo = z.infer<typeof commentSubscribeVoSchema>;

export const GetCommentSubscribeRoute: RouteConfig = registerRoute({
method: 'get',
path: GET_COMMENT_SUBSCRIBE,
description: 'get record comment subscribe detail',
request: {
params: z.object({
tableId: z.string(),
recordId: z.string(),
}),
},
responses: {
200: {
description: 'Successfully get record comment subscribe detail.',
},
},
tags: ['comment'],
});

export const getCommentSubscribe = async (tableId: string, recordId: string) => {
return axios.get<ICommentSubscribeVo>(urlBuilder(GET_COMMENT_SUBSCRIBE, { tableId, recordId }));
};
Loading

0 comments on commit 591b79c

Please sign in to comment.