-
Notifications
You must be signed in to change notification settings - Fork 17
/
admin.HR.go
68 lines (49 loc) · 1.46 KB
/
admin.HR.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package company
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func getAllHRHandler(ctx *gin.Context) {
var HRs []CompanyHR
cid, err := strconv.ParseUint(ctx.Param("cid"), 10, 64)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = getAllHR(ctx, &HRs, uint(cid))
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
ctx.JSON(http.StatusOK, HRs)
}
func deleteHRHandler(ctx *gin.Context) {
hrid, err := strconv.ParseUint(ctx.Param("hrid"), 10, 64)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = deleteHR(ctx, uint(hrid))
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
logrus.Infof("An HR with id %d is deleted", hrid)
ctx.JSON(http.StatusOK, gin.H{"status": "Successfully deleted"})
}
func addHRHandler(ctx *gin.Context) {
var addHRRequest CompanyHR
if err := ctx.ShouldBindJSON(&addHRRequest); err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err := addHR(ctx, &addHRRequest)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
logrus.Infof("An HR %s is added with id %d", addHRRequest.Name, addHRRequest.ID)
ctx.JSON(http.StatusOK, gin.H{"status": "Successfully added"})
}