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,28 @@
|
||||
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 validScopes = map[string]bool{
|
||||
"international": true,
|
||||
"domestic": true,
|
||||
}
|
||||
|
||||
var validDocStatuses = map[string]bool{
|
||||
"IS": true,
|
||||
"TS": true,
|
||||
"TR": true,
|
||||
"CDV": true,
|
||||
"WDTR": true,
|
||||
"InProgress": true,
|
||||
}
|
||||
|
||||
type StandardizationHandler struct {
|
||||
repo *repository.StandardizationRepository
|
||||
}
|
||||
@@ -22,3 +39,135 @@ func (h *StandardizationHandler) GetStandardsBodies(c *gin.Context) {
|
||||
}
|
||||
httpx.OK(c, bodies)
|
||||
}
|
||||
|
||||
func (h *StandardizationHandler) CreateStandardsBody(c *gin.Context) {
|
||||
var req models.StandardsBody
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httpx.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Org == "" || req.FullName == "" || req.Period == "" {
|
||||
httpx.BadRequest(c, "org, full_name, and period are required")
|
||||
return
|
||||
}
|
||||
if !validScopes[req.Scope] {
|
||||
httpx.BadRequest(c, "scope must be 'international' or 'domestic'")
|
||||
return
|
||||
}
|
||||
id, err := h.repo.CreateStandardsBody(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
httpx.InternalServerError(c, "Failed to create standards body: "+err.Error())
|
||||
return
|
||||
}
|
||||
req.ID = id
|
||||
httpx.Created(c, req)
|
||||
}
|
||||
|
||||
func (h *StandardizationHandler) UpdateStandardsBody(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil || id <= 0 {
|
||||
httpx.BadRequest(c, "Invalid standards body ID")
|
||||
return
|
||||
}
|
||||
var req models.StandardsBody
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httpx.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Org == "" || req.FullName == "" || req.Period == "" {
|
||||
httpx.BadRequest(c, "org, full_name, and period are required")
|
||||
return
|
||||
}
|
||||
if !validScopes[req.Scope] {
|
||||
httpx.BadRequest(c, "scope must be 'international' or 'domestic'")
|
||||
return
|
||||
}
|
||||
req.ID = id
|
||||
if err := h.repo.UpdateStandardsBody(c.Request.Context(), id, req); err != nil {
|
||||
httpx.InternalServerError(c, "Failed to update standards body: "+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OK(c, req)
|
||||
}
|
||||
|
||||
func (h *StandardizationHandler) DeleteStandardsBody(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil || id <= 0 {
|
||||
httpx.BadRequest(c, "Invalid standards body ID")
|
||||
return
|
||||
}
|
||||
if err := h.repo.DeleteStandardsBody(c.Request.Context(), id); err != nil {
|
||||
httpx.InternalServerError(c, "Failed to delete standards body: "+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.NoContent(c)
|
||||
}
|
||||
|
||||
func (h *StandardizationHandler) CreateStandardDocument(c *gin.Context) {
|
||||
bodyID, err := strconv.Atoi(c.Param("bodyId"))
|
||||
if err != nil || bodyID <= 0 {
|
||||
httpx.BadRequest(c, "Invalid bodyId parameter")
|
||||
return
|
||||
}
|
||||
var req models.StandardDocument
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httpx.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.WG == "" || req.ProjectName == "" || req.Title == "" || req.DocRef == "" {
|
||||
httpx.BadRequest(c, "wg, project_name, title, and doc_ref are required")
|
||||
return
|
||||
}
|
||||
if !validDocStatuses[req.Status] {
|
||||
httpx.BadRequest(c, "status must be one of: IS, TS, TR, CDV, WDTR, InProgress")
|
||||
return
|
||||
}
|
||||
req.BodyID = bodyID
|
||||
id, err := h.repo.CreateStandardDocument(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
httpx.InternalServerError(c, "Failed to create standard document: "+err.Error())
|
||||
return
|
||||
}
|
||||
req.ID = id
|
||||
httpx.Created(c, req)
|
||||
}
|
||||
|
||||
func (h *StandardizationHandler) UpdateStandardDocument(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil || id <= 0 {
|
||||
httpx.BadRequest(c, "Invalid document ID")
|
||||
return
|
||||
}
|
||||
var req models.StandardDocument
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httpx.BadRequest(c, "Invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.WG == "" || req.ProjectName == "" || req.Title == "" || req.DocRef == "" {
|
||||
httpx.BadRequest(c, "wg, project_name, title, and doc_ref are required")
|
||||
return
|
||||
}
|
||||
if !validDocStatuses[req.Status] {
|
||||
httpx.BadRequest(c, "status must be one of: IS, TS, TR, CDV, WDTR, InProgress")
|
||||
return
|
||||
}
|
||||
req.ID = id
|
||||
if err := h.repo.UpdateStandardDocument(c.Request.Context(), id, req); err != nil {
|
||||
httpx.InternalServerError(c, "Failed to update standard document: "+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OK(c, req)
|
||||
}
|
||||
|
||||
func (h *StandardizationHandler) DeleteStandardDocument(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil || id <= 0 {
|
||||
httpx.BadRequest(c, "Invalid document ID")
|
||||
return
|
||||
}
|
||||
if err := h.repo.DeleteStandardDocument(c.Request.Context(), id); err != nil {
|
||||
httpx.InternalServerError(c, "Failed to delete standard document: "+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.NoContent(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user