src/
|-- contexts/ # Domain classification by context
| |-- auth/ # Authentication related logic (JWT, Bearer token)
| | |-- dtos/ # Data Transfer Objects for auth
| | |-- models/ # Auth related models (e.g., User)
| | |-- services/ # Auth related business logic
| | `-- auth.controller.ts # Routes related to authentication
|
| |-- frontendBoard/ # Frontend bulletin board context
| | |-- dtos/ # Data Transfer Objects for frontend posts
| | |-- models/ # Frontend board related models (e.g., Post, Comment, Like)
| | |-- services/ # Business logic for frontend board
| | `-- board.controller.ts# Routes for the frontend bulletin board
|
| `-- backendBoard/ # Backend bulletin board context
| |-- dtos/ # Data Transfer Objects for backend posts
| |-- models/ # Backend board related models
| |-- services/ # Business logic for backend board
| `-- board.controller.ts# Routes for the backend bulletin board
|
|-- shared/ # Shared utilities, middleware, etc.
| |-- middleware/ # Custom express middleware
| |-- utils/ # Utility functions
| `-- validators/ # Request validation schemas
|
|-- config/ # Configuration files (e.g., database config)
|-- prisma/ # Prisma ORM related files
| `-- schema.prisma # Prisma schema file
|
`-- app.ts # Entry point of the application
이러한 구조에서
// src/contexts/frontendBoard/dtos/CreatePostDto.ts
export class CreatePostDto {
title: string;
content: string;
constructor(title: string, content: string) {
this.title = title;
this.content = content;
}
}
// src/contexts/frontendBoard/models/Post.ts
export class Post {
id: number;
title: string;
content: string;
createdAt: Date;
constructor(id: number, title: string, content: string, createdAt: Date) {
this.id = id;
this.title = title;
this.content = content;
this.createdAt = createdAt;
}
// Method to display post info
displayInfo() {
console.log(`Post: ${this.title}, created at: ${this.createdAt}`);
}
}
// src/contexts/frontendBoard/services/PostService.ts
import { Post } from '../models/Post';
import { CreatePostDto } from '../dtos/CreatePostDto';
export class PostService {
createPost(createPostDto: CreatePostDto): Post {
// Simulate saving the post to a database and returning the new post object
const newPost = new Post(Date.now(), createPostDto.title, createPostDto.content, new Date());
console.log(`Created new post with title: ${newPost.title}`);
return newPost;
}
}