diff --git a/external/docs/docs.go b/external/docs/docs.go index d8b55f5..16b87f7 100644 --- a/external/docs/docs.go +++ b/external/docs/docs.go @@ -4457,9 +4457,9 @@ const docTemplate = `{ } } }, - "/user/{cid}/role": { - "post": { - "description": "Create a new user role", + "/user/{cid}/roles": { + "get": { + "description": "Get roles for the user logged in", "consumes": [ "application/json" ], @@ -4469,7 +4469,7 @@ const docTemplate = `{ "tags": [ "user-roles" ], - "summary": "Create a new user role", + "summary": "Get your roles", "parameters": [ { "type": "integer", @@ -4477,20 +4477,11 @@ const docTemplate = `{ "name": "cid", "in": "path", "required": true - }, - { - "description": "User Role", - "name": "user_role", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/user_role.Request" - } } ], "responses": { - "201": { - "description": "Created", + "200": { + "description": "OK", "schema": { "$ref": "#/definitions/user_role.Response" } @@ -4508,11 +4499,9 @@ const docTemplate = `{ } } } - } - }, - "/user/{cid}/role/": { - "get": { - "description": "Get roles for the user logged in", + }, + "post": { + "description": "Create a new user role", "consumes": [ "application/json" ], @@ -4522,7 +4511,7 @@ const docTemplate = `{ "tags": [ "user-roles" ], - "summary": "Get your roles", + "summary": "Create a new user role", "parameters": [ { "type": "integer", @@ -4530,11 +4519,20 @@ const docTemplate = `{ "name": "cid", "in": "path", "required": true + }, + { + "description": "User Role", + "name": "user_role", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/user_role.Request" + } } ], "responses": { - "200": { - "description": "OK", + "201": { + "description": "Created", "schema": { "$ref": "#/definitions/user_role.Response" } @@ -4554,7 +4552,7 @@ const docTemplate = `{ } } }, - "/user/{cid}/role/{role_id}": { + "/user/{cid}/roles/{role_id}": { "delete": { "description": "Remove a user role", "consumes": [ @@ -5159,6 +5157,10 @@ const docTemplate = `{ "type": "integer", "example": 1293257 }, + "assignee_name": { + "type": "string", + "example": "John Doe" + }, "created_at": { "type": "string", "example": "2021-01-01T00:00:00Z" @@ -5187,6 +5189,10 @@ const docTemplate = `{ "type": "integer", "example": 1293257 }, + "secondary_assignee_name": { + "type": "string", + "example": "Jane Doe" + }, "shifts": { "type": "boolean", "example": true @@ -5431,6 +5437,9 @@ const docTemplate = `{ "type": "integer", "example": 1 }, + "name": { + "type": "string" + }, "position_id": { "type": "integer", "example": 1 @@ -5944,6 +5953,9 @@ const docTemplate = `{ "type": "integer", "example": 1 }, + "name": { + "type": "string" + }, "position_id": { "type": "integer", "example": 1 @@ -6394,25 +6406,25 @@ const docTemplate = `{ "type": "string", "example": "2021-01-01T00:00:00Z" }, + "first_name": { + "type": "string", + "example": "John" + }, "id": { "type": "integer", "example": 1 }, + "last_name": { + "type": "string", + "example": "Doe" + }, "reason": { "type": "string", "example": "I want to transfer to ZDV" }, - "requestType": { + "request_type": { "$ref": "#/definitions/types.RequestType" }, - "requested_facility": { - "allOf": [ - { - "$ref": "#/definitions/constants.FacilityID" - } - ], - "example": "ZDV" - }, "status": { "$ref": "#/definitions/types.StatusType" }, diff --git a/external/docs/swagger.json b/external/docs/swagger.json index 6fc4e56..57a0475 100644 --- a/external/docs/swagger.json +++ b/external/docs/swagger.json @@ -4450,9 +4450,9 @@ } } }, - "/user/{cid}/role": { - "post": { - "description": "Create a new user role", + "/user/{cid}/roles": { + "get": { + "description": "Get roles for the user logged in", "consumes": [ "application/json" ], @@ -4462,7 +4462,7 @@ "tags": [ "user-roles" ], - "summary": "Create a new user role", + "summary": "Get your roles", "parameters": [ { "type": "integer", @@ -4470,20 +4470,11 @@ "name": "cid", "in": "path", "required": true - }, - { - "description": "User Role", - "name": "user_role", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/user_role.Request" - } } ], "responses": { - "201": { - "description": "Created", + "200": { + "description": "OK", "schema": { "$ref": "#/definitions/user_role.Response" } @@ -4501,11 +4492,9 @@ } } } - } - }, - "/user/{cid}/role/": { - "get": { - "description": "Get roles for the user logged in", + }, + "post": { + "description": "Create a new user role", "consumes": [ "application/json" ], @@ -4515,7 +4504,7 @@ "tags": [ "user-roles" ], - "summary": "Get your roles", + "summary": "Create a new user role", "parameters": [ { "type": "integer", @@ -4523,11 +4512,20 @@ "name": "cid", "in": "path", "required": true + }, + { + "description": "User Role", + "name": "user_role", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/user_role.Request" + } } ], "responses": { - "200": { - "description": "OK", + "201": { + "description": "Created", "schema": { "$ref": "#/definitions/user_role.Response" } @@ -4547,7 +4545,7 @@ } } }, - "/user/{cid}/role/{role_id}": { + "/user/{cid}/roles/{role_id}": { "delete": { "description": "Remove a user role", "consumes": [ @@ -5152,6 +5150,10 @@ "type": "integer", "example": 1293257 }, + "assignee_name": { + "type": "string", + "example": "John Doe" + }, "created_at": { "type": "string", "example": "2021-01-01T00:00:00Z" @@ -5180,6 +5182,10 @@ "type": "integer", "example": 1293257 }, + "secondary_assignee_name": { + "type": "string", + "example": "Jane Doe" + }, "shifts": { "type": "boolean", "example": true @@ -5424,6 +5430,9 @@ "type": "integer", "example": 1 }, + "name": { + "type": "string" + }, "position_id": { "type": "integer", "example": 1 @@ -5937,6 +5946,9 @@ "type": "integer", "example": 1 }, + "name": { + "type": "string" + }, "position_id": { "type": "integer", "example": 1 @@ -6387,25 +6399,25 @@ "type": "string", "example": "2021-01-01T00:00:00Z" }, + "first_name": { + "type": "string", + "example": "John" + }, "id": { "type": "integer", "example": 1 }, + "last_name": { + "type": "string", + "example": "Doe" + }, "reason": { "type": "string", "example": "I want to transfer to ZDV" }, - "requestType": { + "request_type": { "$ref": "#/definitions/types.RequestType" }, - "requested_facility": { - "allOf": [ - { - "$ref": "#/definitions/constants.FacilityID" - } - ], - "example": "ZDV" - }, "status": { "$ref": "#/definitions/types.StatusType" }, diff --git a/external/docs/swagger.yaml b/external/docs/swagger.yaml index f02482b..f5613b5 100644 --- a/external/docs/swagger.yaml +++ b/external/docs/swagger.yaml @@ -256,6 +256,9 @@ definitions: assignee: example: 1293257 type: integer + assignee_name: + example: John Doe + type: string created_at: example: "2021-01-01T00:00:00Z" type: string @@ -275,6 +278,9 @@ definitions: secondary_assignee: example: 1293257 type: integer + secondary_assignee_name: + example: Jane Doe + type: string shifts: example: true type: boolean @@ -452,6 +458,8 @@ definitions: id: example: 1 type: integer + name: + type: string position_id: example: 1 type: integer @@ -807,6 +815,8 @@ definitions: id: example: 1 type: integer + name: + type: string position_id: example: 1 type: integer @@ -1119,18 +1129,20 @@ definitions: created_at: example: "2021-01-01T00:00:00Z" type: string + first_name: + example: John + type: string id: example: 1 type: integer + last_name: + example: Doe + type: string reason: example: I want to transfer to ZDV type: string - requestType: + request_type: $ref: '#/definitions/types.RequestType' - requested_facility: - allOf: - - $ref: '#/definitions/constants.FacilityID' - example: ZDV status: $ref: '#/definitions/types.StatusType' updated_at: @@ -4332,28 +4344,22 @@ paths: summary: Update a rating change tags: - rating-change - /user/{cid}/role: - post: + /user/{cid}/roles: + get: consumes: - application/json - description: Create a new user role + description: Get roles for the user logged in parameters: - description: User CID in: path name: cid required: true type: integer - - description: User Role - in: body - name: user_role - required: true - schema: - $ref: '#/definitions/user_role.Request' produces: - application/json responses: - "201": - description: Created + "200": + description: OK schema: $ref: '#/definitions/user_role.Response' "400": @@ -4364,25 +4370,30 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/utils.ErrResponse' - summary: Create a new user role + summary: Get your roles tags: - user-roles - /user/{cid}/role/: - get: + post: consumes: - application/json - description: Get roles for the user logged in + description: Create a new user role parameters: - description: User CID in: path name: cid required: true type: integer + - description: User Role + in: body + name: user_role + required: true + schema: + $ref: '#/definitions/user_role.Request' produces: - application/json responses: - "200": - description: OK + "201": + description: Created schema: $ref: '#/definitions/user_role.Response' "400": @@ -4393,10 +4404,10 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/utils.ErrResponse' - summary: Get your roles + summary: Create a new user role tags: - user-roles - /user/{cid}/role/{role_id}: + /user/{cid}/roles/{role_id}: delete: consumes: - application/json diff --git a/external/v3/action-log/action_log.go b/external/v3/action-log/action_log.go index ff05e45..05d1f30 100644 --- a/external/v3/action-log/action_log.go +++ b/external/v3/action-log/action_log.go @@ -1,6 +1,7 @@ package action_log import ( + "encoding/json" "fmt" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" @@ -18,6 +19,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/disciplinary-log/disciplinary_log.go b/external/v3/disciplinary-log/disciplinary_log.go index b51a387..60ab347 100644 --- a/external/v3/disciplinary-log/disciplinary_log.go +++ b/external/v3/disciplinary-log/disciplinary_log.go @@ -1,6 +1,7 @@ package disciplinary_log import ( + "encoding/json" "fmt" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" @@ -19,6 +20,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/event/event_signup.go b/external/v3/event/event_signup.go index 2ada5b2..8f51e1a 100644 --- a/external/v3/event/event_signup.go +++ b/external/v3/event/event_signup.go @@ -23,17 +23,21 @@ import ( // @Router /facility/{FacilityID}/events/{EventID}/signups [post] func CreateEventSignup(w http.ResponseWriter, r *http.Request) { req := &EventSignupRequest{} - if err := render.Bind(r, req); err != nil { + if err := req.Bind(r); err != nil { + log.WithError(err).Error("Error binding request") utils.Render(w, r, utils.ErrBadRequest) return } if err := req.Validate(); err != nil { + log.WithError(err).Error("Error validating request") utils.Render(w, r, utils.ErrBadRequest) return } + event := utils.GetEventCtx(r) signup := &models.EventSignup{ + EventID: event.ID, PositionID: req.PositionID, CID: req.CID, Shift: req.Shift, diff --git a/external/v3/event/struct.go b/external/v3/event/struct.go index 01bebc5..0543400 100644 --- a/external/v3/event/struct.go +++ b/external/v3/event/struct.go @@ -1,9 +1,12 @@ package event import ( + "encoding/json" + "fmt" "github.com/VATUSA/primary-api/pkg/constants" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/go-chi/render" + log "github.com/sirupsen/logrus" "net/http" "time" ) @@ -21,6 +24,9 @@ func (req *EventTemplateRequest) Validate() error { } func (req *EventTemplateRequest) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } @@ -62,6 +68,9 @@ func (req *EventRequest) Validate() error { } func (req *EventRequest) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } @@ -100,15 +109,62 @@ func (req *EventPositionRequest) Validate() error { } func (req *EventPositionRequest) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } type EventPositionResponse struct { *models.EventPosition + AssigneeName string `json:"assignee_name" example:"John Doe"` + SecondaryAssigneeName string `json:"secondary_assignee_name" example:"Jane Doe"` } func NewEventPositionResponse(ep *models.EventPosition) *EventPositionResponse { - return &EventPositionResponse{EventPosition: ep} + resp := &EventPositionResponse{EventPosition: ep} + if ep.Assignee != 0 { + user := models.User{CID: ep.Assignee} + if err := user.Get(); err != nil { + log.WithError(err).Errorf("Error getting user %d", ep.Assignee) + resp.AssigneeName = "Unknown" + } + + ois, err := models.GetUserOIs(user.CID, ep.Facility) + if err != nil { + log.WithError(err).Errorf("Error getting OIs for user %d", user.CID) + } + resp.AssigneeName = fmt.Sprintf("%s - %s", user.FirstName, ois) + } + if ep.SecondaryAssignee != 0 { + user := models.User{CID: ep.SecondaryAssignee} + if err := user.Get(); err != nil { + log.WithError(err).Errorf("Error getting user %d", ep.SecondaryAssignee) + resp.SecondaryAssigneeName = "Unknown" + } + + ois, err := models.GetUserOIs(user.CID, ep.Facility) + if err != nil { + log.WithError(err).Errorf("Error getting OIs for user %d", user.CID) + } + resp.SecondaryAssigneeName = fmt.Sprintf("%s - %s", user.FirstName, ois) + } + + for idx, signup := range ep.Signups { + user := models.User{CID: signup.CID} + if err := user.Get(); err != nil { + log.WithError(err).Errorf("Error getting user %d", signup.CID) + continue + } + + ois, err := models.GetUserOIs(user.CID, ep.Facility) + if err != nil { + log.WithError(err).Errorf("Error getting OIs for user %d", user.CID) + } + ep.Signups[idx].Name = fmt.Sprintf("%s - %s", user.FirstName, ois) + } + + return resp } func (res *EventPositionResponse) Render(w http.ResponseWriter, r *http.Request) error { @@ -137,6 +193,9 @@ func (req *EventSignupRequest) Validate() error { } func (req *EventSignupRequest) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } @@ -175,6 +234,9 @@ func (req *EventRoutingRequest) Validate() error { } func (req *EventRoutingRequest) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/facility-log/facility_log.go b/external/v3/facility-log/facility_log.go index d5b246d..e70ec10 100644 --- a/external/v3/facility-log/facility_log.go +++ b/external/v3/facility-log/facility_log.go @@ -1,6 +1,7 @@ package facility_log import ( + "encoding/json" "errors" "fmt" "github.com/VATUSA/primary-api/pkg/constants" @@ -21,6 +22,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/facility/facility.go b/external/v3/facility/facility.go index 020fd4e..421e952 100644 --- a/external/v3/facility/facility.go +++ b/external/v3/facility/facility.go @@ -1,6 +1,7 @@ package facility import ( + "encoding/json" "github.com/VATUSA/primary-api/pkg/constants" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" @@ -18,6 +19,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/facility/router.go b/external/v3/facility/router.go index 55a2c6e..7c219b5 100644 --- a/external/v3/facility/router.go +++ b/external/v3/facility/router.go @@ -57,7 +57,7 @@ func Router(r chi.Router) { roster.Router(r) }) - r.Route("/roster-requests", func(r chi.Router) { + r.Route("/roster-request", func(r chi.Router) { roster_request.Router(r) }) }) diff --git a/external/v3/faq/faq.go b/external/v3/faq/faq.go index 9ee39e6..a100ce6 100644 --- a/external/v3/faq/faq.go +++ b/external/v3/faq/faq.go @@ -1,6 +1,7 @@ package faq import ( + "encoding/json" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" "github.com/go-chi/render" @@ -19,6 +20,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/feedback/feedback.go b/external/v3/feedback/feedback.go index 79e2897..262f3d7 100644 --- a/external/v3/feedback/feedback.go +++ b/external/v3/feedback/feedback.go @@ -1,6 +1,7 @@ package feedback import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/constants" "github.com/VATUSA/primary-api/pkg/database/models" @@ -29,6 +30,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/notification/notification.go b/external/v3/notification/notification.go index 7afe6b2..28ee27f 100644 --- a/external/v3/notification/notification.go +++ b/external/v3/notification/notification.go @@ -1,6 +1,7 @@ package notification import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" @@ -22,6 +23,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/rating-change/rating_change.go b/external/v3/rating-change/rating_change.go index 32954cc..80583bf 100644 --- a/external/v3/rating-change/rating_change.go +++ b/external/v3/rating-change/rating_change.go @@ -1,6 +1,7 @@ package rating_change import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/constants" "github.com/VATUSA/primary-api/pkg/database/models" @@ -20,6 +21,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/roster-request/roster_request.go b/external/v3/roster-request/roster_request.go index 6542ff4..fa1fe8a 100644 --- a/external/v3/roster-request/roster_request.go +++ b/external/v3/roster-request/roster_request.go @@ -1,12 +1,14 @@ package roster_request import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/database/types" "github.com/VATUSA/primary-api/pkg/utils" "github.com/go-chi/render" "github.com/go-playground/validator/v10" + log "github.com/sirupsen/logrus" "net/http" ) @@ -22,15 +24,31 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } type Response struct { *models.RosterRequest + FirstName string `json:"first_name" example:"John"` + LastName string `json:"last_name" example:"Doe"` } func NewRosterRequestResponse(r *models.RosterRequest) *Response { - return &Response{RosterRequest: r} + resp := &Response{RosterRequest: r} + + user := &models.User{CID: r.CID} + if err := user.Get(); err != nil { + log.WithError(err).Errorf("Error getting user with CID %d", r.CID) + return resp + } + + resp.FirstName = user.FirstName + resp.LastName = user.LastName + + return resp } func (res *Response) Render(w http.ResponseWriter, r *http.Request) error { diff --git a/external/v3/roster/roster.go b/external/v3/roster/roster.go index 23833fe..ac64d2c 100644 --- a/external/v3/roster/roster.go +++ b/external/v3/roster/roster.go @@ -1,6 +1,7 @@ package roster import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" @@ -23,6 +24,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/user-flag/user_flag.go b/external/v3/user-flag/user_flag.go index 5f1837e..1cf21c4 100644 --- a/external/v3/user-flag/user_flag.go +++ b/external/v3/user-flag/user_flag.go @@ -1,6 +1,7 @@ package user_flag import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" @@ -26,6 +27,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/external/v3/user-role/user-role.go b/external/v3/user-role/user-role.go index af7f4f3..dcad806 100644 --- a/external/v3/user-role/user-role.go +++ b/external/v3/user-role/user-role.go @@ -1,12 +1,14 @@ package user_role import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/constants" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" "github.com/go-chi/render" "github.com/go-playground/validator/v10" + log "github.com/sirupsen/logrus" "net/http" "time" ) @@ -21,6 +23,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } @@ -72,12 +77,19 @@ func NewUserRoleListResponse(userRoles []models.UserRole) []render.Renderer { // @Success 200 {object} Response // @Failure 400 {object} utils.ErrResponse // @Failure 500 {object} utils.ErrResponse -// @Router /user/{cid}/role/ [get] +// @Router /user/{cid}/roles [get] func GetSelfRoles(w http.ResponseWriter, r *http.Request) { user := utils.GetXUser(r) + rosters, err := models.GetRostersByCID(user.CID) + if err != nil { + log.WithError(err).Errorf("Error getting rosters for user %d", user.CID) + utils.Render(w, r, utils.ErrInternalServer) + return + } + roles := []models.UserRole{} - for _, roster := range user.Roster { + for _, roster := range rosters { roles = append(roles, roster.Roles...) } @@ -97,7 +109,7 @@ func GetSelfRoles(w http.ResponseWriter, r *http.Request) { // @Success 201 {object} Response // @Failure 400 {object} utils.ErrResponse // @Failure 500 {object} utils.ErrResponse -// @Router /user/{cid}/role [post] +// @Router /user/{cid}/roles [post] func CreateUserRoles(w http.ResponseWriter, r *http.Request) { req := &Request{} if err := render.Bind(r, req); err != nil { @@ -139,7 +151,7 @@ func CreateUserRoles(w http.ResponseWriter, r *http.Request) { // @Success 204 // @Failure 400 {object} utils.ErrResponse // @Failure 500 {object} utils.ErrResponse -// @Router /user/{cid}/role/{role_id} [delete] +// @Router /user/{cid}/roles/{role_id} [delete] func DeleteUserRoles(w http.ResponseWriter, r *http.Request) { user := utils.GetUserCtx(r) role := utils.GetUserRoleCtx(r) diff --git a/external/v3/user/router.go b/external/v3/user/router.go index 7ed07b1..d4c6f5d 100644 --- a/external/v3/user/router.go +++ b/external/v3/user/router.go @@ -66,7 +66,7 @@ func Router(r chi.Router) { user_flag.Router(r) }) - r.Route("/user-roles", func(r chi.Router) { + r.Route("/roles", func(r chi.Router) { user_role.Router(r) }) }) diff --git a/external/v3/user/user.go b/external/v3/user/user.go index d8e6a03..c1ddf23 100644 --- a/external/v3/user/user.go +++ b/external/v3/user/user.go @@ -1,6 +1,7 @@ package user import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/database/models" "github.com/VATUSA/primary-api/pkg/utils" @@ -21,6 +22,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/go.sum b/go.sum index 708ce20..28ca650 100644 --- a/go.sum +++ b/go.sum @@ -4,63 +4,35 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= -github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA= -github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= github.com/aws/aws-sdk-go-v2 v1.32.0 h1:GuHp7GvMN74PXD5C97KT5D87UhIy4bQPkflQKbfkndg= github.com/aws/aws-sdk-go-v2 v1.32.0/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2/go.mod h1:lPprDr1e6cJdyYeGXnRaJoP4Md+cDBvi2eOj00BlGmg= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 h1:pT3hpW0cOHRJx8Y0DfJUEQuqPild8jRGmSFmBgvydr0= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6/go.mod h1:j/I2++U0xX+cr44QjHay4Cvxj6FUbnxrgmqN3H1jTZA= -github.com/aws/aws-sdk-go-v2/credentials v1.17.11 h1:YuIB1dJNf1Re822rriUOTxopaHHvIq0l/pX3fwO+Tzs= -github.com/aws/aws-sdk-go-v2/credentials v1.17.11/go.mod h1:AQtFPsDH9bI2O+71anW6EKL+NcD7LG3dpKGMV4SShgo= github.com/aws/aws-sdk-go-v2/credentials v1.17.39 h1:tmVexAhoGqJxNE2oc4/SJqL+Jz1x1iCPt5ts9XcqZCU= github.com/aws/aws-sdk-go-v2/credentials v1.17.39/go.mod h1:zgOdbDI9epE608PdboJ87CYvPIejAgFevazeJW6iauQ= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 h1:aw39xVGeRWlWx9EzGVnhOR4yOjQDHPQ6o6NmBlscyQg= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5/go.mod h1:FSaRudD0dXiMPK2UjknVwwTYyZMRsHv3TtkabsZih5I= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.19 h1:Q/k5wCeJkSWs+62kDfOillkNIJ5NqmE3iOfm48g/W8c= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.19/go.mod h1:Wns1C66VvtA2Bv/cUBuKZKQKdjo7EVMhp90aAa+8oTI= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 h1:PG1F3OD1szkuQPzDw3CIQsRIrtTlUC3lP84taWzHlq0= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5/go.mod h1:jU1li6RFryMz+so64PpKtudI+QzbKoIEivqdf6LNpOc= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.19 h1:AYLE0lUfKvN6icFTR/p+NmD1amYKTbqHQ1Nm+jwE6BM= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.19/go.mod h1:1giLakj64GjuH1NBzF/DXqly5DWHtMTaOzRZ53nFX0I= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 h1:81KE7vaZzrl7yHBYHVEzYB8sypz11NMOZ40YlWvPxsU= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5/go.mod h1:LIt2rg7Mcgn09Ygbdh/RdIm0rQ+3BNkbP1gyVMFtRK0= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.19 h1:FKdiFzTxlTRO71p0C7VrLbkkdW8qfMKF5+ej6bTmkT0= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.19/go.mod h1:abO3pCj7WLQPTllnSeYImqFfkGrmJV0JovWo/gqT5N0= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 h1:ZMeFZ5yk+Ek+jNr1+uwCd2tG89t6oTS5yVWpa6yy2es= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7/go.mod h1:mxV05U+4JiHqIpGqqYXOHLPKUC6bDXC44bsUhNjOEwY= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.0 h1:FQNWhRuSq8QwW74GtU0MrveNhZbqvHsA4dkA9w8fTDQ= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.0/go.mod h1:j/zZ3zmWfGCK91K73YsfHP53BSTLSjL/y6YN39XbBLM= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 h1:ogRAwT1/gxJBcSWDMZlgyFUM962F51A5CRhDLbxLdmo= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7/go.mod h1:YCsIZhXfRPLFFCl5xxY+1T9RKzOKjCut+28JSX2DnAk= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.0 h1:AdbiDUgQZmM28rDIZbiSwFxz8+3B94aOXxzs6oH+EA0= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.0/go.mod h1:uV476Bd80tiDTX4X2redMtagQUg65aU/gzPojSJ4kSI= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 h1:f9RyWNtS8oH7cZlbn+/JNPpjUk5+5fLd5lM9M0i49Ys= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5/go.mod h1:h5CoMZV2VF297/VLhRhO1WF+XYWOzXo+4HsObA4HjBQ= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.0 h1:1NKXS8XfhMM0bg5wVYa/eOH8AM2f6JijugbKEyQFTIg= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.0/go.mod h1:ph931DUfVfgrhZR7py9olSvHCiRpvaGxNvlWBcXxFds= -github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 h1:6cnno47Me9bRykw9AEv9zkXE+5or7jz8TsskTTccbgc= -github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1/go.mod h1:qmdkIIAC+GCLASF7R2whgNrJADz0QZPX+Seiw/i4S3o= github.com/aws/aws-sdk-go-v2/service/s3 v1.65.0 h1:2dSm7frMrw2tdJ0QvyccQNJyPGaP24dyDgZ6h1QJMGU= github.com/aws/aws-sdk-go-v2/service/s3 v1.65.0/go.mod h1:4XSVpw66upN8wND3JZA29eXl2NOZvfFVq7DIP6xvfuQ= -github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= -github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4= github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4= -github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= -github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= @@ -81,16 +53,13 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= -github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= @@ -138,31 +107,23 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= -golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= -golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -170,8 +131,6 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -181,15 +140,11 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= -golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -199,12 +154,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/mysql v1.5.6 h1:Ld4mkIickM+EliaQZQx3uOJDJHtrd70MxAUqWqlx3Y8= -gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= -gorm.io/gorm v1.25.9 h1:wct0gxZIELDk8+ZqF/MVnHLkA1rvYlBWUMv2EdsK1g8= -gorm.io/gorm v1.25.9/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= diff --git a/internal/v1/action-log/action_log.go b/internal/v1/action-log/action_log.go index 16a112d..5c335ab 100644 --- a/internal/v1/action-log/action_log.go +++ b/internal/v1/action-log/action_log.go @@ -17,6 +17,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/disciplinary-log/disciplinary_log.go b/internal/v1/disciplinary-log/disciplinary_log.go index 5e112ca..1ca2366 100644 --- a/internal/v1/disciplinary-log/disciplinary_log.go +++ b/internal/v1/disciplinary-log/disciplinary_log.go @@ -19,6 +19,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/document/document.go b/internal/v1/document/document.go index 42a7aac..1c2ba45 100644 --- a/internal/v1/document/document.go +++ b/internal/v1/document/document.go @@ -28,6 +28,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/facility-log/facility_log.go b/internal/v1/facility-log/facility_log.go index 7dbf829..a55aaad 100644 --- a/internal/v1/facility-log/facility_log.go +++ b/internal/v1/facility-log/facility_log.go @@ -1,6 +1,7 @@ package facility_log import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/constants" "github.com/VATUSA/primary-api/pkg/database/models" @@ -20,6 +21,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/faq/faq.go b/internal/v1/faq/faq.go index f53189f..c7203e6 100644 --- a/internal/v1/faq/faq.go +++ b/internal/v1/faq/faq.go @@ -21,6 +21,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/feedback/feedback.go b/internal/v1/feedback/feedback.go index d6fae36..3200056 100644 --- a/internal/v1/feedback/feedback.go +++ b/internal/v1/feedback/feedback.go @@ -28,6 +28,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/news/news.go b/internal/v1/news/news.go index 95d6d86..46fb05d 100644 --- a/internal/v1/news/news.go +++ b/internal/v1/news/news.go @@ -21,6 +21,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/notification/notification.go b/internal/v1/notification/notification.go index 25a942a..b205598 100644 --- a/internal/v1/notification/notification.go +++ b/internal/v1/notification/notification.go @@ -23,6 +23,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/rating-change/rating_change.go b/internal/v1/rating-change/rating_change.go index 1baad21..e76f800 100644 --- a/internal/v1/rating-change/rating_change.go +++ b/internal/v1/rating-change/rating_change.go @@ -21,6 +21,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/roster-request/roster_request.go b/internal/v1/roster-request/roster_request.go index d417d2a..d5611e0 100644 --- a/internal/v1/roster-request/roster_request.go +++ b/internal/v1/roster-request/roster_request.go @@ -23,6 +23,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/roster/roster.go b/internal/v1/roster/roster.go index c85e6f6..e82034b 100644 --- a/internal/v1/roster/roster.go +++ b/internal/v1/roster/roster.go @@ -24,6 +24,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/user-flag/user_flag.go b/internal/v1/user-flag/user_flag.go index 5f1837e..fc918e0 100644 --- a/internal/v1/user-flag/user_flag.go +++ b/internal/v1/user-flag/user_flag.go @@ -26,6 +26,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/internal/v1/user/user.go b/internal/v1/user/user.go index 06a84e7..2bd6c74 100644 --- a/internal/v1/user/user.go +++ b/internal/v1/user/user.go @@ -29,6 +29,9 @@ func (req *Request) Validate() error { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/pkg/database/models/event.go b/pkg/database/models/event.go index 8b0959b..d5f81bd 100644 --- a/pkg/database/models/event.go +++ b/pkg/database/models/event.go @@ -30,7 +30,7 @@ func (e *Event) Create() error { } func (e *Event) Get() error { - return database.DB.Preload("Positions").Preload("Routing").First(e).Error + return database.DB.Preload("Positions.Signups").Preload("Routing").First(e).Error } func (e *Event) Update() error { diff --git a/pkg/database/models/event_position.go b/pkg/database/models/event_position.go index d302168..e894d66 100644 --- a/pkg/database/models/event_position.go +++ b/pkg/database/models/event_position.go @@ -40,7 +40,10 @@ func (ep *EventPosition) Delete() error { func GetEventPositionsFiltered(eventId uint, facilityID constants.FacilityID) ([]EventPosition, error) { var positions []EventPosition - query := database.DB.Where("event_id = ?", eventId) + query := database.DB.Preload("Signups") + if eventId != 0 { + query = query.Where("event_id = ?", eventId) + } if facilityID != "" { query = query.Where("facility = ?", facilityID) } diff --git a/pkg/database/models/event_signup.go b/pkg/database/models/event_signup.go index 99f9a78..0e02acc 100644 --- a/pkg/database/models/event_signup.go +++ b/pkg/database/models/event_signup.go @@ -9,9 +9,10 @@ type EventSignup struct { ID uint `json:"id" gorm:"primaryKey" example:"1"` EventID uint `json:"event_id" gorm:"not null" example:"1"` - PositionID uint `json:"position_id" gorm:"not null" example:"1"` - CID uint `json:"cid" gorm:"not null" example:"1293257"` - Shift uint `json:"shift" gorm:"not null;default:1" example:"1"` // 1 = Primary, 2 = Secondary + PositionID uint `json:"position_id" gorm:"not null" example:"1"` + CID uint `json:"cid" gorm:"not null" example:"1293257"` + Name string `json:"name" gorm:"-"` + Shift uint `json:"shift" gorm:"not null;default:1" example:"1"` // 1 = Primary, 2 = Secondary CreatedAt time.Time `json:"created_at" example:"2021-01-01T00:00:00Z"` UpdatedAt time.Time `json:"updated_at" example:"2021-01-01T00:00:00Z"` diff --git a/pkg/database/models/roster_request.go b/pkg/database/models/roster_request.go index b3af9e4..b40a023 100644 --- a/pkg/database/models/roster_request.go +++ b/pkg/database/models/roster_request.go @@ -10,9 +10,9 @@ import ( type RosterRequest struct { ID uint `json:"id" gorm:"primaryKey" example:"1"` CID uint `json:"cid" example:"1293257"` - Facility constants.FacilityID `json:"requested_facility" example:"ZDV"` - RequestType types.RequestType `gorm:"type:enum('visiting', 'transferring');"` - Status types.StatusType `gorm:"type:enum('pending', 'accepted', 'rejected');"` + Facility constants.FacilityID `json:"-" example:"ZDV"` + RequestType types.RequestType `json:"request_type" gorm:"type:enum('visiting', 'transferring');"` + Status types.StatusType `json:"status" gorm:"type:enum('pending', 'accepted', 'rejected');"` Reason string `json:"reason" example:"I want to transfer to ZDV"` CreatedAt time.Time `json:"created_at" example:"2021-01-01T00:00:00Z"` UpdatedAt time.Time `json:"updated_at" example:"2021-01-01T00:00:00Z"` @@ -46,20 +46,20 @@ func GetAllRosterRequestsByCID(cid uint) ([]RosterRequest, error) { func GetAllRosterRequestsByFacility(facility constants.FacilityID) ([]RosterRequest, error) { var rosterRequests []RosterRequest - return rosterRequests, database.DB.Where("requested_facility = ?", facility).Find(&rosterRequests).Error + return rosterRequests, database.DB.Where("facility = ?", facility).Find(&rosterRequests).Error } func GetRosterRequestsByType(facility constants.FacilityID, reqType types.RequestType) ([]RosterRequest, error) { var rosterRequests []RosterRequest - return rosterRequests, database.DB.Where("requested_facility = ? AND request_type = ?", facility, reqType).Find(&rosterRequests).Error + return rosterRequests, database.DB.Where("facility = ? AND request_type = ?", facility, reqType).Find(&rosterRequests).Error } func GetRosterRequestsByStatus(facility constants.FacilityID, status types.StatusType) ([]RosterRequest, error) { var rosterRequests []RosterRequest - return rosterRequests, database.DB.Where("requested_facility = ? AND status = ?", facility, status).Find(&rosterRequests).Error + return rosterRequests, database.DB.Where("facility = ? AND status = ?", facility, status).Find(&rosterRequests).Error } func GetRosterRequestsByTypeAndStatus(facility constants.FacilityID, reqType types.RequestType, status types.StatusType) ([]RosterRequest, error) { var rosterRequests []RosterRequest - return rosterRequests, database.DB.Where("requested_facility = ? AND request_type = ? AND status = ?", facility, reqType, status).Find(&rosterRequests).Error + return rosterRequests, database.DB.Where("facility = ? AND request_type = ? AND status = ?", facility, reqType, status).Find(&rosterRequests).Error } diff --git a/pkg/database/models/user.go b/pkg/database/models/user.go index ed3fe13..43495ab 100644 --- a/pkg/database/models/user.go +++ b/pkg/database/models/user.go @@ -53,7 +53,7 @@ func (un *User) Get() error { return database.DB.Where("discord_id = ?", un.DiscordID).First(un).Error } - return database.DB.First(un).Error + return database.DB.Preload("Roster").First(un).Error } func GetAllUsers() ([]User, error) { @@ -87,3 +87,17 @@ func IsValidUser(cid uint) bool { } return true } + +func GetUserOIs(cid uint, facility constants.FacilityID) (string, error) { + var user User + if err := database.DB.Preload("Roster").First(&user, cid).Error; err != nil { + return "", err + } + + for _, roster := range user.Roster { + if roster.Facility == facility { + return roster.OIs, nil + } + } + return user.PreferredOIs, nil +} diff --git a/pkg/database/types/roster_request_type.go b/pkg/database/types/roster_request_type.go index 780ab47..1ebee29 100644 --- a/pkg/database/types/roster_request_type.go +++ b/pkg/database/types/roster_request_type.go @@ -13,12 +13,12 @@ const ( ) func (s *RequestType) Scan(value interface{}) error { - strValue, ok := value.(string) - if !ok { - return errors.New("failed to scan RequestType") + if byteSlice, ok := value.([]byte); ok { + *s = RequestType(byteSlice) + } else { + return errors.New("failed to scan request_type") } - *s = RequestType(strValue) return nil } diff --git a/pkg/go-chi/middleware/auth/feedback.go b/pkg/go-chi/middleware/auth/feedback.go index 5fe9c3c..62e84a5 100644 --- a/pkg/go-chi/middleware/auth/feedback.go +++ b/pkg/go-chi/middleware/auth/feedback.go @@ -1,6 +1,7 @@ package middleware import ( + "encoding/json" "github.com/VATUSA/primary-api/pkg/database/types" "github.com/VATUSA/primary-api/pkg/utils" log "github.com/sirupsen/logrus" @@ -98,6 +99,10 @@ type Request struct { } func (req *Request) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } + return nil } diff --git a/pkg/go-chi/middleware/auth/user_role.go b/pkg/go-chi/middleware/auth/user_role.go index a597379..d65aff9 100644 --- a/pkg/go-chi/middleware/auth/user_role.go +++ b/pkg/go-chi/middleware/auth/user_role.go @@ -1,6 +1,7 @@ package middleware import ( + "encoding/json" "errors" "github.com/VATUSA/primary-api/pkg/constants" "github.com/VATUSA/primary-api/pkg/database/models" @@ -20,6 +21,9 @@ func (req *UserRoleRequest) Validate() error { } func (req *UserRoleRequest) Bind(r *http.Request) error { + if err := json.NewDecoder(r.Body).Decode(req); err != nil { + return err + } return nil } diff --git a/pkg/utils/pprint.go b/pkg/utils/pprint.go new file mode 100644 index 0000000..485fb83 --- /dev/null +++ b/pkg/utils/pprint.go @@ -0,0 +1,15 @@ +package utils + +import ( + "encoding/json" + "fmt" + log "github.com/sirupsen/logrus" +) + +func Pprint(obj interface{}) { + marshaled, err := json.MarshalIndent(obj, "", " ") + if err != nil { + log.Fatalf("marshaling error: %s", err) + } + fmt.Println(string(marshaled)) +}