添加资源模块,添加资源获取接口
This commit is contained in:
@@ -8,6 +8,7 @@ import { AuthModule } from './auth/auth.module';
|
|||||||
import { VerificationModule } from './verification/verification.module';
|
import { VerificationModule } from './verification/verification.module';
|
||||||
import { NotificationModule } from './notification/notification.module';
|
import { NotificationModule } from './notification/notification.module';
|
||||||
import { PassportModule } from '@nestjs/passport';
|
import { PassportModule } from '@nestjs/passport';
|
||||||
|
import { ResourceModule } from './resource/resource.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -27,7 +28,8 @@ import { PassportModule } from '@nestjs/passport';
|
|||||||
UserModule,
|
UserModule,
|
||||||
AuthModule,
|
AuthModule,
|
||||||
VerificationModule,
|
VerificationModule,
|
||||||
NotificationModule
|
NotificationModule,
|
||||||
|
ResourceModule
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
|
|||||||
40
tone-page-server/src/resource/entity/resource.entity.ts
Normal file
40
tone-page-server/src/resource/entity/resource.entity.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, PrimaryColumn, UpdateDateColumn } from "typeorm";
|
||||||
|
|
||||||
|
type ResourceTag = {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Resource {
|
||||||
|
@PrimaryColumn('uuid', { unique: true, default: () => 'gen_random_uuid()' })
|
||||||
|
@Index({ unique: true })
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
imageUrl: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
link: string;
|
||||||
|
|
||||||
|
@Column('jsonb')
|
||||||
|
tags: ResourceTag[];
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
isHidden: boolean;
|
||||||
|
|
||||||
|
@CreateDateColumn({ precision: 3 })
|
||||||
|
createdAt: Date;
|
||||||
|
|
||||||
|
@UpdateDateColumn({ precision: 3 })
|
||||||
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@DeleteDateColumn({ nullable: true, precision: 3 })
|
||||||
|
deletedAt: Date;
|
||||||
|
}
|
||||||
18
tone-page-server/src/resource/resource.controller.spec.ts
Normal file
18
tone-page-server/src/resource/resource.controller.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ResourceController } from './resource.controller';
|
||||||
|
|
||||||
|
describe('ResourceController', () => {
|
||||||
|
let controller: ResourceController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [ResourceController],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<ResourceController>(ResourceController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
15
tone-page-server/src/resource/resource.controller.ts
Normal file
15
tone-page-server/src/resource/resource.controller.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { ResourceService } from './resource.service';
|
||||||
|
|
||||||
|
@Controller('resource')
|
||||||
|
export class ResourceController {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly resourceService: ResourceService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async getResource() {
|
||||||
|
return this.resourceService.findAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
tone-page-server/src/resource/resource.module.ts
Normal file
12
tone-page-server/src/resource/resource.module.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ResourceController } from './resource.controller';
|
||||||
|
import { ResourceService } from './resource.service';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Resource } from './entity/resource.entity';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports:[TypeOrmModule.forFeature([Resource])],
|
||||||
|
controllers: [ResourceController],
|
||||||
|
providers: [ResourceService]
|
||||||
|
})
|
||||||
|
export class ResourceModule {}
|
||||||
18
tone-page-server/src/resource/resource.service.spec.ts
Normal file
18
tone-page-server/src/resource/resource.service.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ResourceService } from './resource.service';
|
||||||
|
|
||||||
|
describe('ResourceService', () => {
|
||||||
|
let service: ResourceService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [ResourceService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<ResourceService>(ResourceService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
16
tone-page-server/src/resource/resource.service.ts
Normal file
16
tone-page-server/src/resource/resource.service.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { Resource } from './entity/resource.entity';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ResourceService {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(Resource)
|
||||||
|
private readonly resourceRepository: Repository<Resource>,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
async findAll(): Promise<Resource[]> {
|
||||||
|
return this.resourceRepository.find();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user