xiongzhu %!s(int64=2) %!d(string=hai) anos
pai
achega
98e666dd90

+ 2 - 1
src/app.module.ts

@@ -56,7 +56,8 @@ import { GalleryModule } from './gallery/gallery.module';
                 cli: {
                     migrationsDir: config.get<string>('TYPEORM_MIGRATIONS_DIR'),
                     subscribersDir: config.get<string>('TYPEORM_SUBSCRIBERS_DIR')
-                }
+                },
+                logging: true
             })
         }),
         AliyunModule,

+ 12 - 16
src/gallery/entities/gallery.entity.ts

@@ -1,31 +1,27 @@
-import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'
+import { ArrayTransformer } from 'src/transformers/array.transformer'
+import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm'
 
 @Entity()
 export class Gallery {
     @PrimaryGeneratedColumn()
     id: number
 
-    @Column({ type: 'varchar' })
-    parody: string[]
-
-    @Column({ type: 'varchar' })
-    charactor: string[]
-
-    @Column({ type: 'varchar' })
-    tag: string[]
-
     @Column()
-    artist: string
+    title: string
 
     @Column()
-    group: string
+    thumb: string
 
-    @Column()
-    language: string
+    charactor: string
+
+    tag: string
 
     @Column()
-    category: string
+    artist: string
 
-    @Column({ type: 'text' })
+    @Column({ type: 'text', transformer: new ArrayTransformer() })
     details: string[]
+
+    @CreateDateColumn()
+    createdAt: Date
 }

+ 5 - 4
src/gallery/gallery.controller.ts

@@ -2,19 +2,20 @@ import { Body, Controller, Get, Post, Put } from '@nestjs/common'
 import { Public } from '../auth/public.decorator'
 import { GalleryService } from './gallery.service'
 import { Gallery } from './entities/gallery.entity'
+import { PageRequest } from '../common/dto/page-request'
 
 @Controller('gallery')
 @Public()
 export class GalleryController {
     constructor(private galleryService: GalleryService) {}
 
-    @Get()
-    async findAll() {
-        return await this.galleryService.findAll()
+    @Post()
+    async findAll(@Body() page: PageRequest<Gallery>) {
+        return await this.galleryService.findAll(page)
     }
 
     @Put()
-    async save(@Body() gallery: Gallery) {
+    async save(@Body() gallery: Partial<Gallery>) {
         return await this.galleryService.save(gallery)
     }
 }

+ 5 - 3
src/gallery/gallery.service.ts

@@ -2,6 +2,8 @@ import { Injectable } from '@nestjs/common'
 import { Repository } from 'typeorm'
 import { Gallery } from './entities/gallery.entity'
 import { InjectRepository } from '@nestjs/typeorm'
+import { PageRequest } from '../common/dto/page-request'
+import { Pagination, paginate } from 'nestjs-typeorm-paginate'
 
 @Injectable()
 export class GalleryService {
@@ -10,11 +12,11 @@ export class GalleryService {
         private readonly galleryRepository: Repository<Gallery>
     ) {}
 
-    async findAll(): Promise<Gallery[]> {
-        return await this.galleryRepository.find()
+    async findAll(req: PageRequest<Gallery>): Promise<Pagination<Gallery>> {
+        return await paginate<Gallery>(this.galleryRepository, req.page, req.search)
     }
 
-    async save(gallery: Gallery): Promise<Gallery> {
+    async save(gallery: Partial<Gallery>): Promise<Gallery> {
         return await this.galleryRepository.save(gallery)
     }
 }

+ 13 - 0
src/transformers/array.transformer.ts

@@ -0,0 +1,13 @@
+import { ValueTransformer } from 'typeorm'
+
+export class ArrayTransformer implements ValueTransformer {
+    to(value: string[]): string {
+        return value?.join()
+    }
+    from(value: string): string[] {
+        if (value) {
+            return value.split(',')
+        }
+        return []
+    }
+}