Adding basic posts and comments
Some checks failed
Anatid Blog CI Workflow / test (./backend) (push) Failing after 28s
Anatid Blog CI Workflow / test (./frontend) (push) Successful in 29s
Anatid Blog CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/anatid-blog-backend, ./backend) (push) Has been skipped
Anatid Blog CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/anatid-blog-frontend, ./frontend) (push) Has been skipped
Anatid Blog CI Workflow / deploy (push) Has been skipped
Some checks failed
Anatid Blog CI Workflow / test (./backend) (push) Failing after 28s
Anatid Blog CI Workflow / test (./frontend) (push) Successful in 29s
Anatid Blog CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/anatid-blog-backend, ./backend) (push) Has been skipped
Anatid Blog CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/anatid-blog-frontend, ./frontend) (push) Has been skipped
Anatid Blog CI Workflow / deploy (push) Has been skipped
This commit is contained in:
parent
604ef6ad09
commit
95f3bf98c7
@ -4,6 +4,7 @@ import { AppService } from './app.service';
|
|||||||
import { PostsModule } from './posts/posts.module';
|
import { PostsModule } from './posts/posts.module';
|
||||||
import { DatabaseModule } from './database/database.module';
|
import { DatabaseModule } from './database/database.module';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { PostModule } from './post/post.module';
|
||||||
import configuration from './config/configuration';
|
import configuration from './config/configuration';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@ -12,7 +13,8 @@ import configuration from './config/configuration';
|
|||||||
load: [configuration]
|
load: [configuration]
|
||||||
}),
|
}),
|
||||||
DatabaseModule,
|
DatabaseModule,
|
||||||
PostsModule
|
PostsModule,
|
||||||
|
PostModule
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
|
7
backend/src/comment/comment.entity.spec.ts
Normal file
7
backend/src/comment/comment.entity.spec.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { Comment } from './comment';
|
||||||
|
|
||||||
|
describe('Comment', () => {
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(new Comment()).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
16
backend/src/comment/comment.entity.ts
Normal file
16
backend/src/comment/comment.entity.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
|
||||||
|
import { Post } from './post.entity';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Comment {
|
||||||
|
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
text: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => Post, (post) => post.comments)
|
||||||
|
post: Post;
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,15 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { PostsController } from './posts.controller';
|
import { PostController } from './post.controller';
|
||||||
|
|
||||||
describe('PostsController', () => {
|
describe('PostController', () => {
|
||||||
let controller: PostsController;
|
let controller: PostController;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [PostsController],
|
controllers: [PostController],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
controller = module.get<PostsController>(PostsController);
|
controller = module.get<PostController>(PostController);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
4
backend/src/post/post.controller.ts
Normal file
4
backend/src/post/post.controller.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { Controller } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Controller('post')
|
||||||
|
export class PostController {}
|
7
backend/src/post/post.entity.spec.ts
Normal file
7
backend/src/post/post.entity.spec.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { Post } from './post';
|
||||||
|
|
||||||
|
describe('Post', () => {
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(new Post()).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
19
backend/src/post/post.entity.ts
Normal file
19
backend/src/post/post.entity.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from ‘typeorm’;
|
||||||
|
import { Comment } from ‘./comment.entity’;
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Post {
|
||||||
|
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
content: string;
|
||||||
|
|
||||||
|
@OneToMany(() => Comment, (comment) => comment.post)
|
||||||
|
comments: Comment[];
|
||||||
|
|
||||||
|
}
|
9
backend/src/post/post.module.ts
Normal file
9
backend/src/post/post.module.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { PostController } from './post.controller';
|
||||||
|
import { PostService } from './post.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [PostController],
|
||||||
|
providers: [PostService]
|
||||||
|
})
|
||||||
|
export class PostModule {}
|
@ -1,15 +1,15 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { PostsService } from './posts.service';
|
import { PostService } from './post.service';
|
||||||
|
|
||||||
describe('PostsService', () => {
|
describe('PostService', () => {
|
||||||
let service: PostsService;
|
let service: PostService;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [PostsService],
|
providers: [PostService],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
service = module.get<PostsService>(PostsService);
|
service = module.get<PostService>(PostService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
27
backend/src/post/post.service.ts
Normal file
27
backend/src/post/post.service.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { Post } from './post.entity';
|
||||||
|
import { Comment } from './comment.entity';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PostService {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(Post)
|
||||||
|
private postRepository: Repository<Post>,
|
||||||
|
|
||||||
|
@InjectRepository(Comment)
|
||||||
|
private commentRepository: Repository<Comment>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async findAll(): Promise<Post[]> {
|
||||||
|
return this.postRepository.find();
|
||||||
|
}
|
||||||
|
|
||||||
|
async findCommentsByPostId(postId: number): Promise<Comment[]> {
|
||||||
|
return this.commentRepository.find({
|
||||||
|
where: { post: { id: postId } },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
export class Post {
|
|
||||||
id: number;
|
|
||||||
title: string;
|
|
||||||
uri: string;
|
|
||||||
body: string;
|
|
||||||
created: Date;
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
import { Controller } from '@nestjs/common';
|
|
||||||
|
|
||||||
@Controller('posts')
|
|
||||||
export class PostsController {}
|
|
@ -1,9 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { PostsController } from './posts.controller';
|
|
||||||
import { PostsService } from './posts.service';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
controllers: [PostsController],
|
|
||||||
providers: [PostsService],
|
|
||||||
})
|
|
||||||
export class PostsModule {}
|
|
@ -1,4 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class PostsService {}
|
|
Loading…
x
Reference in New Issue
Block a user