Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin panel #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/controller/comment.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Request, Response } from 'express';
import asyncHandler from 'express-async-handler';
import { getAllComments, createComment, saveComment, findCommentById, deleteComment } from '@src/service/comment.service';

// Get the list of comments
export const commentList = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const comments = await getAllComments()
res.json(comments);
});

export const commentCreateGet = asyncHandler(async (req: Request, res: Response): Promise<void> => {
// You can return an HTML form here if you're rendering views
res.json({ message: 'Ready to create a new comment' });
});

// Create a new comment
export const commentCreatePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const { review_id, parent_id, comment_text } = req.body;

const comment = await createComment({
review_id,
parent_id,
comment_text,
});

res.status(201).json(comment);
});

Comment on lines +11 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admin có nghiệp vụ tạo comment à e?

// Get details of a specific comment
export const commentDetails = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const comment = await findCommentById(parseInt(req.params.id))

if (!comment) {
res.status(404).json({ message: 'Comment not found' });
return;
}

res.json(comment);
});
Comment on lines +30 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action view detail comment c nghĩ ko cần nè


export const commentUpdateGet = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const comment = await findCommentById(parseInt(req.params.id));

if (!comment) {
res.status(404).json({ message: 'Comment not found' });
return;
}

// You can return an HTML form here if you're rendering views
// For now, let's return the comment data as JSON
res.json(comment);
});

// Update an existing comment
export const commentUpdatePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const comment = await findCommentById(parseInt(req.params.id))

if (!comment) {
res.status(404).json({ message: 'Comment not found' });
return;
}

const { comment_text } = req.body;

comment.comment_text = comment_text;

await saveComment(comment)
res.json(comment);
});
Comment on lines +41 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tương tự, admin có nghiệp vụ update comment ko e?


// Delete a comment
export const commentDeletePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const comment = await findCommentById(parseInt(req.params.id))

if (!comment) {
res.status(404).json({ message: 'Comment not found' });
return;
}

await deleteComment(comment)
res.status(204).send(); // No content to send back
});
85 changes: 85 additions & 0 deletions src/controller/enrollment.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Request, Response } from 'express';
import asyncHandler from 'express-async-handler';
import { createEnrollments, deleteEnrollment, findEnrollmentById, getAllEnrollments, saveEnrollment } from '@src/service/enrollment.service';

// Get the list of enrollments
export const enrollmentList = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const enrollments = await getAllEnrollments()
res.json(enrollments);
});

export const enrollmentCreateGet = asyncHandler(async (req: Request, res: Response): Promise<void> => {
// You can return an HTML form here if you're rendering views
res.json({ message: 'Ready to create a new enrollment' });
});

// Create a new enrollment
export const enrollmentCreatePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const { user_id, course_id, enrollment_date, progress, completion_date } = req.body;

const enrollment = createEnrollments({
user_id,
course_id,
enrollment_date,
progress,
completion_date,
});

res.status(201).json(enrollment);
});

// Get details of a specific enrollment
export const enrollmentDetails = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const enrollment = await findEnrollmentById(parseInt(req.params.id))

if (!enrollment) {
res.status(404).json({ message: 'Enrollment not found' });
return;
}

res.json(enrollment);
});

export const enrollmentUpdateGet = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const enrollment = await findEnrollmentById(parseInt(req.params.id));

if (!enrollment) {
res.status(404).json({ message: 'Enrollment not found' });
return;
}

// You can return an HTML form here if you're rendering views
// For now, let's return the enrollment data as JSON
res.json(enrollment);
});

// Update an existing enrollment
export const enrollmentUpdatePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const enrollment = await findEnrollmentById(parseInt(req.params.id))

if (!enrollment) {
res.status(404).json({ message: 'Enrollment not found' });
return;
}

const { progress, completion_date } = req.body;

enrollment.progress = progress;
enrollment.completion_date = completion_date;

await saveEnrollment(enrollment)
res.json(enrollment);
});

// Delete an enrollment
export const enrollmentDeletePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const enrollment = await findEnrollmentById(parseInt(req.params.id))

if (!enrollment) {
res.status(404).json({ message: 'Enrollment not found' });
return;
}

