u
This commit is contained in:
1 parent
5ca04f85ca
commit
d9c49b34db
17 files changed
+452
-175
No files matched your search
@@ -3,7 +3,6 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"allapp/biz/handler/space"
|
||||
"allapp/biz/model/auth"
|
||||
"allapp/conf"
|
||||
"allapp/db"
|
||||
@@ -12,7 +11,6 @@ import (
|
||||
"allapp/utils/httpx"
|
||||
"allapp/utils/idgen"
|
||||
"allapp/utils/jwtx"
|
||||
"allapp/utils/redisx"
|
||||
"allapp/utils/response"
|
||||
"context"
|
||||
"fmt"
|
||||
@@ -58,14 +56,6 @@ func LoginQq(ctx context.Context, c *app.RequestContext) {
|
||||
return
|
||||
}
|
||||
|
||||
// 初始化空间信息
|
||||
err := InitUserSpaces(ctx, user.UserID)
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
_ = db.Queries.UpdateUserLastLoginTime(ctx, user.UserID)
|
||||
token, _ := jwtx.CreateToken(user.UserID)
|
||||
|
||||
@@ -150,14 +140,6 @@ func LoginWx(ctx context.Context, c *app.RequestContext) {
|
||||
return
|
||||
}
|
||||
|
||||
// 初始化用户空间信息
|
||||
err := InitUserSpaces(ctx, user.UserID)
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
_ = db.Queries.UpdateUserLastLoginTime(ctx, user.UserID)
|
||||
token, _ := jwtx.CreateToken(user.UserID)
|
||||
|
||||
@@ -202,13 +184,6 @@ func registerUser(ctx context.Context, c *app.RequestContext, openid, nickname,
|
||||
}
|
||||
|
||||
err := db.WithTx(ctx, func(q *repo.Queries) error {
|
||||
// 确保空间存在
|
||||
err := space.EnsureUserHasSpaceWithTx(ctx, q, userId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 插入用户
|
||||
if err := q.InsertUser(ctx, repo.InsertUserParams{
|
||||
ID: userId,
|
||||
@@ -242,14 +217,6 @@ func registerUser(ctx context.Context, c *app.RequestContext, openid, nickname,
|
||||
return
|
||||
}
|
||||
|
||||
// 初始化用户空间信息
|
||||
err = InitUserSpaces(ctx, userId)
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
token, _ := jwtx.CreateToken(userId)
|
||||
resp := &auth.LoginResp{
|
||||
Token: token,
|
||||
@@ -291,18 +258,3 @@ func initMoneyCategoryTx(ctx context.Context, q *repo.Queries, userId int64) err
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 初始化用户空间信息
|
||||
func InitUserSpaces(ctx context.Context, userID int64) error {
|
||||
spaces, err := db.Queries.ListUserSpaces(ctx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
spaceRoles := make(map[int64]int32, len(spaces))
|
||||
for _, row := range spaces {
|
||||
spaceRoles[row.ID] = row.Role
|
||||
}
|
||||
|
||||
return redisx.SetUserSpaces(ctx, userID, spaceRoles)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func CreateSpace(ctx context.Context, c *app.RequestContext) {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Id = spaceId
|
||||
resp.SpaceId = spaceId
|
||||
resp.InviteCode = inviteCode
|
||||
|
||||
response.Success(c).Data(resp).Send()
|
||||
@@ -184,6 +184,8 @@ func ExitSpace(ctx context.Context, c *app.RequestContext) {
|
||||
|
||||
resp := new(space.ExitSpaceResult)
|
||||
|
||||
exitSpaceId := req.SpaceId
|
||||
|
||||
userID := middleware.GetUserID(ctx)
|
||||
|
||||
spaceUser, err := db.Queries.GetSpaceUser(ctx, userID)
|
||||
@@ -197,6 +199,11 @@ func ExitSpace(ctx context.Context, c *app.RequestContext) {
|
||||
}
|
||||
}
|
||||
|
||||
if spaceUser.SpaceID != exitSpaceId {
|
||||
response.Success(c).Data(resp).Send()
|
||||
return
|
||||
}
|
||||
|
||||
if spaceUser.Role == 0 {
|
||||
response.Fail(c).Message("请选择解散空间").Send()
|
||||
return
|
||||
@@ -364,8 +371,87 @@ func JoinSpace(ctx context.Context, c *app.RequestContext) {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Id = spaceByInviteCode.ID
|
||||
resp.Name = spaceByInviteCode.Name.String
|
||||
resp.SpaceId = spaceByInviteCode.ID
|
||||
resp.SpaceName = spaceByInviteCode.Name.String
|
||||
|
||||
response.Success(c).Data(resp).Send()
|
||||
}
|
||||
|
||||
// UpdateSpaceUserRole .
|
||||
// @router /space/updateRole [POST]
|
||||
func UpdateSpaceUserRole(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req space.UpdateSpaceUserRoleParams
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(space.UpdateSpaceUserRoleResult)
|
||||
|
||||
userID := middleware.GetUserID(ctx)
|
||||
spaceID := req.SpaceId
|
||||
updateUserID := req.UserId
|
||||
|
||||
hasPermission, err := hasSpacePermission(ctx, userID, spaceID)
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !hasPermission {
|
||||
response.Fail(c).Message("无权限操作该空间").Send()
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否在该空间
|
||||
updateSpaceUser, err := db.Queries.GetSpaceUser(ctx, updateUserID)
|
||||
|
||||
if err != nil {
|
||||
if errorx.IsNotFound(err) {
|
||||
response.Fail(c).Message("授权失败,该用户不在该空间").Send()
|
||||
return
|
||||
}
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if updateSpaceUser.SpaceID != spaceID {
|
||||
response.Fail(c).Message("授权失败,该用户不在该空间").Send()
|
||||
return
|
||||
}
|
||||
|
||||
// 更新
|
||||
err = db.WithTx(ctx, func(q *repo.Queries) error {
|
||||
err2 := q.UpdateSpaceUserRole(ctx, repo.UpdateSpaceUserRoleParams{
|
||||
Role: 1,
|
||||
SpaceID: spaceID,
|
||||
UserID: userID,
|
||||
})
|
||||
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
|
||||
err2 = q.UpdateSpaceUserRole(ctx, repo.UpdateSpaceUserRoleParams{
|
||||
Role: 0,
|
||||
SpaceID: spaceID,
|
||||
UserID: updateUserID,
|
||||
})
|
||||
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c).Data(resp).Send()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v6.33.1
|
||||
// protoc v4.25.3
|
||||
// source: api.proto
|
||||
|
||||
package api
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v6.33.1
|
||||
// protoc v4.25.3
|
||||
// source: space.proto
|
||||
|
||||
package space
|
||||
@@ -26,7 +26,7 @@ var file_space_proto_rawDesc = []byte{
|
||||
0x0a, 0x0b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x73,
|
||||
0x70, 0x61, 0x63, 0x65, 0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a,
|
||||
0x17, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2f, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70,
|
||||
0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x9e, 0x04, 0x0a, 0x0c, 0x53, 0x70, 0x61,
|
||||
0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x90, 0x05, 0x0a, 0x0c, 0x53, 0x70, 0x61,
|
||||
0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x54, 0x0a, 0x0b, 0x43, 0x72, 0x65,
|
||||
0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x12, 0x18, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x65,
|
||||
0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x72, 0x61,
|
||||
@@ -60,23 +60,32 @@ var file_space_proto_rawDesc = []byte{
|
||||
0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x53, 0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73,
|
||||
0x1a, 0x16, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x53, 0x70, 0x61,
|
||||
0x63, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x0f, 0xd2, 0xc1, 0x18, 0x0b, 0x2f, 0x73,
|
||||
0x70, 0x61, 0x63, 0x65, 0x2f, 0x6a, 0x6f, 0x69, 0x6e, 0x42, 0x18, 0x5a, 0x16, 0x61, 0x6c, 0x6c,
|
||||
0x61, 0x70, 0x70, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x73, 0x70,
|
||||
0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x70, 0x61, 0x63, 0x65, 0x2f, 0x6a, 0x6f, 0x69, 0x6e, 0x12, 0x70, 0x0a, 0x13, 0x55, 0x70, 0x64,
|
||||
0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65,
|
||||
0x12, 0x20, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53,
|
||||
0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x50, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x73, 0x1a, 0x20, 0x2e, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74,
|
||||
0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x65,
|
||||
0x73, 0x75, 0x6c, 0x74, 0x22, 0x15, 0xd2, 0xc1, 0x18, 0x11, 0x2f, 0x73, 0x70, 0x61, 0x63, 0x65,
|
||||
0x2f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x6f, 0x6c, 0x65, 0x42, 0x18, 0x5a, 0x16, 0x61,
|
||||
0x6c, 0x6c, 0x61, 0x70, 0x70, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f,
|
||||
0x73, 0x70, 0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var file_space_proto_goTypes = []interface{}{
|
||||
(*CreateSpaceParams)(nil), // 0: space.CreateSpaceParams
|
||||
(*DissolveSpaceParams)(nil), // 1: space.DissolveSpaceParams
|
||||
(*ExitSpaceParams)(nil), // 2: space.ExitSpaceParams
|
||||
(*ListSpaceUsersParams)(nil), // 3: space.ListSpaceUsersParams
|
||||
(*RemoveSpaceUserParams)(nil), // 4: space.RemoveSpaceUserParams
|
||||
(*JoinSpaceParams)(nil), // 5: space.JoinSpaceParams
|
||||
(*DissolveSpaceResult)(nil), // 6: space.DissolveSpaceResult
|
||||
(*ExitSpaceResult)(nil), // 7: space.ExitSpaceResult
|
||||
(*ListSpaceUsersResult)(nil), // 8: space.ListSpaceUsersResult
|
||||
(*RemoveSpaceUserResult)(nil), // 9: space.RemoveSpaceUserResult
|
||||
(*JoinSpaceResult)(nil), // 10: space.JoinSpaceResult
|
||||
(*CreateSpaceParams)(nil), // 0: space.CreateSpaceParams
|
||||
(*DissolveSpaceParams)(nil), // 1: space.DissolveSpaceParams
|
||||
(*ExitSpaceParams)(nil), // 2: space.ExitSpaceParams
|
||||
(*ListSpaceUsersParams)(nil), // 3: space.ListSpaceUsersParams
|
||||
(*RemoveSpaceUserParams)(nil), // 4: space.RemoveSpaceUserParams
|
||||
(*JoinSpaceParams)(nil), // 5: space.JoinSpaceParams
|
||||
(*UpdateSpaceUserRoleParams)(nil), // 6: space.UpdateSpaceUserRoleParams
|
||||
(*DissolveSpaceResult)(nil), // 7: space.DissolveSpaceResult
|
||||
(*ExitSpaceResult)(nil), // 8: space.ExitSpaceResult
|
||||
(*ListSpaceUsersResult)(nil), // 9: space.ListSpaceUsersResult
|
||||
(*RemoveSpaceUserResult)(nil), // 10: space.RemoveSpaceUserResult
|
||||
(*JoinSpaceResult)(nil), // 11: space.JoinSpaceResult
|
||||
(*UpdateSpaceUserRoleResult)(nil), // 12: space.UpdateSpaceUserRoleResult
|
||||
}
|
||||
var file_space_proto_depIdxs = []int32{
|
||||
0, // 0: space.SpaceService.CreateSpace:input_type -> space.CreateSpaceParams
|
||||
@@ -85,14 +94,16 @@ var file_space_proto_depIdxs = []int32{
|
||||
3, // 3: space.SpaceService.ListSpaceUsers:input_type -> space.ListSpaceUsersParams
|
||||
4, // 4: space.SpaceService.RemoveSpaceUser:input_type -> space.RemoveSpaceUserParams
|
||||
5, // 5: space.SpaceService.JoinSpace:input_type -> space.JoinSpaceParams
|
||||
0, // 6: space.SpaceService.CreateSpace:output_type -> space.CreateSpaceParams
|
||||
6, // 7: space.SpaceService.DissolveSpace:output_type -> space.DissolveSpaceResult
|
||||
7, // 8: space.SpaceService.ExitSpace:output_type -> space.ExitSpaceResult
|
||||
8, // 9: space.SpaceService.ListSpaceUsers:output_type -> space.ListSpaceUsersResult
|
||||
9, // 10: space.SpaceService.RemoveSpaceUser:output_type -> space.RemoveSpaceUserResult
|
||||
10, // 11: space.SpaceService.JoinSpace:output_type -> space.JoinSpaceResult
|
||||
6, // [6:12] is the sub-list for method output_type
|
||||
0, // [0:6] is the sub-list for method input_type
|
||||
6, // 6: space.SpaceService.UpdateSpaceUserRole:input_type -> space.UpdateSpaceUserRoleParams
|
||||
0, // 7: space.SpaceService.CreateSpace:output_type -> space.CreateSpaceParams
|
||||
7, // 8: space.SpaceService.DissolveSpace:output_type -> space.DissolveSpaceResult
|
||||
8, // 9: space.SpaceService.ExitSpace:output_type -> space.ExitSpaceResult
|
||||
9, // 10: space.SpaceService.ListSpaceUsers:output_type -> space.ListSpaceUsersResult
|
||||
10, // 11: space.SpaceService.RemoveSpaceUser:output_type -> space.RemoveSpaceUserResult
|
||||
11, // 12: space.SpaceService.JoinSpace:output_type -> space.JoinSpaceResult
|
||||
12, // 13: space.SpaceService.UpdateSpaceUserRole:output_type -> space.UpdateSpaceUserRoleResult
|
||||
7, // [7:14] is the sub-list for method output_type
|
||||
0, // [0:7] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v6.33.1
|
||||
// protoc v4.25.3
|
||||
// source: space/space_types.proto
|
||||
|
||||
package space
|
||||
@@ -74,7 +74,7 @@ type CreateSpaceResult struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id int64 `protobuf:"varint,1,opt,name=Id,proto3" form:"id" json:"id"`
|
||||
SpaceId int64 `protobuf:"varint,1,opt,name=SpaceId,proto3" form:"space_id" json:"space_id"`
|
||||
InviteCode string `protobuf:"bytes,2,opt,name=InviteCode,proto3" form:"invite_code" json:"invite_code"`
|
||||
}
|
||||
|
||||
@@ -110,9 +110,9 @@ func (*CreateSpaceResult) Descriptor() ([]byte, []int) {
|
||||
return file_space_space_types_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *CreateSpaceResult) GetId() int64 {
|
||||
func (x *CreateSpaceResult) GetSpaceId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
return x.SpaceId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -437,8 +437,8 @@ type JoinSpaceResult struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id int64 `protobuf:"varint,1,opt,name=Id,proto3" form:"id" json:"id"`
|
||||
Name string `protobuf:"bytes,2,opt,name=Name,proto3" form:"name" json:"name"`
|
||||
SpaceId int64 `protobuf:"varint,1,opt,name=SpaceId,proto3" form:"space_id" json:"space_id"`
|
||||
SpaceName string `protobuf:"bytes,2,opt,name=SpaceName,proto3" form:"space_name" json:"space_name"`
|
||||
}
|
||||
|
||||
func (x *JoinSpaceResult) Reset() {
|
||||
@@ -473,16 +473,16 @@ func (*JoinSpaceResult) Descriptor() ([]byte, []int) {
|
||||
return file_space_space_types_proto_rawDescGZIP(), []int{8}
|
||||
}
|
||||
|
||||
func (x *JoinSpaceResult) GetId() int64 {
|
||||
func (x *JoinSpaceResult) GetSpaceId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
return x.SpaceId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *JoinSpaceResult) GetName() string {
|
||||
func (x *JoinSpaceResult) GetSpaceName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
return x.SpaceName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -492,6 +492,8 @@ type ExitSpaceParams struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
SpaceId int64 `protobuf:"varint,1,opt,name=SpaceId,proto3" form:"space_id" json:"space_id"`
|
||||
}
|
||||
|
||||
func (x *ExitSpaceParams) Reset() {
|
||||
@@ -526,6 +528,13 @@ func (*ExitSpaceParams) Descriptor() ([]byte, []int) {
|
||||
return file_space_space_types_proto_rawDescGZIP(), []int{9}
|
||||
}
|
||||
|
||||
func (x *ExitSpaceParams) GetSpaceId() int64 {
|
||||
if x != nil {
|
||||
return x.SpaceId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type ExitSpaceResult struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -658,6 +667,108 @@ func (*RemoveSpaceUserResult) Descriptor() ([]byte, []int) {
|
||||
return file_space_space_types_proto_rawDescGZIP(), []int{12}
|
||||
}
|
||||
|
||||
// 更新权限
|
||||
type UpdateSpaceUserRoleParams struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
SpaceId int64 `protobuf:"varint,1,opt,name=SpaceId,proto3" form:"space_id" json:"space_id" vd:"$ != 0"`
|
||||
UserId int64 `protobuf:"varint,2,opt,name=UserId,proto3" form:"user_id" json:"user_id" vd:"$ != 0"`
|
||||
Role int32 `protobuf:"varint,3,opt,name=Role,proto3" form:"role" json:"role" vd:"$ != 0"`
|
||||
}
|
||||
|
||||
func (x *UpdateSpaceUserRoleParams) Reset() {
|
||||
*x = UpdateSpaceUserRoleParams{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_space_space_types_proto_msgTypes[13]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *UpdateSpaceUserRoleParams) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*UpdateSpaceUserRoleParams) ProtoMessage() {}
|
||||
|
||||
func (x *UpdateSpaceUserRoleParams) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_space_space_types_proto_msgTypes[13]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use UpdateSpaceUserRoleParams.ProtoReflect.Descriptor instead.
|
||||
func (*UpdateSpaceUserRoleParams) Descriptor() ([]byte, []int) {
|
||||
return file_space_space_types_proto_rawDescGZIP(), []int{13}
|
||||
}
|
||||
|
||||
func (x *UpdateSpaceUserRoleParams) GetSpaceId() int64 {
|
||||
if x != nil {
|
||||
return x.SpaceId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *UpdateSpaceUserRoleParams) GetUserId() int64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *UpdateSpaceUserRoleParams) GetRole() int32 {
|
||||
if x != nil {
|
||||
return x.Role
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type UpdateSpaceUserRoleResult struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *UpdateSpaceUserRoleResult) Reset() {
|
||||
*x = UpdateSpaceUserRoleResult{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_space_space_types_proto_msgTypes[14]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *UpdateSpaceUserRoleResult) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*UpdateSpaceUserRoleResult) ProtoMessage() {}
|
||||
|
||||
func (x *UpdateSpaceUserRoleResult) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_space_space_types_proto_msgTypes[14]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use UpdateSpaceUserRoleResult.ProtoReflect.Descriptor instead.
|
||||
func (*UpdateSpaceUserRoleResult) Descriptor() ([]byte, []int) {
|
||||
return file_space_space_types_proto_rawDescGZIP(), []int{14}
|
||||
}
|
||||
|
||||
var File_space_space_types_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_space_space_types_proto_rawDesc = []byte{
|
||||
@@ -666,10 +777,11 @@ var file_space_space_types_proto_rawDesc = []byte{
|
||||
0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x31, 0x0a, 0x11, 0x43,
|
||||
0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73,
|
||||
0x12, 0x1c, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x08,
|
||||
0xca, 0xbb, 0x18, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x5c,
|
||||
0xca, 0xbb, 0x18, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x6c,
|
||||
0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73,
|
||||
0x75, 0x6c, 0x74, 0x12, 0x16, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42,
|
||||
0x06, 0xca, 0xbb, 0x18, 0x02, 0x69, 0x64, 0x52, 0x02, 0x49, 0x64, 0x12, 0x2f, 0x0a, 0x0a, 0x49,
|
||||
0x75, 0x6c, 0x74, 0x12, 0x26, 0x0a, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x03, 0x42, 0x0c, 0xca, 0xbb, 0x18, 0x08, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f,
|
||||
0x69, 0x64, 0x52, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x2f, 0x0a, 0x0a, 0x49,
|
||||
0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42,
|
||||
0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x5f, 0x63, 0x6f, 0x64, 0x65,
|
||||
0x52, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x3d, 0x0a, 0x13,
|
||||
@@ -703,26 +815,42 @@ var file_space_space_types_proto_rawDesc = []byte{
|
||||
0x6d, 0x73, 0x12, 0x3a, 0x0a, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x1a, 0xca, 0xbb, 0x18, 0x0b, 0x69, 0x6e, 0x76, 0x69,
|
||||
0x74, 0x65, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0xda, 0xbb, 0x18, 0x07, 0x24, 0x20, 0x21, 0x3d, 0x20,
|
||||
0x27, 0x27, 0x52, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x47,
|
||||
0x27, 0x27, 0x52, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x67,
|
||||
0x0a, 0x0f, 0x4a, 0x6f, 0x69, 0x6e, 0x53, 0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c,
|
||||
0x74, 0x12, 0x16, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x06, 0xca,
|
||||
0xbb, 0x18, 0x02, 0x69, 0x64, 0x52, 0x02, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x04, 0x4e, 0x61, 0x6d,
|
||||
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x08, 0xca, 0xbb, 0x18, 0x04, 0x6e, 0x61, 0x6d,
|
||||
0x65, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x11, 0x0a, 0x0f, 0x45, 0x78, 0x69, 0x74, 0x53,
|
||||
0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x11, 0x0a, 0x0f, 0x45, 0x78,
|
||||
0x69, 0x74, 0x53, 0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x78, 0x0a,
|
||||
0x15, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72,
|
||||
0x74, 0x12, 0x26, 0x0a, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x03, 0x42, 0x0c, 0xca, 0xbb, 0x18, 0x08, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64,
|
||||
0x52, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x2c, 0x0a, 0x09, 0x53, 0x70, 0x61,
|
||||
0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0e, 0xca, 0xbb,
|
||||
0x18, 0x0a, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x09, 0x53, 0x70,
|
||||
0x61, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x39, 0x0a, 0x0f, 0x45, 0x78, 0x69, 0x74, 0x53,
|
||||
0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x26, 0x0a, 0x07, 0x53, 0x70,
|
||||
0x61, 0x63, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0c, 0xca, 0xbb, 0x18,
|
||||
0x08, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x52, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65,
|
||||
0x49, 0x64, 0x22, 0x11, 0x0a, 0x0f, 0x45, 0x78, 0x69, 0x74, 0x53, 0x70, 0x61, 0x63, 0x65, 0x52,
|
||||
0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x78, 0x0a, 0x15, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53,
|
||||
0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x30,
|
||||
0x0a, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42,
|
||||
0x16, 0xca, 0xbb, 0x18, 0x08, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18,
|
||||
0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64,
|
||||
0x12, 0x2d, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03,
|
||||
0x42, 0x15, 0xca, 0xbb, 0x18, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18,
|
||||
0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22,
|
||||
0x17, 0x0a, 0x15, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73,
|
||||
0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0xa4, 0x01, 0x0a, 0x19, 0x55, 0x70, 0x64,
|
||||
0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65,
|
||||
0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x30, 0x0a, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49,
|
||||
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x16, 0xca, 0xbb, 0x18, 0x08, 0x73, 0x70, 0x61,
|
||||
0x63, 0x65, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52,
|
||||
0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x2d, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72,
|
||||
0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x15, 0xca, 0xbb, 0x18, 0x07, 0x75, 0x73,
|
||||
0x65, 0x72, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52,
|
||||
0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x17, 0x0a, 0x15, 0x52, 0x65, 0x6d, 0x6f, 0x76,
|
||||
0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74,
|
||||
0x42, 0x18, 0x5a, 0x16, 0x61, 0x6c, 0x6c, 0x61, 0x70, 0x70, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d,
|
||||
0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x73, 0x70, 0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x26, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x18,
|
||||
0x03, 0x20, 0x01, 0x28, 0x05, 0x42, 0x12, 0xca, 0xbb, 0x18, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0xda,
|
||||
0xbb, 0x18, 0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x22,
|
||||
0x1b, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73,
|
||||
0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x18, 0x5a, 0x16,
|
||||
0x61, 0x6c, 0x6c, 0x61, 0x70, 0x70, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c,
|
||||
0x2f, 0x73, 0x70, 0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -737,21 +865,23 @@ func file_space_space_types_proto_rawDescGZIP() []byte {
|
||||
return file_space_space_types_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_space_space_types_proto_msgTypes = make([]protoimpl.MessageInfo, 13)
|
||||
var file_space_space_types_proto_msgTypes = make([]protoimpl.MessageInfo, 15)
|
||||
var file_space_space_types_proto_goTypes = []interface{}{
|
||||
(*CreateSpaceParams)(nil), // 0: space.CreateSpaceParams
|
||||
(*CreateSpaceResult)(nil), // 1: space.CreateSpaceResult
|
||||
(*DissolveSpaceParams)(nil), // 2: space.DissolveSpaceParams
|
||||
(*DissolveSpaceResult)(nil), // 3: space.DissolveSpaceResult
|
||||
(*ListSpaceUsersParams)(nil), // 4: space.ListSpaceUsersParams
|
||||
(*SpaceUser)(nil), // 5: space.SpaceUser
|
||||
(*ListSpaceUsersResult)(nil), // 6: space.ListSpaceUsersResult
|
||||
(*JoinSpaceParams)(nil), // 7: space.JoinSpaceParams
|
||||
(*JoinSpaceResult)(nil), // 8: space.JoinSpaceResult
|
||||
(*ExitSpaceParams)(nil), // 9: space.ExitSpaceParams
|
||||
(*ExitSpaceResult)(nil), // 10: space.ExitSpaceResult
|
||||
(*RemoveSpaceUserParams)(nil), // 11: space.RemoveSpaceUserParams
|
||||
(*RemoveSpaceUserResult)(nil), // 12: space.RemoveSpaceUserResult
|
||||
(*CreateSpaceParams)(nil), // 0: space.CreateSpaceParams
|
||||
(*CreateSpaceResult)(nil), // 1: space.CreateSpaceResult
|
||||
(*DissolveSpaceParams)(nil), // 2: space.DissolveSpaceParams
|
||||
(*DissolveSpaceResult)(nil), // 3: space.DissolveSpaceResult
|
||||
(*ListSpaceUsersParams)(nil), // 4: space.ListSpaceUsersParams
|
||||
(*SpaceUser)(nil), // 5: space.SpaceUser
|
||||
(*ListSpaceUsersResult)(nil), // 6: space.ListSpaceUsersResult
|
||||
(*JoinSpaceParams)(nil), // 7: space.JoinSpaceParams
|
||||
(*JoinSpaceResult)(nil), // 8: space.JoinSpaceResult
|
||||
(*ExitSpaceParams)(nil), // 9: space.ExitSpaceParams
|
||||
(*ExitSpaceResult)(nil), // 10: space.ExitSpaceResult
|
||||
(*RemoveSpaceUserParams)(nil), // 11: space.RemoveSpaceUserParams
|
||||
(*RemoveSpaceUserResult)(nil), // 12: space.RemoveSpaceUserResult
|
||||
(*UpdateSpaceUserRoleParams)(nil), // 13: space.UpdateSpaceUserRoleParams
|
||||
(*UpdateSpaceUserRoleResult)(nil), // 14: space.UpdateSpaceUserRoleResult
|
||||
}
|
||||
var file_space_space_types_proto_depIdxs = []int32{
|
||||
5, // 0: space.ListSpaceUsersResult.users:type_name -> space.SpaceUser
|
||||
@@ -924,6 +1054,30 @@ func file_space_space_types_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_space_space_types_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*UpdateSpaceUserRoleParams); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_space_space_types_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*UpdateSpaceUserRoleResult); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
@@ -931,7 +1085,7 @@ func file_space_space_types_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_space_space_types_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 13,
|
||||
NumMessages: 15,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
||||
@@ -3,10 +3,8 @@ package middleware
|
||||
import (
|
||||
"allapp/utils/jwtx"
|
||||
"allapp/utils/pathx"
|
||||
"allapp/utils/redisx"
|
||||
"allapp/utils/response"
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
@@ -19,7 +17,6 @@ type ctxKeyUser struct{}
|
||||
type ContextUser struct {
|
||||
UserID int64
|
||||
DeviceUUID string
|
||||
SpaceID int64
|
||||
}
|
||||
|
||||
// Auth 中间件,支持 header 中传 spaceid 并校验权限
|
||||
@@ -50,27 +47,9 @@ func Auth() app.HandlerFunc {
|
||||
|
||||
userID := verifyToken.UserID
|
||||
|
||||
// 获取 header 中的 spaceid
|
||||
spaceIDStr := strings.TrimSpace(string(c.GetHeader("X-Space-Id")))
|
||||
spaceID, err := strconv.ParseInt(spaceIDStr, 10, 64)
|
||||
if err != nil || spaceID == 0 {
|
||||
response.Fail(c).Code(response.HttpCode.ErrSpaceRequired).Message("请先选择空间").Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 判断用户是否在该空间
|
||||
inSpace, err := redisx.InSpace(ctx, userID, spaceID)
|
||||
if err != nil || !inSpace {
|
||||
response.Fail(c).Code(response.HttpCode.ErrSpaceRequired).Message("无权限访问该空间").Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 设置 context
|
||||
user := &ContextUser{
|
||||
UserID: userID,
|
||||
SpaceID: spaceID,
|
||||
UserID: userID,
|
||||
}
|
||||
ctx = setContextUser(ctx, user)
|
||||
|
||||
@@ -92,11 +71,6 @@ func GetUserID(ctx context.Context) int64 {
|
||||
return GetContextUser(ctx).UserID
|
||||
}
|
||||
|
||||
// GetSpaceID 从 context 获取当前 spaceid
|
||||
func GetSpaceID(ctx context.Context) int64 {
|
||||
return GetContextUser(ctx).SpaceID
|
||||
}
|
||||
|
||||
// 内部中间件设置 ContextUser
|
||||
func setContextUser(ctx context.Context, user *ContextUser) context.Context {
|
||||
return context.WithValue(ctx, ctxKeyUser{}, user)
|
||||
|
||||
@@ -45,3 +45,13 @@ func _listspaceusersMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _updateroleMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _updatespaceuserroleMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
@@ -24,6 +24,7 @@ func Register(r *server.Hertz) {
|
||||
_space.POST("/exit", append(_exitspaceMw(), space.ExitSpace)...)
|
||||
_space.POST("/join", append(_joinspaceMw(), space.JoinSpace)...)
|
||||
_space.POST("/remove", append(_removespaceuserMw(), space.RemoveSpaceUser)...)
|
||||
_space.POST("/updateRole", append(_updatespaceuserroleMw(), space.UpdateSpaceUserRole)...)
|
||||
_space.POST("/users", append(_listspaceusersMw(), space.ListSpaceUsers)...)
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,4 @@ WHERE space_id = $1;
|
||||
-- name: UpdateSpaceUserRole :exec
|
||||
UPDATE space_user
|
||||
SET role = $1
|
||||
WHERE user_id = $2;
|
||||
WHERE user_id = $2 AND space_id = $3;
|
||||
@@ -143,16 +143,17 @@ func (q *Queries) ListSpaceUsers(ctx context.Context, spaceID int64) ([]ListSpac
|
||||
const updateSpaceUserRole = `-- name: UpdateSpaceUserRole :exec
|
||||
UPDATE space_user
|
||||
SET role = $1
|
||||
WHERE user_id = $2
|
||||
WHERE user_id = $2 AND space_id = $3
|
||||
`
|
||||
|
||||
type UpdateSpaceUserRoleParams struct {
|
||||
Role int32
|
||||
UserID int64
|
||||
Role int32
|
||||
UserID int64
|
||||
SpaceID int64
|
||||
}
|
||||
|
||||
// 修改角色
|
||||
func (q *Queries) UpdateSpaceUserRole(ctx context.Context, arg UpdateSpaceUserRoleParams) error {
|
||||
_, err := q.db.Exec(ctx, updateSpaceUserRole, arg.Role, arg.UserID)
|
||||
_, err := q.db.Exec(ctx, updateSpaceUserRole, arg.Role, arg.UserID, arg.SpaceID)
|
||||
return err
|
||||
}
|
||||
@@ -38,4 +38,9 @@ service SpaceService {
|
||||
rpc JoinSpace(JoinSpaceParams) returns (JoinSpaceResult) {
|
||||
option (api.post) = "/space/join";
|
||||
};
|
||||
|
||||
// 赋予权限
|
||||
rpc UpdateSpaceUserRole(UpdateSpaceUserRoleParams) returns (UpdateSpaceUserRoleResult) {
|
||||
option (api.post) = "/space/updateRole";
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ message CreateSpaceParams {
|
||||
}
|
||||
|
||||
message CreateSpaceResult {
|
||||
int64 Id = 1 [(api.body)="id"];
|
||||
int64 SpaceId = 1 [(api.body)="space_id"];
|
||||
string InviteCode = 2 [(api.body)="invite_code"];
|
||||
}
|
||||
|
||||
@@ -48,13 +48,13 @@ message JoinSpaceParams {
|
||||
}
|
||||
|
||||
message JoinSpaceResult {
|
||||
int64 Id = 1 [(api.body)="id"];
|
||||
string Name = 2 [(api.body)="name"];
|
||||
int64 SpaceId = 1 [(api.body)="space_id"];
|
||||
string SpaceName = 2 [(api.body)="space_name"];
|
||||
}
|
||||
|
||||
// 退出空间
|
||||
message ExitSpaceParams {
|
||||
|
||||
int64 SpaceId = 1 [(api.body)="space_id"];
|
||||
}
|
||||
|
||||
message ExitSpaceResult {
|
||||
@@ -71,4 +71,13 @@ message RemoveSpaceUserResult {
|
||||
|
||||
}
|
||||
|
||||
// 更新权限
|
||||
message UpdateSpaceUserRoleParams {
|
||||
int64 SpaceId = 1 [(api.body) = "space_id",(api.vd)="$ != 0"];
|
||||
int64 UserId = 2 [(api.body) = "user_id",(api.vd)="$ != 0"];
|
||||
int32 Role = 3 [(api.body) = "role",(api.vd)="$ != 0"];
|
||||
}
|
||||
|
||||
message UpdateSpaceUserRoleResult {
|
||||
|
||||
}
|
||||
@@ -1,20 +1,54 @@
|
||||
import type { JoinSpaceParams, KickOutUserParams, ListSpaceUsersResult } from '@/types/space/space'
|
||||
import type {
|
||||
CreateSpaceParams,
|
||||
CreateSpaceResult,
|
||||
DissolveSpaceParams,
|
||||
DissolveSpaceResult,
|
||||
ExitSpaceParams,
|
||||
ExitSpaceResult,
|
||||
JoinSpaceParams,
|
||||
JoinSpaceResult,
|
||||
ListSpaceUsersParams,
|
||||
ListSpaceUsersResult,
|
||||
RemoveSpaceUserParams,
|
||||
RemoveSpaceUserResult,
|
||||
UpdateSpaceUserRoleParams,
|
||||
UpdateSpaceUserRoleResult,
|
||||
} from '@/types/space/space'
|
||||
import alovaInstance from '../../index'
|
||||
|
||||
const API_PREFIX = '/space'
|
||||
|
||||
// Join Space API
|
||||
export function joinSpaceApi(params: JoinSpaceParams) {
|
||||
return alovaInstance.Post<ResponseData<void>>(`${API_PREFIX}/join`, params)
|
||||
return alovaInstance.Post<ResponseData<JoinSpaceResult>>(`${API_PREFIX}/join`, params)
|
||||
}
|
||||
|
||||
export function kickOutUserApi(params: KickOutUserParams) {
|
||||
return alovaInstance.Post<ResponseData<void>>(`${API_PREFIX}/kick`, params)
|
||||
// Create Space API
|
||||
export function createSpaceApi(params: CreateSpaceParams) {
|
||||
return alovaInstance.Post<ResponseData<CreateSpaceResult>>(`${API_PREFIX}/create`, params)
|
||||
}
|
||||
|
||||
export function quitSpaceApi() {
|
||||
return alovaInstance.Post<ResponseData<void>>(`${API_PREFIX}/quit`)
|
||||
// Dissolve Space API
|
||||
export function dissolveSpaceApi(params: DissolveSpaceParams) {
|
||||
return alovaInstance.Post<ResponseData<DissolveSpaceResult>>(`${API_PREFIX}/dissolve`, params)
|
||||
}
|
||||
|
||||
export function listSpaceUsersApi() {
|
||||
return alovaInstance.Post<ResponseData<ListSpaceUsersResult>>(`${API_PREFIX}/users`)
|
||||
// Exit Space API
|
||||
export function exitSpaceApi(params: ExitSpaceParams) {
|
||||
return alovaInstance.Post<ResponseData<ExitSpaceResult>>(`${API_PREFIX}/exit`, params)
|
||||
}
|
||||
|
||||
// Remove Space User API
|
||||
export function removeSpaceUserApi(params: RemoveSpaceUserParams) {
|
||||
return alovaInstance.Post<ResponseData<RemoveSpaceUserResult>>(`${API_PREFIX}/remove`, params)
|
||||
}
|
||||
|
||||
// Update Role API
|
||||
export function updateSpaceUserRoleApi(params: UpdateSpaceUserRoleParams) {
|
||||
return alovaInstance.Post<ResponseData<UpdateSpaceUserRoleResult>>(`${API_PREFIX}/updateRole`, params)
|
||||
}
|
||||
|
||||
// List Space Users API
|
||||
export function listSpaceUsersApi(params: ListSpaceUsersParams) {
|
||||
return alovaInstance.Post<ResponseData<ListSpaceUsersResult>>(`${API_PREFIX}/users`, params)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { ListUserSpacesResult } from '@/types/user'
|
||||
import type { UserSpace } from '@/types/user'
|
||||
import alovaInstance from '../index'
|
||||
|
||||
const API_PREFIX = '/user'
|
||||
|
||||
export function listUserSpacesApi() {
|
||||
return alovaInstance.Post<ResponseData<ListUserSpacesResult>>(`${API_PREFIX}/spaces`)
|
||||
export function getUserSpaceApi() {
|
||||
return alovaInstance.Post<ResponseData<UserSpace>>(`${API_PREFIX}/space`)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { create } from 'zustand'
|
||||
import { getUserSpaceApi } from '@/request/api/space/spaceUser'
|
||||
import { getUserSpaceApi } from '@/request/api/user'
|
||||
import { useMoneyCategoryStore } from './moneyCategory'
|
||||
import { useNavStore } from './navigation'
|
||||
import { useSpaceStore } from './space'
|
||||
@@ -38,7 +38,7 @@ export const useAppStore = create<AppState>((set, get) => ({
|
||||
|
||||
// 获取空间信息
|
||||
const res = await getUserSpaceApi()
|
||||
spaceStore.setUserSpace(res.data)
|
||||
spaceStore.setUserSpace(res.data)
|
||||
}
|
||||
catch (err) {
|
||||
console.error('app init error:', err)
|
||||
|
||||
@@ -1,22 +1,66 @@
|
||||
// 创建空间
|
||||
export interface CreateSpaceParams {
|
||||
name: string
|
||||
}
|
||||
export interface CreateSpaceResult {
|
||||
space_id: number
|
||||
invite_code: string
|
||||
}
|
||||
|
||||
// 解散空间
|
||||
export interface DissolveSpaceParams {
|
||||
space_id: number
|
||||
}
|
||||
export interface DissolveSpaceResult {
|
||||
}
|
||||
|
||||
// 加入空间
|
||||
export interface JoinSpaceParams {
|
||||
invite_code: string
|
||||
}
|
||||
export interface JoinSpaceResult {
|
||||
space_id: number
|
||||
space_name: string
|
||||
}
|
||||
|
||||
// 退出空间
|
||||
export interface ExitSpaceParams {
|
||||
space_id: number
|
||||
}
|
||||
export interface ExitSpaceResult {
|
||||
}
|
||||
|
||||
// 踢出用户
|
||||
export interface KickOutUserParams {
|
||||
export interface RemoveSpaceUserParams {
|
||||
space_id: number
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface RemoveSpaceUserResult {
|
||||
}
|
||||
|
||||
// 更新用户权限
|
||||
export interface UpdateSpaceUserRoleParams {
|
||||
space_id: number
|
||||
user_id: number
|
||||
role: number
|
||||
}
|
||||
export interface UpdateSpaceUserRoleResult {
|
||||
}
|
||||
|
||||
// 空间用户列表
|
||||
export interface SpaceUser {
|
||||
user_id: number
|
||||
user_name: number
|
||||
user_avatar: string
|
||||
id: number
|
||||
name: number
|
||||
avatar: string
|
||||
role: number
|
||||
last_login_time: number
|
||||
}
|
||||
|
||||
export interface ListSpaceUsersParams {
|
||||
space_id: number
|
||||
}
|
||||
|
||||
export interface ListSpaceUsersResult {
|
||||
users: SpaceUser[]
|
||||
}
|
||||
|
||||
@@ -4,7 +4,3 @@ export interface UserSpace {
|
||||
invite_code: string
|
||||
role: number
|
||||
}
|
||||
|
||||
export interface ListUserSpacesResult {
|
||||
spaces: UserSpace[]
|
||||
}
|
||||
Reference in new issue
Block a user