添加博客模块
This commit is contained in:
@@ -9,6 +9,8 @@ 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';
|
import { ResourceModule } from './resource/resource.module';
|
||||||
|
import { BlogModule } from './blog/blog.module';
|
||||||
|
import { BlgService } from './blg/blg.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -29,9 +31,10 @@ import { ResourceModule } from './resource/resource.module';
|
|||||||
AuthModule,
|
AuthModule,
|
||||||
VerificationModule,
|
VerificationModule,
|
||||||
NotificationModule,
|
NotificationModule,
|
||||||
ResourceModule
|
ResourceModule,
|
||||||
|
BlogModule
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService, BlgService],
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|||||||
18
tone-page-server/src/blog/blog.controller.spec.ts
Normal file
18
tone-page-server/src/blog/blog.controller.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { BlogController } from './blog.controller';
|
||||||
|
|
||||||
|
describe('BlogController', () => {
|
||||||
|
let controller: BlogController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [BlogController],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<BlogController>(BlogController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
15
tone-page-server/src/blog/blog.controller.ts
Normal file
15
tone-page-server/src/blog/blog.controller.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { BlogService } from './blog.service';
|
||||||
|
|
||||||
|
@Controller('blog')
|
||||||
|
export class BlogController {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly blogService: BlogService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
getBlogs() {
|
||||||
|
return this.blogService.list();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
tone-page-server/src/blog/blog.module.ts
Normal file
12
tone-page-server/src/blog/blog.module.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { BlogController } from './blog.controller';
|
||||||
|
import { BlogService } from './blog.service';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Blog } from './entity/Blog.entity';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [TypeOrmModule.forFeature([Blog])],
|
||||||
|
controllers: [BlogController],
|
||||||
|
providers: [BlogService]
|
||||||
|
})
|
||||||
|
export class BlogModule { }
|
||||||
18
tone-page-server/src/blog/blog.service.spec.ts
Normal file
18
tone-page-server/src/blog/blog.service.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { BlogService } from './blog.service';
|
||||||
|
|
||||||
|
describe('BlogService', () => {
|
||||||
|
let service: BlogService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [BlogService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<BlogService>(BlogService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
23
tone-page-server/src/blog/blog.service.ts
Normal file
23
tone-page-server/src/blog/blog.service.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Blog } from './entity/Blog.entity';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BlogService {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(Blog)
|
||||||
|
private readonly blogRepository: Repository<Blog>,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
async list() {
|
||||||
|
return this.blogRepository.find({
|
||||||
|
where: { deletedAt: null },
|
||||||
|
order: {
|
||||||
|
publishAt: 'DESC',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
30
tone-page-server/src/blog/entity/Blog.entity.ts
Normal file
30
tone-page-server/src/blog/entity/Blog.entity.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Column, CreateDateColumn, DeleteDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Blog {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
contentUrl: string;
|
||||||
|
|
||||||
|
@Column({ precision: 3 })
|
||||||
|
publishAt: Date;
|
||||||
|
|
||||||
|
@CreateDateColumn({ precision: 3 })
|
||||||
|
createdAt: Date;
|
||||||
|
|
||||||
|
@UpdateDateColumn({ precision: 3 })
|
||||||
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@DeleteDateColumn({ precision: 3, nullable: true })
|
||||||
|
deletedAt: Date;
|
||||||
|
|
||||||
|
// 权限关系 TODO
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user