await deleteEnrollment
res.status(204).send(); // No content to send back
});
92 changes: 92 additions & 0 deletions src/controller/lesson.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Request, Response } from 'express';
import asyncHandler from 'express-async-handler';
import { getRepository } from 'typeorm';
import { Lesson } from '../entity/Lesson';
import { createLesson, deleteLesson, findLessonById, getAllLessons, saveLesson } from '../service/lesson.service';

// Get the list of lessons
export const lessonList = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const lessons = await getAllLessons()
res.json(lessons);
});

export const lessonCreateGet = asyncHandler(async (req: Request, res: Response): Promise<void> => {
// You can return an HTML form here if you're rendering views
res.json({ message: 'Ready to create a new lesson' });
});

// Create a new lesson
export const lessonCreatePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const { name, progress, type, content, description, time, section_id } = req.body;

const lesson = createLesson({
name,
progress,
type,
content,
description,
time,
section_id,
});
res.status(201).json(lesson);
});

// Get details of a specific lesson
export const lessonDetails = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const lesson = await findLessonById(parseInt(req.params.id))

if (!lesson) {
res.status(404).json({ message: 'Lesson not found' });
return;
}

res.json(lesson);
});

export const lessonUpdateGet = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const lesson = await findLessonById(parseInt(req.params.id));

if (!lesson) {
res.status(404).json({ message: 'Lesson not found' });
return;
}

// You can return an HTML form here if you're rendering views
// For now, let's return the lesson data as JSON
res.json(lesson);
});

// Update an existing lesson
export const lessonUpdatePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const lesson = await findLessonById(parseInt(req.params.id))

if (!lesson) {
res.status(404).json({ message: 'Lesson not found' });
return;
}

const { name, progress, type, content, description, time } = req.body;

lesson.name = name;
lesson.progress = progress;
lesson.type = type;
lesson.content = content;
lesson.description = description;
lesson.time = time;

await saveLesson(lesson)
res.json(lesson);
});

// Delete a lesson
export const lessonDeletePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const lesson = await findLessonById(parseInt(req.params.id))

if (!lesson) {
res.status(404).json({ message: 'Lesson not found' });
return;
}

await deleteLesson(lesson)
res.status(204).send(); // No content to send back
});
78 changes: 78 additions & 0 deletions src/controller/payment.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Request, Response } from 'express';
import asyncHandler from 'express-async-handler';
import { createPayment, deletePayment, findPaymentById, getAllPayments, savePayment } from '../service/payment.service';

// Get the list of payments
export const paymentList = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const payments = await getAllPayments();
res.json(payments);
});

export const paymentCreateGet = asyncHandler(async (req: Request, res: Response): Promise<void> => {
// You can return an HTML form here if you're rendering views
res.json({ message: 'Ready to create a new payment' });
});

// Create a new payment
export const paymentCreatePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const { user_id, course_id, amount, payment_date, status } = req.body;
const payment = await createPayment({ user_id, course_id, amount, payment_date, status })
res.status(201).json(payment);
});

// Get details of a specific payment
export const paymentDetails = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const payment = await findPaymentById(parseInt(req.params.id))

if (!payment) {
res.status(404).json({ message: 'Payment not found' });
return;
}

res.json(payment);
});

export const paymentUpdateGet = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const payment = await findPaymentById(parseInt(req.params.id));

if (!payment) {
res.status(404).json({ message: 'Payment not found' });
return;
}

// You can return an HTML form here if you're rendering views
// For now, let's return the payment data as JSON
res.json(payment);
});

// Update an existing payment
export const paymentUpdatePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const payment = await findPaymentById(parseInt(req.params.id))

if (!payment) {
res.status(404).json({ message: 'Payment not found' });
return;
}

const { amount, payment_date, status } = req.body;

payment.amount = amount;
payment.payment_date = payment_date;
payment.status = status;

await savePayment(payment)
res.json(payment);
});

// Delete a payment
export const paymentDeletePost = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const payment = await findPaymentById(parseInt(req.params.id))

if (!payment) {
res.status(404).json({ message: 'Payment not found' });
return;
}

await deletePayment(payment)
res.status(204).send(); // No content to send back
});
Loading