u
This commit is contained in:
1 parent
cf9b01e633
commit
4dcac7b5a0
16 files changed
+139
-69
No files matched your search
@@ -301,7 +301,7 @@ func GetUserSpace(ctx context.Context, c *app.RequestContext) {
|
||||
|
||||
userID := middleware.GetUserID(ctx)
|
||||
|
||||
spaceByUserId, err := db.Queries.GetSpaceByUserId(ctx, userID)
|
||||
spaceByUserId, err := db.Queries.GetUserSpaceDetail(ctx, userID)
|
||||
|
||||
if err != nil {
|
||||
if errorx.IsNotFound(err) {
|
||||
@@ -313,9 +313,10 @@ func GetUserSpace(ctx context.Context, c *app.RequestContext) {
|
||||
}
|
||||
}
|
||||
|
||||
resp.Id = spaceByUserId.ID
|
||||
resp.Name = spaceByUserId.Name.String
|
||||
resp.InviteCode = spaceByUserId.InviteCode
|
||||
resp.SpaceId = spaceByUserId.SpaceID
|
||||
resp.SpaceName = spaceByUserId.SpaceName.String
|
||||
resp.InviteCode = spaceByUserId.SpaceInviteCode
|
||||
resp.Role = spaceByUserId.Role
|
||||
|
||||
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 v4.25.3
|
||||
// protoc v6.33.1
|
||||
// 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 v4.25.3
|
||||
// protoc v6.33.1
|
||||
// source: space.proto
|
||||
|
||||
package space
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v4.25.3
|
||||
// protoc v6.33.1
|
||||
// source: space/space_types.proto
|
||||
|
||||
package space
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v4.25.3
|
||||
// protoc v6.33.1
|
||||
// source: space/space_user_types.proto
|
||||
|
||||
package space
|
||||
@@ -573,9 +573,10 @@ type GetUserSpaceResult 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"`
|
||||
InviteCode string `protobuf:"bytes,3,opt,name=InviteCode,proto3" form:"invite_code" json:"invite_code"`
|
||||
Role int32 `protobuf:"varint,4,opt,name=Role,proto3" form:"role" json:"role"`
|
||||
}
|
||||
|
||||
func (x *GetUserSpaceResult) Reset() {
|
||||
@@ -610,16 +611,16 @@ func (*GetUserSpaceResult) Descriptor() ([]byte, []int) {
|
||||
return file_space_space_user_types_proto_rawDescGZIP(), []int{12}
|
||||
}
|
||||
|
||||
func (x *GetUserSpaceResult) GetId() int64 {
|
||||
func (x *GetUserSpaceResult) GetSpaceId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
return x.SpaceId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *GetUserSpaceResult) GetName() string {
|
||||
func (x *GetUserSpaceResult) GetSpaceName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
return x.SpaceName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -631,6 +632,13 @@ func (x *GetUserSpaceResult) GetInviteCode() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GetUserSpaceResult) GetRole() int32 {
|
||||
if x != nil {
|
||||
return x.Role
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_space_space_user_types_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_space_space_user_types_proto_rawDesc = []byte{
|
||||
@@ -683,17 +691,21 @@ var file_space_space_user_types_proto_rawDesc = []byte{
|
||||
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, 0x22, 0x14, 0x0a, 0x12,
|
||||
0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x53, 0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x73, 0x22, 0x7b, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 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, 0x12, 0x2f,
|
||||
0x0a, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 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, 0x42,
|
||||
0x22, 0x5a, 0x20, 0x63, 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x65,
|
||||
0x2d, 0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x73, 0x70,
|
||||
0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x6d, 0x73, 0x22, 0xb9, 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x53, 0x70,
|
||||
0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 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, 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, 0x12,
|
||||
0x2f, 0x0a, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 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,
|
||||
0x12, 0x1c, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x42, 0x08,
|
||||
0xca, 0xbb, 0x18, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x52, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x42, 0x22,
|
||||
0x5a, 0x20, 0x63, 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2d,
|
||||
0x67, 0x6f, 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 (
|
||||
|
||||
@@ -35,3 +35,15 @@ ORDER BY su.join_time ASC;
|
||||
-- name: GetSpaceUserByUserId :one
|
||||
SELECT * FROM space_user WHERE user_id = $1;
|
||||
|
||||
-- name: GetUserSpaceDetail :one
|
||||
SELECT
|
||||
s.id AS space_id,
|
||||
s.name AS space_name,
|
||||
s.invite_code AS space_invite_code,
|
||||
su.id AS space_user_id,
|
||||
su.user_id,
|
||||
su.role
|
||||
FROM space_user su
|
||||
JOIN space s ON su.space_id = s.id
|
||||
WHERE su.user_id = $1;
|
||||
|
||||
@@ -48,6 +48,42 @@ func (q *Queries) GetSpaceUserByUserId(ctx context.Context, userID int64) (Space
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserSpaceDetail = `-- name: GetUserSpaceDetail :one
|
||||
SELECT
|
||||
s.id AS space_id,
|
||||
s.name AS space_name,
|
||||
s.invite_code AS space_invite_code,
|
||||
su.id AS space_user_id,
|
||||
su.user_id,
|
||||
su.role
|
||||
FROM space_user su
|
||||
JOIN space s ON su.space_id = s.id
|
||||
WHERE su.user_id = $1
|
||||
`
|
||||
|
||||
type GetUserSpaceDetailRow struct {
|
||||
SpaceID int64
|
||||
SpaceName pgtype.Text
|
||||
SpaceInviteCode string
|
||||
SpaceUserID int64
|
||||
UserID int64
|
||||
Role int32
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserSpaceDetail(ctx context.Context, userID int64) (GetUserSpaceDetailRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUserSpaceDetail, userID)
|
||||
var i GetUserSpaceDetailRow
|
||||
err := row.Scan(
|
||||
&i.SpaceID,
|
||||
&i.SpaceName,
|
||||
&i.SpaceInviteCode,
|
||||
&i.SpaceUserID,
|
||||
&i.UserID,
|
||||
&i.Role,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertSpaceUser = `-- name: InsertSpaceUser :exec
|
||||
INSERT INTO space_user(id,space_id,user_id,role)
|
||||
VALUES ($1,$2,$3,$4)
|
||||
|
||||
@@ -63,7 +63,8 @@ message GetUserSpaceParams{
|
||||
|
||||
}
|
||||
message GetUserSpaceResult{
|
||||
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"];
|
||||
string InviteCode = 3[(api.body)="invite_code"];
|
||||
int32 Role = 4[(api.body)="role"];
|
||||
}
|
||||
Reference in new issue
Block a user