Skip to content

Commit

Permalink
Merge pull request #23 from Excali-Studio/EXD-88-simple-search
Browse files Browse the repository at this point in the history
[EXD-88] Added "description" field to Canvas & simple search by part …
  • Loading branch information
coredumped7893 authored Jun 11, 2024
2 parents c14d501 + a2b604e commit 52b56b5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/canvas/canvas.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class CanvasController {
return {
id: canvas.id,
name: canvas.name,
description: canvas.description,
tags: canvas.tags,
dateCreated: canvas.dateCreated,
dateUpdated: canvas.dateUpdated,
Expand Down Expand Up @@ -115,6 +116,7 @@ export class CanvasController {
return {
id: canvas.id,
name: canvas.name,
description: canvas.description,
tags: canvas.tags,
dateCreated: canvas.dateCreated,
dateUpdated: canvas.dateUpdated,
Expand Down Expand Up @@ -168,6 +170,7 @@ export class CanvasController {
return {
id: canvas.id,
name: canvas.name,
description: canvas.description,
tags: canvas.tags,
dateCreated: canvas.dateCreated,
dateUpdated: canvas.dateUpdated,
Expand Down
11 changes: 10 additions & 1 deletion src/canvas/canvas.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Transform } from 'class-transformer';

export interface CanvasCreateCommand {
name: string;
description?: string;
userId: Uuid;
}

Expand All @@ -30,6 +31,7 @@ export interface CanvasContentUpdateCommand {
export interface CanvasMetadataUpdateCommand {
id: Uuid;
name: string;
description?: string;
}

export interface GiveAccessCommand {
Expand Down Expand Up @@ -68,12 +70,18 @@ export class CanvasMetadataUpdateDTO {
@MinLength(3)
@MaxLength(255)
name: string;
@IsOptional()
@MaxLength(4000)
description?: string;
}

export class CanvasCreateDTO {
@MinLength(3)
@MaxLength(255)
name: string;
@IsOptional()
@MaxLength(4000)
description?: string;
}

export class CanvasContentUpdateDTO {
Expand All @@ -88,6 +96,7 @@ export interface CanvasDTO {
dateCreated: Date;
dateUpdated: Date;
name: string;
description: string;
tags: CanvasTagDTO[];
}

Expand Down Expand Up @@ -129,7 +138,7 @@ export class CanvasFilter extends ListFilter {
@Transform(({ value }) => (Array.isArray(value) ? value : Array(value)))
tagIds?: Uuid[] = [];
@ApiProperty({ required: false })
searchName?: string;
searchQuery?: string;
}

export class CanvasStateFilter {
Expand Down
18 changes: 13 additions & 5 deletions src/canvas/canvas.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { Repository } from 'typeorm';
import { Brackets, Repository } from 'typeorm';
import { CanvasEntity } from './entity/canvas.entity';
import { InjectRepository } from '@nestjs/typeorm';
import {
Expand Down Expand Up @@ -50,6 +50,7 @@ export class CanvasService {
});
const canvas = new CanvasEntity();
canvas.name = command.name.trim();
canvas.description = command.description?.trim();
await this.canvasRepository.save(canvas);
const canvasAccess = new CanvasAccessEntity();
canvasAccess.isOwner = true;
Expand Down Expand Up @@ -95,6 +96,7 @@ export class CanvasService {
}

canvas.name = command.name.trim();
canvas.description = command.description?.trim();
canvas.dateUpdated = new Date();
await this.canvasRepository.save(canvas);

Expand Down Expand Up @@ -132,10 +134,16 @@ export class CanvasService {
.setParameter(`tagId${index}`, tagId);
});

if (canvasFilter.searchName) {
queryBuilder.andWhere('LOWER(canvas.name) like :searchName', {
searchName: `%${canvasFilter.searchName.toLowerCase()}%`,
});
if (canvasFilter.searchQuery) {
queryBuilder.andWhere(
new Brackets((qb) => {
qb.where('LOWER(canvas.name) like :searchQuery', {
searchQuery: `%${canvasFilter.searchQuery.toLowerCase()}%`,
}).orWhere('LOWER(canvas.description) like :searchQuery', {
searchQuery: `%${canvasFilter.searchQuery.toLowerCase()}%`,
});
}),
);
}

return PageableUtils.producePagedResult(
Expand Down
6 changes: 6 additions & 0 deletions src/canvas/entity/canvas.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export class CanvasEntity {
@Column({ nullable: false })
name: string;

@Column({
type: 'text',
nullable: true,
})
description: string;

@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
dateCreated: Date;

Expand Down

0 comments on commit 52b56b5

Please sign in to comment.