use uuid for everything
This commit is contained in:
+13
-11
@@ -11,6 +11,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func isOwnerOfGroup(user *User, group *Group) bool {
|
||||
@@ -27,7 +29,7 @@ func getIfOwnerUserAndGroup(ctx context.Context, response *http.ResponseWriter,
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
affectedGroupId, err := ConvertStringUint32(request.FormValue("groupid"))
|
||||
affectedGroupId, err := ConvertStringUuid(request.FormValue("groupid"))
|
||||
if err != nil {
|
||||
http.Error(*response, "no such group", http.StatusUnauthorized)
|
||||
return nil, nil, err
|
||||
@@ -77,7 +79,7 @@ func HttpHandeGroupCreate(response http.ResponseWriter, request *http.Request) {
|
||||
OwnerId: user.Id,
|
||||
CreatorId: user.Id,
|
||||
Color: color,
|
||||
Users: map[uint32]struct{}{user.Id: {}},
|
||||
Users: map[uuid.UUID]struct{}{user.Id: {}},
|
||||
}
|
||||
|
||||
enableUserColors := request.FormValue("enableUserColors")
|
||||
@@ -91,7 +93,7 @@ func HttpHandeGroupCreate(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
response.WriteHeader(http.StatusCreated)
|
||||
fmt.Fprintf(response, "%d", group.Id)
|
||||
fmt.Fprintf(response, "%s", group.Id)
|
||||
}
|
||||
|
||||
func HttpHandleGroupDelete(response http.ResponseWriter, request *http.Request) {
|
||||
@@ -140,13 +142,13 @@ func HttpHandleGroupAddUsers(response http.ResponseWriter, request *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
var ids [MaxUsersInGroup]uint32
|
||||
var ids [MaxUsersInGroup]uuid.UUID
|
||||
var idx uint32 = 0
|
||||
for _, s := range usersStringSlice {
|
||||
if idx >= MaxUsersInGroup {
|
||||
break
|
||||
}
|
||||
id, err := ConvertStringUint32(strings.TrimSpace(s))
|
||||
id, err := ConvertStringUuid(strings.TrimSpace(s))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -192,13 +194,13 @@ func HttpHandleGroupRemoveUser(response http.ResponseWriter, request *http.Reque
|
||||
|
||||
usersStringSlice := strings.SplitN(usersString, ",", int(MaxUsersInGroup)+1)
|
||||
|
||||
var ids [MaxUsersInGroup]uint32
|
||||
var ids [MaxUsersInGroup]uuid.UUID
|
||||
var idx uint32 = 0
|
||||
for _, s := range usersStringSlice {
|
||||
if idx >= MaxUsersInGroup {
|
||||
break
|
||||
}
|
||||
id, err := ConvertStringUint32(strings.TrimSpace(s))
|
||||
id, err := ConvertStringUuid(strings.TrimSpace(s))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -314,7 +316,7 @@ func HttpHandleGroupMessage(response http.ResponseWriter, request *http.Request)
|
||||
return
|
||||
}
|
||||
groupIdStr := request.FormValue("groupid")
|
||||
groupId, err := ConvertStringUint32(groupIdStr)
|
||||
groupId, err := ConvertStringUuid(groupIdStr)
|
||||
if err != nil {
|
||||
http.Error(response, "no such group", http.StatusUnauthorized)
|
||||
return
|
||||
@@ -360,13 +362,13 @@ func HttpHandleGroupsGetWithoutMembers(response http.ResponseWriter, request *ht
|
||||
}
|
||||
|
||||
user.Mu.RLock()
|
||||
groupIds := make([]uint32, 0, len(user.Groups))
|
||||
groupIds := make([]uuid.UUID, 0, len(user.Groups))
|
||||
for groupId := range user.Groups {
|
||||
groupIds = append(groupIds, groupId)
|
||||
}
|
||||
user.Mu.RUnlock()
|
||||
|
||||
groups := make(map[uint32]*Group, len(groupIds))
|
||||
groups := make(map[uuid.UUID]*Group, len(groupIds))
|
||||
for _, groupId := range groupIds {
|
||||
group, err := GetGroup(ctx, groupId)
|
||||
if err != nil {
|
||||
@@ -398,7 +400,7 @@ func HttpHandleGroupMembersGet(response http.ResponseWriter, request *http.Reque
|
||||
}
|
||||
|
||||
groupStr := request.FormValue("group")
|
||||
groupId, err := ConvertStringUint32(groupStr)
|
||||
groupId, err := ConvertStringUuid(groupStr)
|
||||
if err != nil {
|
||||
http.Error(response, "invalid group", http.StatusBadRequest)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user