-
Notifications
You must be signed in to change notification settings - Fork 4
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
PluckySquirrel
wants to merge
1
commit into
awesome-academy:master
Choose a base branch
from
PluckySquirrel:crud_admin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Admin panel #17
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
|
||
// 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?