mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00
NOISSUE - Fix auth members list response (#1555)
* NOISSUE - Fix auth members list response Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Move group type next to page details Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rm membersRes Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
parent
6ad654d7cb
commit
e8a51842aa
@ -250,7 +250,7 @@ func listMembersEndpoint(svc auth.Service) endpoint.Endpoint {
|
||||
return memberPageRes{}, err
|
||||
}
|
||||
|
||||
return buildUsersResponse(page), nil
|
||||
return buildUsersResponse(page, req.groupType), nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,7 +350,7 @@ func buildGroupsResponse(gp auth.GroupPage) groupPageRes {
|
||||
return res
|
||||
}
|
||||
|
||||
func buildUsersResponse(mp auth.MemberPage) memberPageRes {
|
||||
func buildUsersResponse(mp auth.MemberPage, groupType string) memberPageRes {
|
||||
res := memberPageRes{
|
||||
pageRes: pageRes{
|
||||
Total: mp.Total,
|
||||
@ -358,11 +358,12 @@ func buildUsersResponse(mp auth.MemberPage) memberPageRes {
|
||||
Limit: mp.Limit,
|
||||
Name: mp.Name,
|
||||
},
|
||||
Members: []interface{}{},
|
||||
Type: groupType,
|
||||
Members: []string{},
|
||||
}
|
||||
|
||||
for _, m := range mp.Members {
|
||||
res.Members = append(res.Members, m)
|
||||
res.Members = append(res.Members, m.ID)
|
||||
}
|
||||
|
||||
return res
|
||||
|
@ -18,7 +18,8 @@ var (
|
||||
|
||||
type memberPageRes struct {
|
||||
pageRes
|
||||
Members []interface{}
|
||||
Type string `json:"type"`
|
||||
Members []string `json:"members"`
|
||||
}
|
||||
|
||||
func (res memberPageRes) Code() int {
|
||||
|
@ -6,8 +6,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const MaxLevel = uint64(5)
|
||||
const MinLevel = uint64(1)
|
||||
const (
|
||||
// MaxLevel represents the maximum group hierarchy level.
|
||||
MaxLevel = uint64(5)
|
||||
// MinLevel represents the minimum group hierarchy level.
|
||||
MinLevel = uint64(1)
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrMaxLevelExceeded malformed entity.
|
||||
@ -50,13 +54,16 @@ var (
|
||||
ErrMemberAlreadyAssigned = errors.New("member is already assigned")
|
||||
)
|
||||
|
||||
// GroupMetadata defines the Metadata type.
|
||||
type GroupMetadata map[string]interface{}
|
||||
|
||||
// Member represents the member information.
|
||||
type Member struct {
|
||||
ID string
|
||||
Type string
|
||||
}
|
||||
|
||||
// Group represents the group information.
|
||||
type Group struct {
|
||||
ID string
|
||||
OwnerID string
|
||||
@ -76,6 +83,7 @@ type Group struct {
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// PageMetadata contains page metadata that helps navigation.
|
||||
type PageMetadata struct {
|
||||
Total uint64
|
||||
Offset uint64
|
||||
@ -87,16 +95,22 @@ type PageMetadata struct {
|
||||
Metadata GroupMetadata
|
||||
}
|
||||
|
||||
// GroupPage contains page related metadata as well as list of groups that
|
||||
// belong to this page.
|
||||
type GroupPage struct {
|
||||
PageMetadata
|
||||
Groups []Group
|
||||
}
|
||||
|
||||
// MemberPage contains page related metadata as well as list of members that
|
||||
// belong to this page.
|
||||
type MemberPage struct {
|
||||
PageMetadata
|
||||
Members []Member
|
||||
}
|
||||
|
||||
// GroupService specifies an API that must be fullfiled by the domain service
|
||||
// implementation, and all of its decorators (e.g. logging & metrics).
|
||||
type GroupService interface {
|
||||
// CreateGroup creates new group.
|
||||
CreateGroup(ctx context.Context, token string, g Group) (Group, error)
|
||||
@ -135,6 +149,7 @@ type GroupService interface {
|
||||
AssignGroupAccessRights(ctx context.Context, token, thingGroupID, userGroupID string) error
|
||||
}
|
||||
|
||||
// GroupRepository specifies a group persistence API.
|
||||
type GroupRepository interface {
|
||||
// Save group
|
||||
Save(ctx context.Context, g Group) (Group, error)
|
||||
|
@ -19,8 +19,6 @@ var (
|
||||
_ mainflux.Response = (*createGroupRes)(nil)
|
||||
_ mainflux.Response = (*createUserRes)(nil)
|
||||
_ mainflux.Response = (*deleteRes)(nil)
|
||||
_ mainflux.Response = (*assignUserToGroupRes)(nil)
|
||||
_ mainflux.Response = (*removeUserFromGroupRes)(nil)
|
||||
)
|
||||
|
||||
// MailSent message response when link is sent
|
||||
@ -237,31 +235,3 @@ func (res deleteRes) Headers() map[string]string {
|
||||
func (res deleteRes) Empty() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type assignUserToGroupRes struct{}
|
||||
|
||||
func (res assignUserToGroupRes) Code() int {
|
||||
return http.StatusNoContent
|
||||
}
|
||||
|
||||
func (res assignUserToGroupRes) Headers() map[string]string {
|
||||
return map[string]string{}
|
||||
}
|
||||
|
||||
func (res assignUserToGroupRes) Empty() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type removeUserFromGroupRes struct{}
|
||||
|
||||
func (res removeUserFromGroupRes) Code() int {
|
||||
return http.StatusNoContent
|
||||
}
|
||||
|
||||
func (res removeUserFromGroupRes) Headers() map[string]string {
|
||||
return map[string]string{}
|
||||
}
|
||||
|
||||
func (res removeUserFromGroupRes) Empty() bool {
|
||||
return true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user