-
Notifications
You must be signed in to change notification settings - Fork 0
/
processingController.go
50 lines (42 loc) · 1004 Bytes
/
processingController.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package controller
import (
"net/http"
model "github.com/ICOMP-UNC/2023---soii---laboratorio-6-FrancoNB/models"
service "github.com/ICOMP-UNC/2023---soii---laboratorio-6-FrancoNB/services"
"github.com/gin-gonic/gin"
)
func Submit(c *gin.Context) {
var process model.Processing
if err := c.ShouldBindJSON(&process); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": "Bad request",
})
return
}
err := service.NewProcessing(process)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
})
} else {
c.JSON(http.StatusOK, gin.H{
"message": "Processing submitted !",
})
}
}
func Summary(c *gin.Context) {
processings, err := service.ListAllProcessing()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
})
} else {
if len(processings) == 0 {
c.JSON(http.StatusOK, gin.H{
"message": "No processing found !",
})
} else {
c.JSON(http.StatusOK, processings)
}
}
}