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

This commit is contained in:
Phill Pover 2025-03-29 08:58:23 +00:00
parent 604ef6ad09
commit 95f3bf98c7
14 changed files with 102 additions and 35 deletions

View File

@ -4,6 +4,7 @@ import { AppService } from './app.service';
import { PostsModule } from './posts/posts.module';
import { DatabaseModule } from './database/database.module';
import { ConfigModule } from '@nestjs/config';
import { PostModule } from './post/post.module';
import configuration from './config/configuration';
@Module({
@ -12,7 +13,8 @@ import configuration from './config/configuration';
load: [configuration]
}),
DatabaseModule,
PostsModule
PostsModule,
PostModule
],
controllers: [AppController],
providers: [AppService],

View File

@ -0,0 +1,7 @@
import { Comment } from './comment';
describe('Comment', () => {
it('should be defined', () => {
expect(new Comment()).toBeDefined();
});
});

View 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;
}

View File

@ -1,15 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PostsController } from './posts.controller';
import { PostController } from './post.controller';
describe('PostsController', () => {
let controller: PostsController;
describe('PostController', () => {
let controller: PostController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [PostsController],
controllers: [PostController],
}).compile();
controller = module.get<PostsController>(PostsController);
controller = module.get<PostController>(PostController);
});
it('should be defined', () => {

View File

@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';
@Controller('post')
export class PostController {}

View File

@ -0,0 +1,7 @@
import { Post } from './post';
describe('Post', () => {
it('should be defined', () => {
expect(new Post()).toBeDefined();
});
});

View 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[];
}

View 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 {}

View File

@ -1,15 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PostsService } from './posts.service';
import { PostService } from './post.service';
describe('PostsService', () => {
let service: PostsService;
describe('PostService', () => {
let service: PostService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [PostsService],
providers: [PostService],
}).compile();
service = module.get<PostsService>(PostsService);
service = module.get<PostService>(PostService);
});
it('should be defined', () => {

View 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 } },
});
}
}

View File

@ -1,7 +0,0 @@
export class Post {
id: number;
title: string;
uri: string;
body: string;
created: Date;
}

View File

@ -1,4 +0,0 @@
import { Controller } from '@nestjs/common';
@Controller('posts')
export class PostsController {}

View File

@ -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 {}

View File

@ -1,4 +0,0 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class PostsService {}