diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..609bb40 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: CI Pipeline + +on: + push: + branches: [ main, feature/new-api ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Download dependencies + run: | + go mod tidy + go mod download + + - name: Build project + run: CGO_ENABLED=0 go build -o bin/nf ./cmd/main.go + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: nf-binary + path: bin/nf diff --git a/internal/sbi/api_student.go b/internal/sbi/api_student.go new file mode 100644 index 0000000..8677ae8 --- /dev/null +++ b/internal/sbi/api_student.go @@ -0,0 +1,38 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func GetStudentData(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "student": "Gilbert", + "semester": 7, + "university": "UDC", + "message": "Datos obtenidos correctamente", + }) +} + +type StudentRequest struct { + Name string `json:"name" binding:"required"` + Semester int `json:"semester"` + Career string `json:"career"` +} + +func RegisterStudent(c *gin.Context) { + var req StudentRequest + + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + + c.JSON(http.StatusCreated, gin.H{ + "status": "registrado correctamente", + "name": req.Name, + "semester": req.Semester, + "career": req.Career, + }) +} diff --git a/internal/sbi/router.go b/internal/sbi/router.go index b62139f..c595491 100644 --- a/internal/sbi/router.go +++ b/internal/sbi/router.go @@ -45,6 +45,9 @@ func newRouter(s *Server) *gin.Engine { spyFamilyGroup := router.Group("/spyfamily") applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute()) + studentGroup := router.Group("/student") + applyRoutes(studentGroup, s.getStudentRoute()) + return router } diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 0ac33fe..d052e5c 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -112,3 +112,20 @@ func (s *Server) shutdownHttpServer() { logger.SBILog.Errorf("HTTP server shutdown failed: %+v", err) } } + +func (s *Server) getStudentRoute() []Route { + return []Route{ + { + Name: "GetStudentData", + Method: "GET", + Pattern: "/data", + APIFunc: GetStudentData, + }, + { + Name: "RegisterStudent", + Method: "POST", + Pattern: "/register", + APIFunc: RegisterStudent, + }, + } +}