feat(console,api): implement /console Admin Dashboard and Go backend full CRUD REST APIs
- Add comprehensive /console admin web UI for managing research projects, areas, members, publications, patents, lectures, and standards - Implement Admin token authentication middleware (RequireAdminToken) with Bearer token validation - Implement POST, PUT, DELETE REST API endpoints for all database entities across 5 domains - Add typed admin API client in refer_landing_page/lib/adminApi.ts with localStorage session persistence - Enhance E2E test runner to manage backend server lifecycle during automated tests - Pass all 12 quality gates cleanly with unanimous reviewer PASS verdicts
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.godopu.com/lab/landing_page/backend/internal/httpx"
|
||||
"git.godopu.com/lab/landing_page/backend/internal/models"
|
||||
"git.godopu.com/lab/landing_page/backend/internal/repository"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var validTerms = map[string]bool{
|
||||
"Spring": true,
|
||||
"Fall": true,
|
||||
}
|
||||
|
||||
type LecturesHandler struct {
|
||||
repo *repository.LecturesRepository
|
||||
}
|
||||
@@ -22,3 +30,119 @@ func (h *LecturesHandler) GetSemesters(c *gin.Context) {
|
||||
}
|
||||
httpx.OK(c, semesters)
|
||||
}
|
||||
|
||||
func (h *LecturesHandler) CreateSemester(c *gin.Context) {
|
||||
var req models.Semester
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httpx.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Year < 1970 || !validTerms[req.Term] {
|
||||
httpx.BadRequest(c, "Valid year and term ('Spring' or 'Fall') are required")
|
||||
return
|
||||
}
|
||||
id, err := h.repo.CreateSemester(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
httpx.InternalServerError(c, "Failed to create semester: "+err.Error())
|
||||
return
|
||||
}
|
||||
req.ID = id
|
||||
httpx.Created(c, req)
|
||||
}
|
||||
|
||||
func (h *LecturesHandler) UpdateSemester(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil || id <= 0 {
|
||||
httpx.BadRequest(c, "Invalid semester ID")
|
||||
return
|
||||
}
|
||||
var req models.Semester
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httpx.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Year < 1970 || !validTerms[req.Term] {
|
||||
httpx.BadRequest(c, "Valid year and term ('Spring' or 'Fall') are required")
|
||||
return
|
||||
}
|
||||
req.ID = id
|
||||
if err := h.repo.UpdateSemester(c.Request.Context(), id, req); err != nil {
|
||||
httpx.InternalServerError(c, "Failed to update semester: "+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OK(c, req)
|
||||
}
|
||||
|
||||
func (h *LecturesHandler) DeleteSemester(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil || id <= 0 {
|
||||
httpx.BadRequest(c, "Invalid semester ID")
|
||||
return
|
||||
}
|
||||
if err := h.repo.DeleteSemester(c.Request.Context(), id); err != nil {
|
||||
httpx.InternalServerError(c, "Failed to delete semester: "+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.NoContent(c)
|
||||
}
|
||||
|
||||
func (h *LecturesHandler) CreateCourse(c *gin.Context) {
|
||||
semesterID, err := strconv.Atoi(c.Param("semesterId"))
|
||||
if err != nil || semesterID <= 0 {
|
||||
httpx.BadRequest(c, "Invalid semesterId parameter")
|
||||
return
|
||||
}
|
||||
var req models.Course
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httpx.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Code == "" || req.NameEn == "" {
|
||||
httpx.BadRequest(c, "code and name_en are required")
|
||||
return
|
||||
}
|
||||
req.SemesterID = semesterID
|
||||
id, err := h.repo.CreateCourse(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
httpx.InternalServerError(c, "Failed to create course: "+err.Error())
|
||||
return
|
||||
}
|
||||
req.ID = id
|
||||
httpx.Created(c, req)
|
||||
}
|
||||
|
||||
func (h *LecturesHandler) UpdateCourse(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil || id <= 0 {
|
||||
httpx.BadRequest(c, "Invalid course ID")
|
||||
return
|
||||
}
|
||||
var req models.Course
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httpx.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Code == "" || req.NameEn == "" {
|
||||
httpx.BadRequest(c, "code and name_en are required")
|
||||
return
|
||||
}
|
||||
req.ID = id
|
||||
if err := h.repo.UpdateCourse(c.Request.Context(), id, req); err != nil {
|
||||
httpx.InternalServerError(c, "Failed to update course: "+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OK(c, req)
|
||||
}
|
||||
|
||||
func (h *LecturesHandler) DeleteCourse(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil || id <= 0 {
|
||||
httpx.BadRequest(c, "Invalid course ID")
|
||||
return
|
||||
}
|
||||
if err := h.repo.DeleteCourse(c.Request.Context(), id); err != nil {
|
||||
httpx.InternalServerError(c, "Failed to delete course: "+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.NoContent(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user