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:
2026-08-24 22:21:12 +09:00
parent dadd14feb1
commit 3f452468d6
32 changed files with 5466 additions and 279 deletions
+113
View File
@@ -1,7 +1,10 @@
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"
)
@@ -23,6 +26,61 @@ func (h *HomeHandler) GetResearchProjects(c *gin.Context) {
httpx.OK(c, projects)
}
func (h *HomeHandler) CreateResearchProject(c *gin.Context) {
var req models.ResearchProject
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.Slug == "" || req.Title == "" || req.Abstract == "" {
httpx.BadRequest(c, "slug, title, and abstract are required")
return
}
id, err := h.repo.CreateResearchProject(c.Request.Context(), req)
if err != nil {
httpx.InternalServerError(c, "Failed to create research project: "+err.Error())
return
}
req.ID = id
httpx.Created(c, req)
}
func (h *HomeHandler) UpdateResearchProject(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid project ID")
return
}
var req models.ResearchProject
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.Slug == "" || req.Title == "" || req.Abstract == "" {
httpx.BadRequest(c, "slug, title, and abstract are required")
return
}
req.ID = id
if err := h.repo.UpdateResearchProject(c.Request.Context(), id, req); err != nil {
httpx.InternalServerError(c, "Failed to update research project: "+err.Error())
return
}
httpx.OK(c, req)
}
func (h *HomeHandler) DeleteResearchProject(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid project ID")
return
}
if err := h.repo.DeleteResearchProject(c.Request.Context(), id); err != nil {
httpx.InternalServerError(c, "Failed to delete research project: "+err.Error())
return
}
httpx.NoContent(c)
}
func (h *HomeHandler) GetResearchAreas(c *gin.Context) {
areas, err := h.repo.GetResearchAreas(c.Request.Context())
if err != nil {
@@ -32,6 +90,61 @@ func (h *HomeHandler) GetResearchAreas(c *gin.Context) {
httpx.OK(c, areas)
}
func (h *HomeHandler) CreateResearchArea(c *gin.Context) {
var req models.ResearchArea
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.NameEn == "" {
httpx.BadRequest(c, "name_en is required")
return
}
id, err := h.repo.CreateResearchArea(c.Request.Context(), req)
if err != nil {
httpx.InternalServerError(c, "Failed to create research area: "+err.Error())
return
}
req.ID = id
httpx.Created(c, req)
}
func (h *HomeHandler) UpdateResearchArea(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid area ID")
return
}
var req models.ResearchArea
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.NameEn == "" {
httpx.BadRequest(c, "name_en is required")
return
}
req.ID = id
if err := h.repo.UpdateResearchArea(c.Request.Context(), id, req); err != nil {
httpx.InternalServerError(c, "Failed to update research area: "+err.Error())
return
}
httpx.OK(c, req)
}
func (h *HomeHandler) DeleteResearchArea(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid area ID")
return
}
if err := h.repo.DeleteResearchArea(c.Request.Context(), id); err != nil {
httpx.InternalServerError(c, "Failed to delete research area: "+err.Error())
return
}
httpx.NoContent(c)
}
func (h *HomeHandler) GetStatsSummary(c *gin.Context) {
stats, err := h.repo.GetStatsSummary(c.Request.Context())
if err != nil {
+124
View File
@@ -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)
}
+143
View File
@@ -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 validMemberDegrees = map[string]bool{
"Professor": true,
"PhD": true,
"PhDCandidate": true,
"PhDStudent": true,
"MSCandidate": true,
"MSStudent": true,
}
var validAlumniDegrees = map[string]bool{
"PhD": true,
"MS": true,
}
type MembersHandler struct {
repo *repository.MembersRepository
}
@@ -23,6 +40,69 @@ func (h *MembersHandler) GetMembers(c *gin.Context) {
httpx.OK(c, members)
}
func (h *MembersHandler) CreateMember(c *gin.Context) {
var req models.Member
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.NameKo == "" || req.NameEn == "" {
httpx.BadRequest(c, "name_ko and name_en are required")
return
}
if !validMemberDegrees[req.Degree] {
httpx.BadRequest(c, "degree must be one of: Professor, PhD, PhDCandidate, PhDStudent, MSCandidate, MSStudent")
return
}
id, err := h.repo.CreateMember(c.Request.Context(), req)
if err != nil {
httpx.InternalServerError(c, "Failed to create member: "+err.Error())
return
}
req.ID = id
httpx.Created(c, req)
}
func (h *MembersHandler) UpdateMember(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid member ID")
return
}
var req models.Member
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.NameKo == "" || req.NameEn == "" {
httpx.BadRequest(c, "name_ko and name_en are required")
return
}
if !validMemberDegrees[req.Degree] {
httpx.BadRequest(c, "degree must be one of: Professor, PhD, PhDCandidate, PhDStudent, MSCandidate, MSStudent")
return
}
req.ID = id
if err := h.repo.UpdateMember(c.Request.Context(), id, req); err != nil {
httpx.InternalServerError(c, "Failed to update member: "+err.Error())
return
}
httpx.OK(c, req)
}
func (h *MembersHandler) DeleteMember(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid member ID")
return
}
if err := h.repo.DeleteMember(c.Request.Context(), id); err != nil {
httpx.InternalServerError(c, "Failed to delete member: "+err.Error())
return
}
httpx.NoContent(c)
}
func (h *MembersHandler) GetAlumni(c *gin.Context) {
alumni, err := h.repo.GetAlumni(c.Request.Context())
if err != nil {
@@ -31,3 +111,66 @@ func (h *MembersHandler) GetAlumni(c *gin.Context) {
}
httpx.OK(c, alumni)
}
func (h *MembersHandler) CreateAlumnus(c *gin.Context) {
var req models.Alumnus
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.NameKo == "" || req.NameEn == "" || req.GraduatedAt == "" {
httpx.BadRequest(c, "name_ko, name_en, and graduated_at are required")
return
}
if !validAlumniDegrees[req.Degree] {
httpx.BadRequest(c, "degree must be one of: PhD, MS")
return
}
id, err := h.repo.CreateAlumnus(c.Request.Context(), req)
if err != nil {
httpx.InternalServerError(c, "Failed to create alumnus: "+err.Error())
return
}
req.ID = id
httpx.Created(c, req)
}
func (h *MembersHandler) UpdateAlumnus(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid alumnus ID")
return
}
var req models.Alumnus
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.NameKo == "" || req.NameEn == "" || req.GraduatedAt == "" {
httpx.BadRequest(c, "name_ko, name_en, and graduated_at are required")
return
}
if !validAlumniDegrees[req.Degree] {
httpx.BadRequest(c, "degree must be one of: PhD, MS")
return
}
req.ID = id
if err := h.repo.UpdateAlumnus(c.Request.Context(), id, req); err != nil {
httpx.InternalServerError(c, "Failed to update alumnus: "+err.Error())
return
}
httpx.OK(c, req)
}
func (h *MembersHandler) DeleteAlumnus(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid alumnus ID")
return
}
if err := h.repo.DeleteAlumnus(c.Request.Context(), id); err != nil {
httpx.InternalServerError(c, "Failed to delete alumnus: "+err.Error())
return
}
httpx.NoContent(c)
}
+133 -7
View File
@@ -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 validPubCategories = map[string]bool{
"intl-journal-conf": true,
"domestic-journal-conf": true,
}
type PublicationsHandler struct {
repo *repository.PublicationsRepository
}
@@ -16,8 +24,8 @@ func NewPublicationsHandler(repo *repository.PublicationsRepository) *Publicatio
func (h *PublicationsHandler) GetPublications(c *gin.Context) {
category := c.Query("category")
if category != "" && category != "intl-journal-conf" && category != "domestic-journal-conf" {
httpx.BadRequest(c, "Invalid category parameter: must be 'intl-journal-conf' or 'domestic-journal-conf'")
if category != "" && !validPubCategories[category] {
httpx.BadRequest(c, "Invalid category: must be 'intl-journal-conf' or 'domestic-journal-conf'")
return
}
@@ -29,13 +37,76 @@ func (h *PublicationsHandler) GetPublications(c *gin.Context) {
httpx.OK(c, pubs)
}
func (h *PublicationsHandler) GetHighlights(c *gin.Context) {
highlights, err := h.repo.GetHighlights(c.Request.Context())
if err != nil {
httpx.InternalServerError(c, "Failed to retrieve highlights: "+err.Error())
func (h *PublicationsHandler) CreatePublication(c *gin.Context) {
var req models.Publication
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
httpx.OK(c, highlights)
if req.Title == "" || req.Venue == "" || req.PublishedAt == "" {
httpx.BadRequest(c, "title, venue, and published_at are required")
return
}
if !validPubCategories[req.Category] {
httpx.BadRequest(c, "category must be 'intl-journal-conf' or 'domestic-journal-conf'")
return
}
id, err := h.repo.CreatePublication(c.Request.Context(), req)
if err != nil {
httpx.InternalServerError(c, "Failed to create publication: "+err.Error())
return
}
req.ID = id
httpx.Created(c, req)
}
func (h *PublicationsHandler) UpdatePublication(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid publication ID")
return
}
var req models.Publication
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.Title == "" || req.Venue == "" || req.PublishedAt == "" {
httpx.BadRequest(c, "title, venue, and published_at are required")
return
}
if !validPubCategories[req.Category] {
httpx.BadRequest(c, "category must be 'intl-journal-conf' or 'domestic-journal-conf'")
return
}
req.ID = id
if err := h.repo.UpdatePublication(c.Request.Context(), id, req); err != nil {
httpx.InternalServerError(c, "Failed to update publication: "+err.Error())
return
}
httpx.OK(c, req)
}
func (h *PublicationsHandler) DeletePublication(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid publication ID")
return
}
if err := h.repo.DeletePublication(c.Request.Context(), id); err != nil {
httpx.InternalServerError(c, "Failed to delete publication: "+err.Error())
return
}
httpx.NoContent(c)
}
func (h *PublicationsHandler) GetHighlights(c *gin.Context) {
pubs, err := h.repo.GetHighlights(c.Request.Context())
if err != nil {
httpx.InternalServerError(c, "Failed to retrieve highlight publications: "+err.Error())
return
}
httpx.OK(c, pubs)
}
func (h *PublicationsHandler) GetPatents(c *gin.Context) {
@@ -46,3 +117,58 @@ func (h *PublicationsHandler) GetPatents(c *gin.Context) {
}
httpx.OK(c, patents)
}
func (h *PublicationsHandler) CreatePatent(c *gin.Context) {
var req models.Patent
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.Title == "" || req.Inventors == "" || req.ApplicationNo == "" || req.ApplicationAt == "" || req.Country == "" || req.PublishedAt == "" {
httpx.BadRequest(c, "title, inventors, application_no, application_at, country, and published_at are required")
return
}
id, err := h.repo.CreatePatent(c.Request.Context(), req)
if err != nil {
httpx.InternalServerError(c, "Failed to create patent: "+err.Error())
return
}
req.ID = id
httpx.Created(c, req)
}
func (h *PublicationsHandler) UpdatePatent(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid patent ID")
return
}
var req models.Patent
if err := c.ShouldBindJSON(&req); err != nil {
httpx.BadRequest(c, "Invalid request body: "+err.Error())
return
}
if req.Title == "" || req.Inventors == "" || req.ApplicationNo == "" || req.ApplicationAt == "" || req.Country == "" || req.PublishedAt == "" {
httpx.BadRequest(c, "title, inventors, application_no, application_at, country, and published_at are required")
return
}
req.ID = id
if err := h.repo.UpdatePatent(c.Request.Context(), id, req); err != nil {
httpx.InternalServerError(c, "Failed to update patent: "+err.Error())
return
}
httpx.OK(c, req)
}
func (h *PublicationsHandler) DeletePatent(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil || id <= 0 {
httpx.BadRequest(c, "Invalid patent ID")
return
}
if err := h.repo.DeletePatent(c.Request.Context(), id); err != nil {
httpx.InternalServerError(c, "Failed to delete patent: "+err.Error())
return
}
httpx.NoContent(c)
}
@@ -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)
}