finish
This commit is contained in:
@@ -31,7 +31,7 @@ func SaveArticleHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
colMap := models.MapJ2c[models.BackArticle](jsonMap, true)
|
||||
if ok := article.SaveArticle(colMap); !ok {
|
||||
if ok := article.SaveArticle(claims, colMap); !ok {
|
||||
ServerErr(c, "Save Failed")
|
||||
return
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func ListArticlesByUser(c *gin.Context) {
|
||||
func DeleteArticleHandler(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
if claims.Role == global.ROLE_ID_MAP["ADMIN"] {
|
||||
if claims.Role != global.ROLE_ID_MAP["ADMIN"] {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func GetArticleHandler(c *gin.Context) {
|
||||
func PublishArticleHandler(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
if claims.Role == global.ROLE_ID_MAP["ADMIN"] {
|
||||
if claims.Role != global.ROLE_ID_MAP["ADMIN"] {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"nCovTrack-Backend/global"
|
||||
"nCovTrack-Backend/service/management"
|
||||
"nCovTrack-Backend/utils"
|
||||
"strconv"
|
||||
@@ -8,8 +9,20 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
//PullContactHandler pull contact from faker
|
||||
// @Tags Management
|
||||
// @Produce json
|
||||
// @Summary pull contact from faker
|
||||
// @Success 200 {object} utils.GinResponse
|
||||
// @Router /management/faker/{patientId} [get]
|
||||
// @Param Token header string true "Token"
|
||||
// @Param patientId path int true "Patient Id"
|
||||
func PullContactHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
if claims.Role != global.ROLE_ID_MAP["ADMIN"] {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
patientId, _ := strconv.Atoi(c.Param("patientId"))
|
||||
rowsAffected := management.PullFromFaker(claims, patientId)
|
||||
if rowsAffected == -1 {
|
||||
@@ -19,13 +32,82 @@ func PullContactHandler(c *gin.Context) {
|
||||
utils.Succ(c, map[string]interface{}{"pullAmount": rowsAffected})
|
||||
}
|
||||
|
||||
//GetObservationHandler get observation's info
|
||||
// @Tags Management
|
||||
// @Produce json
|
||||
// @Summary get observation's info
|
||||
// @Success 200 {object} utils.GinResponse{data=models.BackObservation}
|
||||
// @Router /management/observation/{id} [get]
|
||||
// @Param token header string true "token"
|
||||
// @Param id path int true "id"
|
||||
func GetObservationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
allowRows := []int{global.ROLE_ID_MAP["ADMIN"], global.ROLE_ID_MAP["WORKER"], global.ROLE_ID_MAP["VOLUNTEER"]}
|
||||
if !utils.Contains(allowRows, claims.Role) {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
utils.Succ(c, management.GetObservation(id))
|
||||
}
|
||||
|
||||
//ListObservationsHandler list observations by query
|
||||
// @Tags Management
|
||||
// @Produce json
|
||||
// @Summary list observations by query
|
||||
// @Success 200 {object} utils.GinResponse{data=[]models.ListObservation}
|
||||
// @Router /management/observation/ [get]
|
||||
// @Param Token header string true "token"
|
||||
// @Param queries query models.BackObservation true "queries"
|
||||
func ListObservationsHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
allowRows := []int{global.ROLE_ID_MAP["ADMIN"], global.ROLE_ID_MAP["WORKER"], global.ROLE_ID_MAP["VOLUNTEER"]}
|
||||
if !utils.Contains(allowRows, claims.Role) {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
jsonMap := bindQuery(c)
|
||||
utils.Succ(c, management.ListObservation(jsonMap))
|
||||
}
|
||||
|
||||
//TreeifyObservationHandler get transform chain by user
|
||||
// @Tags Management
|
||||
// @Produce json
|
||||
// @Summary get transform chain by user
|
||||
// @Success 200 {object} utils.GinResponse{data=models.TreeObservation}
|
||||
// @Router /management/observation/tree/{id}/{direction} [get]
|
||||
// @Param Token header string true "token"
|
||||
// @Param id path int true "id"
|
||||
// @Param direction path string true "direction" Enums(up, down, all)
|
||||
func TreeifyObservationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
allowRows := []int{global.ROLE_ID_MAP["ADMIN"], global.ROLE_ID_MAP["WORKER"], global.ROLE_ID_MAP["VOLUNTEER"]}
|
||||
if !utils.Contains(allowRows, claims.Role) {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
direction := c.Param("direction")
|
||||
tree := management.TreeifyObservations(id, direction)
|
||||
utils.Succ(c, tree)
|
||||
}
|
||||
|
||||
//InsertObservationHandler insert observation
|
||||
// @Tags Management
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Summary insert observation
|
||||
// @Success 200 {object} utils.GinResponse
|
||||
// @Router /management/observation/ [post]
|
||||
// @Param Observation body models.BackObservation true "observation"
|
||||
// @Param Token header string true "token"
|
||||
func InsertObservationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
allowRows := []int{global.ROLE_ID_MAP["ADMIN"], global.ROLE_ID_MAP["WORKER"]}
|
||||
if !utils.Contains(allowRows, claims.Role) {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
observaion := bindJson(c)
|
||||
delete(observaion, "id")
|
||||
ok := management.InsertObservation(claims, observaion)
|
||||
@@ -36,18 +118,65 @@ func InsertObservationHandler(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetObservationHandler(c *gin.Context) {
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
utils.Succ(c, management.GetObservation(id))
|
||||
//UpdateObservationHandler update observation
|
||||
// @Tags Management
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Summary update observation
|
||||
// @Success 200 {object} utils.GinResponse
|
||||
// @Router /management/observation/ [put]
|
||||
// @Param Observation body models.BackObservation true "observation"
|
||||
// @Param Token header string true "token"
|
||||
func UpdateObservationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
allowRows := []int{global.ROLE_ID_MAP["ADMIN"], global.ROLE_ID_MAP["WORKER"]}
|
||||
if !utils.Contains(allowRows, claims.Role) {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
observation := bindJson(c)
|
||||
ok := management.UpdateObservation(claims, observation)
|
||||
if ok {
|
||||
utils.Succ(c, nil)
|
||||
} else {
|
||||
OperationFailed(c)
|
||||
}
|
||||
}
|
||||
|
||||
//ListLocationHandler list locations
|
||||
// @Tags Management
|
||||
// @Produce json
|
||||
// @Summary list locations
|
||||
// @Success 200 {object} utils.GinResponse{data=models.BackLocation}
|
||||
// @Router /management/location/ [get]
|
||||
// @Param queries query models.BackLocation true "queries"
|
||||
// @Param Token header string true "token"
|
||||
func ListLocationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
allowRows := []int{global.ROLE_ID_MAP["ADMIN"], global.ROLE_ID_MAP["WORKER"], global.ROLE_ID_MAP["VOLUNTEER"]}
|
||||
if !utils.Contains(allowRows, claims.Role) {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
queryMap := bindQuery(c)
|
||||
utils.Succ(c, management.ListLocation(queryMap))
|
||||
}
|
||||
|
||||
//InsertLocationHandler insert location
|
||||
// @Tags Management
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Summary insert location
|
||||
// @Success 200 {object} utils.GinResponse
|
||||
// @Router /management/location/ [post]
|
||||
// @Param Location body models.BackLocation true "location"
|
||||
// @Param Token header string true "token"
|
||||
func InsertLocationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
if claims.Role != global.ROLE_ID_MAP["ADMIN"] {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
locationMap := bindJson(c)
|
||||
ok := management.InsertLocation(claims, locationMap)
|
||||
if ok {
|
||||
@@ -57,7 +186,20 @@ func InsertLocationHandler(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
//DeleteLocationHandler delete location
|
||||
// @Tags Management
|
||||
// @Produce json
|
||||
// @Summary delete location
|
||||
// @Success 200 {object} utils.GinResponse
|
||||
// @Router /management/location/{id} [delete]
|
||||
// @Param Token header string true "token"
|
||||
// @Param Id path int true "Id"
|
||||
func DeleteLocationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
if claims.Role != global.ROLE_ID_MAP["ADMIN"] {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
ok := management.DeleteLocation(id)
|
||||
if ok {
|
||||
@@ -66,3 +208,27 @@ func DeleteLocationHandler(c *gin.Context) {
|
||||
OperationFailed(c)
|
||||
}
|
||||
}
|
||||
|
||||
//InsertPcrHandler insert pcr record
|
||||
// @Tags Management
|
||||
// @Produce json
|
||||
// @Summary insert pcr record
|
||||
// @Success 200 {object} utils.GinResponse
|
||||
// @Router /management/pcr/ [post]
|
||||
// @Param Pcr body models.BackPcr true "Pcr"
|
||||
// @Param Token header string true "token"
|
||||
func InsertPcrHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
allowRows := []int{global.ROLE_ID_MAP["ADMIN"], global.ROLE_ID_MAP["WORKER"]}
|
||||
if !utils.Contains(allowRows, claims.Role) {
|
||||
Forbidden(c)
|
||||
return
|
||||
}
|
||||
jsonMap := bindJson(c)
|
||||
ok := management.InsertPcr(claims, jsonMap)
|
||||
if ok {
|
||||
utils.Succ(c, nil)
|
||||
} else {
|
||||
OperationFailed(c)
|
||||
}
|
||||
}
|
||||
|
||||
65
handler/notify.go
Normal file
65
handler/notify.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"nCovTrack-Backend/models"
|
||||
"nCovTrack-Backend/service/notify"
|
||||
"nCovTrack-Backend/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
//InsertNotificationHandler for test
|
||||
func InsertNotificationHandler(c *gin.Context) {
|
||||
sendNotify := models.SendInfo{Region: []string{"江苏 徐州"}, Channel: []int{1, 0}, Notification: models.BackNotification{Time: time.Now(), Kind: "测试", Content: "Test"}}
|
||||
notify.SendNotify(sendNotify)
|
||||
}
|
||||
|
||||
//CountNotificationHandler count the notification
|
||||
// @Tags Notification
|
||||
// @Produce json
|
||||
// @Summary count the notification
|
||||
// @Success 200 {object} utils.GinResponse
|
||||
// @Router /notify/count/ [get]
|
||||
// @Param Token header string true "token"
|
||||
func CountNotificationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
count := notify.QueryNotificationLen(claims.Region)
|
||||
utils.Succ(c, map[string]interface{}{"count": count})
|
||||
}
|
||||
|
||||
//ListNotificationHandler list the notifications in the range
|
||||
// @Tags Notification
|
||||
// @Produce json
|
||||
// @Summary list the notification in the range
|
||||
// @Success 200 {object} utils.GinResponse{data=[]models.BackNotification}
|
||||
// @Router /notify/{start}/{end} [get]
|
||||
// @Param Token header string true "token"
|
||||
// @Param start path int true "start"
|
||||
// @Param end path int true "end"
|
||||
func ListNotificationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
start, _ := strconv.Atoi(c.Param("start"))
|
||||
end, _ := strconv.Atoi(c.Param("end"))
|
||||
notifications := notify.ListNotifycation(claims.Region, start, end)
|
||||
utils.Succ(c, notifications)
|
||||
}
|
||||
|
||||
//DeleteNotificationHandler delete the notify by index
|
||||
// @Tags Notification
|
||||
// @Produce json
|
||||
// @Summary delete the notify by index, if -1 delete all
|
||||
// @Success 200 {object} utils.GinResponse
|
||||
// @Router /notify/{index} [delete]
|
||||
// @Param Token header string true "token"
|
||||
// @Param index path int true "index"
|
||||
func DeleteNotificationHandler(c *gin.Context) {
|
||||
claims := utils.ClaimsFromHeader(c)
|
||||
index, _ := strconv.Atoi(c.Param("index"))
|
||||
if index == -1 {
|
||||
notify.CleanNotification(claims.Region)
|
||||
}
|
||||
notify.DeleteNotification(claims.Region, index)
|
||||
utils.Succ(c, nil)
|
||||
}
|
||||
@@ -24,11 +24,13 @@ func UserRegisterHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
registered := user.NoDuplicatePhoneOrEmail(jsonMap["phone"].(string), jsonMap["email"].(string))
|
||||
if registered {
|
||||
if !registered {
|
||||
utils.Success(c, 200, 200, "Registered", nil)
|
||||
return
|
||||
}
|
||||
colMap := models.MapJ2c[models.BackUser](jsonMap, true)
|
||||
user.Register(colMap)
|
||||
utils.Succ(c, nil)
|
||||
}
|
||||
|
||||
//UserApproveHandler admin approve account
|
||||
|
||||
Reference in New Issue
Block a user