New posts and users modules
Some checks failed
Anatid Blog CI Workflow / test (./backend) (push) Failing after 39s
Anatid Blog CI Workflow / test (./frontend) (push) Successful in 30s
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 39s
Anatid Blog CI Workflow / test (./frontend) (push) Successful in 30s
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
76cf733438
commit
1a74bb3bcd
@ -1,10 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { PostModule } from './post/post.module';
|
||||
import { DatabaseModule } from './database/database.module';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import configuration from './config/configuration';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { DatabaseModule } from './database/database.module';
|
||||
import { PostsModule } from './posts/posts.module';
|
||||
import { UsersModule } from './users/users.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -12,7 +13,8 @@ import configuration from './config/configuration';
|
||||
load: [configuration]
|
||||
}),
|
||||
DatabaseModule,
|
||||
PostModule
|
||||
PostsModule,
|
||||
UsersModule
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
@ -1,16 +0,0 @@
|
||||
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
|
||||
import { Post } from '../post/post.entity';
|
||||
|
||||
@Entity()
|
||||
export class Comment {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
text: string;
|
||||
|
||||
@ManyToOne(() => Post, (post) => post.comments)
|
||||
post: Post;
|
||||
|
||||
}
|
@ -18,7 +18,7 @@ import configuration from '../config/configuration';
|
||||
password: configService.get('database.password'),
|
||||
database: configService.get('database.name'),
|
||||
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
|
||||
synchronize: true, // Be cautious about using synchronize in production
|
||||
synchronize: true,
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
|
@ -3,7 +3,6 @@ import { PostController } from './post.controller';
|
||||
import { PostService } from './post.service';
|
||||
|
||||
@Module({
|
||||
imports: [ PostService ],
|
||||
controllers: [PostController],
|
||||
providers: [PostService]
|
||||
})
|
||||
|
4
backend/src/posts/dto/create-post.dto.ts
Normal file
4
backend/src/posts/dto/create-post.dto.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export CreatePostDto {
|
||||
title: string;
|
||||
body: string;
|
||||
}
|
13
backend/src/posts/post.entity.ts
Normal file
13
backend/src/posts/post.entity.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
export class Post {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
title: string
|
||||
|
||||
@Column()
|
||||
body: string
|
||||
}
|
18
backend/src/posts/posts.controller.spec.ts
Normal file
18
backend/src/posts/posts.controller.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PostsController } from './posts.controller';
|
||||
|
||||
describe('PostsController', () => {
|
||||
let controller: PostsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PostsController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PostsController>(PostsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
24
backend/src/posts/posts.controller.ts
Normal file
24
backend/src/posts/posts.controller.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { PostsService } from './posts.service';
|
||||
import { CreatePostDto } from './dto';
|
||||
|
||||
@Controller('posts')
|
||||
export class PostsController {
|
||||
|
||||
constructor(private readonly postsService: PostService) {}
|
||||
|
||||
@Get()
|
||||
findAll(): string {
|
||||
return this.postsService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string): string {
|
||||
return this.postsService.findOne(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() createPostDto: CreatePostDto): string {
|
||||
return this.postsService;
|
||||
}
|
||||
}
|
9
backend/src/posts/posts.module.ts
Normal file
9
backend/src/posts/posts.module.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Post } from './Post.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Post])],
|
||||
exports: [TypeOrmModule]
|
||||
})
|
||||
export class PostsModule {}
|
18
backend/src/posts/posts.service.spec.ts
Normal file
18
backend/src/posts/posts.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PostsService } from './posts.service';
|
||||
|
||||
describe('PostsService', () => {
|
||||
let service: PostsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [PostsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<PostsService>(PostsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
33
backend/src/posts/posts.service.ts
Normal file
33
backend/src/posts/posts.service.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Post } from './Post.entity';
|
||||
|
||||
@Injectable()
|
||||
export class PostsService {
|
||||
constructor(
|
||||
@InjectRepository(Post)
|
||||
private PostsRepository: Repository<Post>,
|
||||
) {}
|
||||
|
||||
findAll(): Promise<Post[]> {
|
||||
return this.PostsRepository.find();
|
||||
}
|
||||
|
||||
findOne(id: number): Promise<Post | null> {
|
||||
return this.PostsRepository.findOneBy({ id });
|
||||
}
|
||||
|
||||
async create(title: string, body: string) Promise<void> {
|
||||
const newPost = this.PostsRepository.create({
|
||||
title: title,
|
||||
body: body
|
||||
});
|
||||
const post = await this.PostsRepository.save(newPost);
|
||||
return post.id;
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
await this.PostsRepository.delete(id);
|
||||
}
|
||||
}
|
16
backend/src/users/user.entity.ts
Normal file
16
backend/src/users/user.entity.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
firstName: string;
|
||||
|
||||
@Column()
|
||||
lastName: string;
|
||||
|
||||
@Column({ default: true })
|
||||
isActive: boolean;
|
||||
}
|
18
backend/src/users/users.controller.spec.ts
Normal file
18
backend/src/users/users.controller.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { UsersController } from './users.controller';
|
||||
|
||||
describe('UsersController', () => {
|
||||
let controller: UsersController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [UsersController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<UsersController>(UsersController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
4
backend/src/users/users.controller.ts
Normal file
4
backend/src/users/users.controller.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('users')
|
||||
export class UsersController {}
|
9
backend/src/users/users.module.ts
Normal file
9
backend/src/users/users.module.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { User } from './user.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User])],
|
||||
exports: [TypeOrmModule]
|
||||
})
|
||||
export class UsersModule {}
|
18
backend/src/users/users.service.spec.ts
Normal file
18
backend/src/users/users.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { UsersService } from './users.service';
|
||||
|
||||
describe('UsersService', () => {
|
||||
let service: UsersService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [UsersService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<UsersService>(UsersService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
24
backend/src/users/users.service.ts
Normal file
24
backend/src/users/users.service.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { User } from './user.entity';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private usersRepository: Repository<User>,
|
||||
) {}
|
||||
|
||||
findAll(): Promise<User[]> {
|
||||
return this.usersRepository.find();
|
||||
}
|
||||
|
||||
findOne(id: number): Promise<User | null> {
|
||||
return this.usersRepository.findOneBy({ id });
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
await this.usersRepository.delete(id);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user