change worker id to serial

This commit is contained in:
simon987
2019-01-29 19:24:12 -05:00
parent 64152bfc08
commit 3a88642c5c
10 changed files with 71 additions and 67 deletions

View File

@@ -2,9 +2,9 @@ package api
import (
"github.com/Sirupsen/logrus"
"github.com/google/uuid"
"math/rand"
"src/task_tracker/storage"
"strconv"
"time"
)
@@ -34,8 +34,8 @@ type GetWorkerResponse struct {
}
type WorkerAccessRequest struct {
WorkerId *uuid.UUID `json:"worker_id"`
ProjectId int64 `json:"project_id"`
WorkerId int64 `json:"worker_id"`
ProjectId int64 `json:"project_id"`
}
type WorkerAccessResponse struct {
@@ -79,17 +79,27 @@ func (api *WebAPI) WorkerCreate(r *Request) {
func (api *WebAPI) WorkerGet(r *Request) {
id, err := uuid.Parse(r.Ctx.UserValue("id").(string))
id, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
if err != nil {
logrus.WithFields(logrus.Fields{
logrus.WithError(err).WithFields(logrus.Fields{
"id": id,
}).Warn("Invalid UUID")
}).Warn("Invalid worker id")
r.Json(GetWorkerResponse{
Ok: false,
Message: err.Error(),
}, 400)
return
} else if id <= 0 {
logrus.WithFields(logrus.Fields{
"id": id,
}).Warn("Invalid worker id")
r.Json(GetWorkerResponse{
Ok: false,
Message: "Invalid worker id",
}, 400)
return
}
worker := api.Database.GetWorker(id)
@@ -188,7 +198,6 @@ func (api *WebAPI) workerCreate(request *CreateWorkerRequest, identity *storage.
}
worker := storage.Worker{
Id: uuid.New(),
Created: time.Now().Unix(),
Identity: identity,
Secret: makeSecret(),