Skip to content

Commit

Permalink
NOISSUE - Clean Up Things Service (absmach#28)
Browse files Browse the repository at this point in the history
* Rework things service

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* add tests

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

---------

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
  • Loading branch information
rodneyosodo authored and dborovcanin committed Oct 13, 2023
1 parent 99b374b commit b5ed276
Show file tree
Hide file tree
Showing 16 changed files with 1,479 additions and 1,331 deletions.
34 changes: 34 additions & 0 deletions things/api/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,68 +193,98 @@ func groupsHandler(svc groups.Service, r *chi.Mux, logger logger.Logger) http.Ha
}

func decodeAssignUsersGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) {
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := assignUsersGroupsRequest{
token: apiutil.ExtractBearerToken(r),
groupID: chi.URLParam(r, "groupID"),
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(err, errors.ErrMalformedEntity))
}

return req, nil
}

func decodeUnassignUsersGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) {
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := unassignUsersGroupsRequest{
token: apiutil.ExtractBearerToken(r),
groupID: chi.URLParam(r, "groupID"),
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(err, errors.ErrMalformedEntity))
}

return req, nil
}

func decodeAssignUsersRequest(_ context.Context, r *http.Request) (interface{}, error) {
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := assignUsersRequest{
token: apiutil.ExtractBearerToken(r),
groupID: chi.URLParam(r, "groupID"),
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(err, errors.ErrMalformedEntity))
}

return req, nil
}

func decodeUnassignUsersRequest(_ context.Context, r *http.Request) (interface{}, error) {
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := unassignUsersRequest{
token: apiutil.ExtractBearerToken(r),
groupID: chi.URLParam(r, "groupID"),
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(err, errors.ErrMalformedEntity))
}

return req, nil
}

func decodeAssignUserGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) {
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := assignUserGroupsRequest{
token: apiutil.ExtractBearerToken(r),
groupID: chi.URLParam(r, "groupID"),
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(err, errors.ErrMalformedEntity))
}

return req, nil
}

func decodeUnassignUserGroupsRequest(_ context.Context, r *http.Request) (interface{}, error) {
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := unassignUserGroupsRequest{
token: apiutil.ExtractBearerToken(r),
groupID: chi.URLParam(r, "groupID"),
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(err, errors.ErrMalformedEntity))
}

return req, nil
}

Expand All @@ -264,6 +294,7 @@ func decodeConnectChannelThingRequest(_ context.Context, r *http.Request) (inter
ThingID: chi.URLParam(r, "thingID"),
ChannelID: chi.URLParam(r, "groupID"),
}

return req, nil
}

Expand All @@ -273,6 +304,7 @@ func decodeDisconnectChannelThingRequest(_ context.Context, r *http.Request) (in
ThingID: chi.URLParam(r, "thingID"),
ChannelID: chi.URLParam(r, "groupID"),
}

return req, nil
}

Expand All @@ -287,6 +319,7 @@ func decodeConnectRequest(_ context.Context, r *http.Request) (interface{}, erro
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(errors.ErrMalformedEntity, err))
}

return req, nil
}

Expand All @@ -301,5 +334,6 @@ func decodeDisconnectRequest(_ context.Context, r *http.Request) (interface{}, e
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(errors.ErrMalformedEntity, err))
}

return req, nil
}
4 changes: 4 additions & 0 deletions things/api/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func decodeUpdateClient(_ context.Context, r *http.Request) (interface{}, error)
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := updateClientReq{
token: apiutil.ExtractBearerToken(r),
id: chi.URLParam(r, "thingID"),
Expand All @@ -210,6 +211,7 @@ func decodeUpdateClientTags(_ context.Context, r *http.Request) (interface{}, er
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := updateClientTagsReq{
token: apiutil.ExtractBearerToken(r),
id: chi.URLParam(r, "thingID"),
Expand All @@ -225,6 +227,7 @@ func decodeUpdateClientCredentials(_ context.Context, r *http.Request) (interfac
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := updateClientCredentialsReq{
token: apiutil.ExtractBearerToken(r),
id: chi.URLParam(r, "thingID"),
Expand All @@ -240,6 +243,7 @@ func decodeUpdateClientOwner(_ context.Context, r *http.Request) (interface{}, e
if !strings.Contains(r.Header.Get("Content-Type"), api.ContentType) {
return nil, errors.Wrap(apiutil.ErrValidation, apiutil.ErrUnsupportedContentType)
}

req := updateClientOwnerReq{
token: apiutil.ExtractBearerToken(r),
id: chi.URLParam(r, "thingID"),
Expand Down
Loading

0 comments on commit b5ed276

Please sign in to comment.