Skip to content

Commit ae6c730

Browse files
authored
Merge pull request #19 from nmbazima/codespace-super-space-dollop-vpx66qj5qxr3pqr9
Pending changes exported from your codespace
2 parents d20ad92 + ba80397 commit ae6c730

7 files changed

Lines changed: 223 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Article Management Project
2+
3+
This project provides a simple and scalable way to manage articles and organize them by categories. Below are the instructions on how to post articles and utilize the category management features.
4+
5+
## Table of Contents
6+
- [Getting Started](#getting-started)
7+
- [Posting an Article](#posting-an-article)
8+
- [Organizing Articles by Category](#organizing-articles-by-category)
9+
- [Project Structure](#project-structure)
10+
11+
## Getting Started
12+
13+
To get started with the Article Management Project, clone the repository and install the necessary dependencies.
14+
15+
```bash
16+
git clone <repository-url>
17+
cd article-management-project
18+
npm install
19+
```
20+
21+
## Posting an Article
22+
23+
1. Navigate to the `src/articles` directory.
24+
2. Create a new Markdown file for your article. Use the naming convention `article-title.md` (e.g., `my-first-article.md`).
25+
3. Structure your article using Markdown syntax. Here’s a basic template:
26+
27+
```markdown
28+
# Article Title
29+
30+
## Introduction
31+
Write an introduction here.
32+
33+
## Content
34+
Write the main content of your article here.
35+
36+
## Conclusion
37+
Write a conclusion here.
38+
```
39+
40+
4. Save the file. Your article will now be available in the project.
41+
42+
## Organizing Articles by Category
43+
44+
1. To add a new category, open the `src/categories/index.ts` file.
45+
2. Use the `addCategory` method of the `CategoryManager` class to create a new category.
46+
3. Assign articles to categories using the `organizeArticlesByCategory` method.
47+
48+
Example usage:
49+
50+
```typescript
51+
const categoryManager = new CategoryManager();
52+
categoryManager.addCategory('Technology');
53+
categoryManager.organizeArticlesByCategory('Technology', 'my-first-article.md');
54+
```
55+
56+
## Project Structure
57+
58+
- `src/articles/`: Contains all article files in Markdown format.
59+
- `src/categories/`: Contains the `CategoryManager` class for managing categories.
60+
- `src/app.ts`: Entry point of the application.
61+
- `src/types/`: Contains TypeScript interfaces for articles and categories.
62+
- `package.json`: Lists dependencies and scripts for the project.
63+
- `tsconfig.json`: TypeScript configuration file.
64+
65+
For further information, refer to the code comments in the respective files or consult the documentation of the libraries used.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "article-management-project",
3+
"version": "1.0.0",
4+
"description": "A project for managing articles and organizing them by categories.",
5+
"main": "src/app.ts",
6+
"scripts": {
7+
"start": "ts-node src/app.ts",
8+
"build": "tsc",
9+
"test": "echo \"No tests specified\" && exit 0"
10+
},
11+
"dependencies": {
12+
"express": "^4.17.1",
13+
"typescript": "^4.4.4"
14+
},
15+
"devDependencies": {
16+
"@types/express": "^4.17.11",
17+
"ts-node": "^10.4.0"
18+
},
19+
"author": "Your Name",
20+
"license": "MIT"
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import express from 'express';
2+
import bodyParser from 'body-parser';
3+
import { CategoryManager } from './categories/index';
4+
import { Article } from './types/index';
5+
6+
const app = express();
7+
const port = process.env.PORT || 3000;
8+
const categoryManager = new CategoryManager();
9+
10+
app.use(bodyParser.json());
11+
12+
// Endpoint to post a new article
13+
app.post('/articles', (req, res) => {
14+
const article: Article = req.body;
15+
// Logic to save the article
16+
res.status(201).send('Article posted successfully');
17+
});
18+
19+
// Endpoint to get articles by category
20+
app.get('/articles/:category', (req, res) => {
21+
const category = req.params.category;
22+
const articles = categoryManager.organizeArticlesByCategory(category);
23+
res.status(200).json(articles);
24+
});
25+
26+
// Endpoint to add a new category
27+
app.post('/categories', (req, res) => {
28+
const categoryName = req.body.name;
29+
categoryManager.addCategory(categoryName);
30+
res.status(201).send('Category added successfully');
31+
});
32+
33+
// Endpoint to get all categories
34+
app.get('/categories', (req, res) => {
35+
const categories = categoryManager.getCategories();
36+
res.status(200).json(categories);
37+
});
38+
39+
app.listen(port, () => {
40+
console.log(`Server is running on http://localhost:${port}`);
41+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Markdown content for the example article
2+
3+
# Example Article Title
4+
5+
## Introduction
6+
7+
This is an example article to demonstrate how to structure articles within the article management project. Articles are written in Markdown format, which allows for easy formatting and readability.
8+
9+
## Content
10+
11+
### Section 1: Overview
12+
13+
In this section, you can provide an overview of the topic discussed in the article. Use headings, lists, and other Markdown features to organize your content effectively.
14+
15+
### Section 2: Details
16+
17+
Here, you can delve deeper into the subject matter. Include relevant information, statistics, or examples to support your points.
18+
19+
- Bullet point 1
20+
- Bullet point 2
21+
- Bullet point 3
22+
23+
### Conclusion
24+
25+
Summarize the key points discussed in the article and provide any final thoughts or calls to action.
26+
27+
## Categories
28+
29+
- Example Category 1
30+
- Example Category 2
31+
32+
## References
33+
34+
1. Reference 1
35+
2. Reference 2
36+
37+
This example serves as a template for creating new articles. Be sure to replace the content with your own and adjust the categories as needed.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class CategoryManager {
2+
private categories: string[] = [];
3+
private articlesByCategory: { [key: string]: string[] } = {};
4+
5+
addCategory(category: string): void {
6+
if (!this.categories.includes(category)) {
7+
this.categories.push(category);
8+
this.articlesByCategory[category] = [];
9+
}
10+
}
11+
12+
getCategories(): string[] {
13+
return this.categories;
14+
}
15+
16+
organizeArticlesByCategory(article: string, category: string): void {
17+
if (this.categories.includes(category)) {
18+
this.articlesByCategory[category].push(article);
19+
} else {
20+
throw new Error(`Category "${category}" does not exist.`);
21+
}
22+
}
23+
24+
getArticlesByCategory(category: string): string[] {
25+
return this.articlesByCategory[category] || [];
26+
}
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export interface Article {
2+
id: string;
3+
title: string;
4+
content: string;
5+
categoryId: string;
6+
createdAt: Date;
7+
updatedAt: Date;
8+
}
9+
10+
export interface Category {
11+
id: string;
12+
name: string;
13+
description?: string;
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"module": "commonjs",
5+
"strict": true,
6+
"esModuleInterop": true,
7+
"skipLibCheck": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"outDir": "./dist"
10+
},
11+
"include": [
12+
"src/**/*"
13+
],
14+
"exclude": [
15+
"node_modules",
16+
"**/*.spec.ts"
17+
]
18+
}

0 commit comments

Comments
 (0)