Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions internal/sbi/api_student.go
Original file line number Diff line number Diff line change
@@ -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,
})
}
3 changes: 3 additions & 0 deletions internal/sbi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
17 changes: 17 additions & 0 deletions internal/sbi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}