Archived
init
This commit is contained in:
commit
3d1d4cf506
53 files changed
+7105
No files matched your search
@@ -0,0 +1,100 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"exam_registration/internal/model"
|
||||
"exam_registration/internal/service"
|
||||
"exam_registration/pkg/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ExamHandler struct {
|
||||
examService *service.ExamService
|
||||
}
|
||||
|
||||
func NewExamHandler() *ExamHandler {
|
||||
return &ExamHandler{
|
||||
examService: &service.ExamService{},
|
||||
}
|
||||
}
|
||||
|
||||
// CreateExam 创建考试
|
||||
func (h *ExamHandler) CreateExam(c *gin.Context) {
|
||||
var exam model.Exam
|
||||
if err := c.ShouldBindJSON(&exam); err != nil {
|
||||
response.Error(c, response.BAD_REQUEST, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
userID, _ := c.Get("user_id")
|
||||
exam.CreatorID = userID.(uint64)
|
||||
|
||||
if err := h.examService.CreateExam(&exam); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, exam)
|
||||
}
|
||||
|
||||
// GetExamByID 获取考试详情
|
||||
func (h *ExamHandler) GetExamByID(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
exam, err := h.examService.GetExamByID(id)
|
||||
if err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, exam)
|
||||
}
|
||||
|
||||
// GetExamList 获取考试列表
|
||||
func (h *ExamHandler) GetExamList(c *gin.Context) {
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("pageSize", "10"))
|
||||
|
||||
exams, total, err := h.examService.GetExamList(page, pageSize)
|
||||
if err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, gin.H{
|
||||
"list": exams,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateExam 更新考试
|
||||
func (h *ExamHandler) UpdateExam(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
var updates map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&updates); err != nil {
|
||||
response.Error(c, response.BAD_REQUEST, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.examService.UpdateExam(id, updates); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, nil)
|
||||
}
|
||||
|
||||
// DeleteExam 删除考试
|
||||
func (h *ExamHandler) DeleteExam(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
if err := h.examService.DeleteExam(id); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, nil)
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"exam_registration/internal/model"
|
||||
"exam_registration/internal/service"
|
||||
"exam_registration/pkg/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type NoticeHandler struct {
|
||||
noticeService *service.NoticeService
|
||||
}
|
||||
|
||||
func NewNoticeHandler() *NoticeHandler {
|
||||
return &NoticeHandler{
|
||||
noticeService: &service.NoticeService{},
|
||||
}
|
||||
}
|
||||
|
||||
// CreateNotice 创建通知
|
||||
func (h *NoticeHandler) CreateNotice(c *gin.Context) {
|
||||
var notice model.ExamNotice
|
||||
if err := c.ShouldBindJSON(¬ice); err != nil {
|
||||
response.Error(c, response.BAD_REQUEST, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
userID, _ := c.Get("user_id")
|
||||
notice.PublisherID = userID.(uint64)
|
||||
|
||||
if err := h.noticeService.CreateNotice(¬ice); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, notice)
|
||||
}
|
||||
|
||||
// GetNoticeByID 获取通知详情
|
||||
func (h *NoticeHandler) GetNoticeByID(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
notice, err := h.noticeService.GetNoticeByID(id)
|
||||
if err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, notice)
|
||||
}
|
||||
|
||||
// GetNoticeList 获取通知列表
|
||||
func (h *NoticeHandler) GetNoticeList(c *gin.Context) {
|
||||
examIDStr := c.Query("exam_id")
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("pageSize", "10"))
|
||||
|
||||
var examID int
|
||||
if examIDStr != "" {
|
||||
examID, _ = strconv.Atoi(examIDStr)
|
||||
}
|
||||
|
||||
notices, total, err := h.noticeService.GetNoticeList(examID, page, pageSize)
|
||||
if err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, gin.H{
|
||||
"list": notices,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateNotice 更新通知
|
||||
func (h *NoticeHandler) UpdateNotice(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
var updates map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&updates); err != nil {
|
||||
response.Error(c, response.BAD_REQUEST, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.noticeService.UpdateNotice(id, updates); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, nil)
|
||||
}
|
||||
|
||||
// DeleteNotice 删除通知
|
||||
func (h *NoticeHandler) DeleteNotice(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
if err := h.noticeService.DeleteNotice(id); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, nil)
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"exam_registration/internal/service"
|
||||
"exam_registration/pkg/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type RegistrationHandler struct {
|
||||
registrationService *service.RegistrationService
|
||||
}
|
||||
|
||||
func NewRegistrationHandler() *RegistrationHandler {
|
||||
return &RegistrationHandler{
|
||||
registrationService: &service.RegistrationService{},
|
||||
}
|
||||
}
|
||||
|
||||
// CreateRegistration 创建报名
|
||||
func (h *RegistrationHandler) CreateRegistration(c *gin.Context) {
|
||||
userID, _ := c.Get("user_id")
|
||||
|
||||
var req struct {
|
||||
ExamID uint64 `json:"exam_id" binding:"required"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.BAD_REQUEST, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.registrationService.CreateRegistration(userID.(uint64), req.ExamID, req.Remark); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, nil)
|
||||
}
|
||||
|
||||
// GetRegistrationList 获取报名列表
|
||||
func (h *RegistrationHandler) GetRegistrationList(c *gin.Context) {
|
||||
userIDStr := c.Query("user_id")
|
||||
examIDStr := c.Query("exam_id")
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("pageSize", "10"))
|
||||
|
||||
var userID, examID int
|
||||
if userIDStr != "" {
|
||||
userID, _ = strconv.Atoi(userIDStr)
|
||||
}
|
||||
if examIDStr != "" {
|
||||
examID, _ = strconv.Atoi(examIDStr)
|
||||
}
|
||||
|
||||
registrations, total, err := h.registrationService.GetRegistrationList(userID, examID, page, pageSize)
|
||||
if err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, gin.H{
|
||||
"list": registrations,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
// AuditRegistration 审核报名
|
||||
func (h *RegistrationHandler) AuditRegistration(c *gin.Context) {
|
||||
regID, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
var req struct {
|
||||
Status int `json:"status" binding:"required"` // 1:通过,2:拒绝
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.BAD_REQUEST, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.registrationService.AuditRegistration(regID, req.Status, req.Comment); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, nil)
|
||||
}
|
||||
|
||||
// UpdateRegistration 更新报名信息
|
||||
func (h *RegistrationHandler) UpdateRegistration(c *gin.Context) {
|
||||
regID, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
var updates map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&updates); err != nil {
|
||||
response.Error(c, response.BAD_REQUEST, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.registrationService.UpdateRegistration(regID, updates); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, nil)
|
||||
}
|
||||
|
||||
// DeleteRegistration 取消报名
|
||||
func (h *RegistrationHandler) DeleteRegistration(c *gin.Context) {
|
||||
regID, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
if err := h.registrationService.DeleteRegistration(regID); err != nil {
|
||||
response.Error(c, response.ERROR, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, nil)
|
||||
}
|
||||
Loaded 3 of 53 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user