From 6aa678fcfe49311750b87f890a078aaa22f391c0 Mon Sep 17 00:00:00 2001 From: Phill Pover Date: Mon, 31 Mar 2025 15:40:14 +0100 Subject: [PATCH] Clean up --- backend/src/comment/comment.entity.spec.ts | 7 ---- backend/src/post/post.controller.spec.ts | 42 ---------------------- backend/src/post/post.controller.ts | 19 ---------- backend/src/post/post.entity.spec.ts | 7 ---- backend/src/post/post.entity.ts | 19 ---------- backend/src/post/post.module.ts | 9 ----- backend/src/post/post.service.spec.ts | 42 ---------------------- backend/src/post/post.service.ts | 27 -------------- 8 files changed, 172 deletions(-) delete mode 100644 backend/src/comment/comment.entity.spec.ts delete mode 100644 backend/src/post/post.controller.spec.ts delete mode 100644 backend/src/post/post.controller.ts delete mode 100644 backend/src/post/post.entity.spec.ts delete mode 100644 backend/src/post/post.entity.ts delete mode 100644 backend/src/post/post.module.ts delete mode 100644 backend/src/post/post.service.spec.ts delete mode 100644 backend/src/post/post.service.ts diff --git a/backend/src/comment/comment.entity.spec.ts b/backend/src/comment/comment.entity.spec.ts deleted file mode 100644 index f9f617f..0000000 --- a/backend/src/comment/comment.entity.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Comment } from './comment.entity'; - -describe('Comment', () => { - it('should be defined', () => { - expect(new Comment()).toBeDefined(); - }); -}); diff --git a/backend/src/post/post.controller.spec.ts b/backend/src/post/post.controller.spec.ts deleted file mode 100644 index a0311f2..0000000 --- a/backend/src/post/post.controller.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { PostController } from './post.controller'; -import { PostService } from './post.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { Post } from './post.entity'; -import { Comment } from '../comment/comment.entity'; - -const mockPost = new Post(); -const mockComment = new Comment(); - -describe('PostController', () => { - let controller: PostController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [PostController], - providers: [ - PostService, - { - provide: getRepositoryToken(Post), - useValue: { - save: jest.fn().mockResolvedValue(mockPost), - find: jest.fn().mockResolvedValue([mockPost]), - }, - }, - { - provide: getRepositoryToken(Comment), - useValue: { - save: jest.fn().mockResolvedValue(mockComment), - find: jest.fn().mockResolvedValue([mockComment]), - }, - }, - ], - }).compile(); - - controller = module.get(PostController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/post/post.controller.ts b/backend/src/post/post.controller.ts deleted file mode 100644 index f80d16d..0000000 --- a/backend/src/post/post.controller.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Controller, Get, Param } from '@nestjs/common'; -import { PostService } from './post.service'; - -@Controller('posts') -export class PostController { - - constructor(private readonly postService: PostService) {} - - @Get() - async findAll() { - return this.postService.findAll(); - } - - @Get(':id/comments') - async findCommentsByPostId(@Param('id') postId: string) { - return this.postService.findCommentsByPostId(+postId); - } - -} diff --git a/backend/src/post/post.entity.spec.ts b/backend/src/post/post.entity.spec.ts deleted file mode 100644 index a53e694..0000000 --- a/backend/src/post/post.entity.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Post } from './post.entity'; - -describe('Post', () => { - it('should be defined', () => { - expect(new Post()).toBeDefined(); - }); -}); diff --git a/backend/src/post/post.entity.ts b/backend/src/post/post.entity.ts deleted file mode 100644 index 4e91111..0000000 --- a/backend/src/post/post.entity.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; -import { Comment } from '../comment/comment.entity'; - -@Entity() -export class Post { - - @PrimaryGeneratedColumn() - id: number; - - @Column() - title: string; - - @Column() - content: string; - - @OneToMany(() => Comment, (comment) => comment.post) - comments: Comment[]; - -} diff --git a/backend/src/post/post.module.ts b/backend/src/post/post.module.ts deleted file mode 100644 index af735ef..0000000 --- a/backend/src/post/post.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Module } from '@nestjs/common'; -import { PostController } from './post.controller'; -import { PostService } from './post.service'; - -@Module({ - controllers: [PostController], - providers: [PostService] -}) -export class PostModule {} diff --git a/backend/src/post/post.service.spec.ts b/backend/src/post/post.service.spec.ts deleted file mode 100644 index 6e35eb2..0000000 --- a/backend/src/post/post.service.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { PostService } from './post.service'; -import { PostController } from './post.controller'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { Post } from './post.entity'; -import { Comment } from '../comment/comment.entity'; - -const mockPost = new Post(); -const mockComment = new Comment(); - -describe('PostService', () => { - let service: PostService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [PostController], - providers: [ - PostService, - { - provide: getRepositoryToken(Post), - useValue: { - save: jest.fn().mockResolvedValue(mockPost), - find: jest.fn().mockResolvedValue([mockPost]), - }, - }, - { - provide: getRepositoryToken(Comment), - useValue: { - save: jest.fn().mockResolvedValue(mockComment), - find: jest.fn().mockResolvedValue([mockComment]), - }, - }, - ], - }).compile(); - - service = module.get(PostService); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/backend/src/post/post.service.ts b/backend/src/post/post.service.ts deleted file mode 100644 index 8953977..0000000 --- a/backend/src/post/post.service.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; -import { Post } from './post.entity'; -import { Comment } from '../comment/comment.entity'; - -@Injectable() -export class PostService { - - constructor( - @InjectRepository(Post) - private postRepository: Repository, - - @InjectRepository(Comment) - private commentRepository: Repository, - ) {} - - async findAll(): Promise { - return this.postRepository.find(); - } - - async findCommentsByPostId(postId: number): Promise { - return this.commentRepository.find({ - where: { post: { id: postId } }, - }); - } -}