Commit d5cdb5f2 by Li Feifei

实现聊天室的curd

parent c6573c1c
......@@ -54,7 +54,7 @@ func newMysqlClient() {
log.Println("db connect error => ", err)
return
}
orm.RegisterModel(new(CompanyApp), new(ImBase))
orm.RegisterModel(new(CompanyApp), new(ImBase), new(ImChatRoom))
MysqlClient = orm.NewOrm()
log.Println("MySQL connect success")
}
......@@ -14,3 +14,14 @@ type ImBase struct {
MultideviceType int64
MsgHookUrl string
}
type ImChatRoom struct {
Id int
Creator string
Name string
Announcement string
Ext string
Status int
Createtime string
Updatetime string
}
package helper
import (
"errors"
"im-microservice/db"
"im-microservice/pb"
"im-microservice/validator_struct"
"github.com/astaxie/beego/orm"
)
const (
chat_table_name = "im_chat_room"
chat_room_id = "id"
chat_creator = "creator"
chat_room = "name"
chat_announcement = "announcement"
chat_status = "status"
chat_create_time = "createtime"
)
func AddChatRoom (addStruct *validator_struct.ChatRoomAddStruct) (int64, error) {
var chat db.ImChatRoom
now := GetNowTime()
chat.Name = addStruct.Name
chat.Announcement = addStruct.Announcement
chat.Creator = addStruct.Creator
chat.Status = 1;
chat.Createtime = now
chat.Updatetime = now
room_id, err := db.MysqlClient.Insert(&chat)
return room_id, err
}
func UpdateChatRoom( update *validator_struct.ChatRoomUpdate) error {
orm_params := make(orm.Params)
if update.Status != 0 {
orm_params[chat_status] = update.Status
}
if update.Announcement != "" {
orm_params[chat_announcement] = update.Announcement
}
if update.Name != "" {
orm_params[chat_room] = update.Name
}
if len(orm_params) == 0 {
return errors.New("修改房间的参数为空")
}
orm_params["updatetime"] = GetNowTime()
_, err := db.MysqlClient.QueryTable(chat_table_name).Filter(chat_room_id, update.RoomId).Update(orm_params)
return err
}
func DeleteChatRoom(room_id int64) error {
_, err := db.MysqlClient.QueryTable(chat_table_name).Filter(chat_room_id, room_id).Delete()
return err
}
func ChatRoomInfo(info *validator_struct.ChatRoomInfo) (res db.ImChatRoom, err error) {
err = db.MysqlClient.QueryTable(chat_table_name).Filter(chat_room_id, info.RoomId).One(&res)
return
}
func GetChatRooms(request *pb.ChatRoomAllRequest) (results map[string]interface{}, err error) {
var (
announcement = request.GetAnnouncement()
name = request.GetName()
status = request.GetStatus()
creator = request.GetCreator()
createtime = request.GetCreatetime()
page = request.GetPage()
)
if page == 0 {
page = 1;
}
count_db := db.MysqlClient.QueryTable(chat_table_name)
if announcement != "" {
count_db = count_db.Filter(chat_announcement + "__icontains", announcement)
}
if name != "" {
count_db = count_db.Filter(chat_room + "__icontains", name)
}
if status != 0 {
count_db = count_db.Filter(chat_status, status)
}
if creator != "" {
count_db = count_db.Filter(chat_creator, creator)
}
if createtime != "" {
count_db = count_db.Filter(chat_create_time + "__age__gte", createtime)
}
ctn, err := count_db.Count()
if err != nil {
return
}
if ctn == 0 {
err = errors.New("没有查询到任何数据")
return
}
// 获取查询条件聊天室的总数
offset, total_page := Paginate(ctn, 20, page)
// 查询数据
var chat_rooms []db.ImChatRoom
if _, err = count_db.Limit(20, offset).All(&chat_rooms); err != nil {
return
}
results = make(map[string]interface{})
results["list"] = chat_rooms
results["total_page"] = total_page
results["total_count"] = ctn
results["page"] = page
results["page_size"] = 20
return
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import (
"errors"
"im-microservice/db"
"log"
"math"
"time"
"gopkg.in/go-playground/validator.v9"
......@@ -37,3 +38,9 @@ func GetCode(mobile string) (string, error) {
return val, nil
}
func Paginate(count, step, page int64) (int64, int64) {
offset := step * (page - 1)
total := int64(math.Ceil(float64(count) / float64(step)))
return offset, total
}
......@@ -17,10 +17,7 @@ const (
func GetImBaseByUserId(user_id int64) (db.ImBase, error) {
var im_base db.ImBase
err := db.MysqlClient.QueryTable(b_table_name).Filter(b_user_id, user_id).One(&im_base)
if err != nil {
return im_base, err
}
return im_base, nil
}
func AddImBase(im *validator_struct.ConfigureAddStruct) error {
......@@ -28,41 +25,34 @@ func AddImBase(im *validator_struct.ConfigureAddStruct) error {
configure.CompanyUserId = im.CompanyUserId
configure.MsgHookUrl = im.MsgHookUrl
configure.MultideviceType = im.MultideviceType
if _, err := db.MysqlClient.Insert(configure); err != nil {
_, err := db.MysqlClient.Insert(configure);
return err
}
return nil
}
func DelConfigure(user_id int64) error {
configure := new(db.ImBase)
configure.CompanyUserId = user_id
if _, err := db.MysqlClient.Delete(configure); err != nil {
_, err := db.MysqlClient.Delete(configure);
return err
}
return nil
}
func GetConfigureAll() []*db.ImBase{
func GetConfigureAll() []*db.ImBase {
var configurs []*db.ImBase
_, _ = db.MysqlClient.QueryTable(b_table_name).All(&configurs)
return configurs
}
func UpdateConfiguer(im *validator_struct.ConfigureUpdateStruct ) error {
func UpdateConfiguer(im *validator_struct.ConfigureUpdateStruct) error {
orm_params := make(orm.Params)
if im.MsgHookUrl != "" {
orm_params["msg_hook_url"] = im.MsgHookUrl
orm_params[b_url] = im.MsgHookUrl
}
if im.MultideviceType != 0 {
orm_params["multidevice_type"] = im.MultideviceType
orm_params[b_type] = im.MultideviceType
}
if len(orm_params) == 0 {
return errors.New("没有数据更改")
}
_, err := db.MysqlClient.QueryTable(b_table_name).Filter(b_user_id, im.CompanyUserId).Update(orm_params)
if err != nil {
return err
}
return nil
}
......@@ -13,6 +13,7 @@ import (
"im-microservice/helper"
"im-microservice/pb"
"im-microservice/sevice/im_chat_room"
ic "im-microservice/sevice/im_configure"
"golang.org/x/net/context"
......@@ -101,11 +102,12 @@ func main() {
log.Fatalf("failed to listen: %v", err)
}
var opts []grpc.ServerOption
opts = append(opts, grpc.UnaryInterceptor(auth))
s := grpc.NewServer(opts...)
//s := grpc.NewServer()
//var opts []grpc.ServerOption
//opts = append(opts, grpc.UnaryInterceptor(auth))
//s := grpc.NewServer(opts...)
s := grpc.NewServer()
pb.RegisterConfigureSeviceServer(s, &ic.ConfigureSevice{})
pb.RegisterChatRoomServiceServer(s, &im_chat_room.ImChatRoomService{})
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
......
......@@ -96,19 +96,97 @@ func (x *Common) GetChecksum() string {
return ""
}
type Page struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
PagetNo int64 `protobuf:"varint,1,opt,name=PagetNo,proto3" json:"PagetNo,omitempty"`
PageSize int64 `protobuf:"varint,2,opt,name=PageSize,proto3" json:"PageSize,omitempty"`
TotalPage int64 `protobuf:"varint,3,opt,name=TotalPage,proto3" json:"TotalPage,omitempty"`
TotalCount int64 `protobuf:"varint,4,opt,name=TotalCount,proto3" json:"TotalCount,omitempty"`
}
func (x *Page) Reset() {
*x = Page{}
if protoimpl.UnsafeEnabled {
mi := &file_u_proto_common_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Page) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Page) ProtoMessage() {}
func (x *Page) ProtoReflect() protoreflect.Message {
mi := &file_u_proto_common_proto_msgTypes[1]
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 Page.ProtoReflect.Descriptor instead.
func (*Page) Descriptor() ([]byte, []int) {
return file_u_proto_common_proto_rawDescGZIP(), []int{1}
}
func (x *Page) GetPagetNo() int64 {
if x != nil {
return x.PagetNo
}
return 0
}
func (x *Page) GetPageSize() int64 {
if x != nil {
return x.PageSize
}
return 0
}
func (x *Page) GetTotalPage() int64 {
if x != nil {
return x.TotalPage
}
return 0
}
func (x *Page) GetTotalCount() int64 {
if x != nil {
return x.TotalCount
}
return 0
}
var File_u_proto_common_proto protoreflect.FileDescriptor
var file_u_proto_common_proto_rawDesc = []byte{
0x0a, 0x14, 0x75, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x22, 0x6c,
0x0a, 0x06, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x70, 0x70, 0x6b,
0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x41, 0x70, 0x70, 0x6b, 0x65, 0x79,
0x12, 0x14, 0x0a, 0x05, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x05, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x75, 0x72, 0x74, 0x69, 0x6d,
0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x43, 0x75, 0x72, 0x74, 0x69, 0x6d, 0x65,
0x12, 0x1a, 0x0a, 0x08, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x18, 0x04, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0x6c, 0x0a, 0x06, 0x43, 0x6f,
0x6d, 0x6d, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x70, 0x70, 0x6b, 0x65, 0x79, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x41, 0x70, 0x70, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05,
0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x4e, 0x6f, 0x6e,
0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x75, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20,
0x01, 0x28, 0x09, 0x52, 0x07, 0x43, 0x75, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08,
0x43, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x43, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x75, 0x6d, 0x22, 0x7a, 0x0a, 0x04, 0x50, 0x61, 0x67, 0x65,
0x12, 0x18, 0x0a, 0x07, 0x50, 0x61, 0x67, 0x65, 0x74, 0x4e, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28,
0x03, 0x52, 0x07, 0x50, 0x61, 0x67, 0x65, 0x74, 0x4e, 0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x61,
0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x50, 0x61,
0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x50,
0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x54, 0x6f, 0x74, 0x61, 0x6c,
0x50, 0x61, 0x67, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75,
0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x43,
0x6f, 0x75, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
......@@ -123,9 +201,10 @@ func file_u_proto_common_proto_rawDescGZIP() []byte {
return file_u_proto_common_proto_rawDescData
}
var file_u_proto_common_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_u_proto_common_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_u_proto_common_proto_goTypes = []interface{}{
(*Common)(nil), // 0: common.Common
(*Common)(nil), // 0: pb.Common
(*Page)(nil), // 1: pb.Page
}
var file_u_proto_common_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
......@@ -153,6 +232,18 @@ func file_u_proto_common_proto_init() {
return nil
}
}
file_u_proto_common_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Page); 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{
......@@ -160,7 +251,7 @@ func file_u_proto_common_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_u_proto_common_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},
......
package im_chat_room
import (
"context"
"im-microservice/db"
"im-microservice/helper"
"im-microservice/pb"
vs "im-microservice/validator_struct"
)
type ImChatRoomService struct {
pb.UnimplementedChatRoomServiceServer
}
func (cr *ImChatRoomService) Add(ctx context.Context, in *pb.ChatRoomAddRequest) (reply *pb.ChatRoomAddReply, err error) {
chat_room_struct := vs.NewAddChatRoom(in)
if err = helper.Valiator(chat_room_struct); err != nil {
return
}
room_id, err := helper.AddChatRoom(chat_room_struct)
if err != nil {
return
}
reply = &pb.ChatRoomAddReply{}
reply.Id = room_id
return
}
func (cr *ImChatRoomService) Update(ctx context.Context, in *pb.ChatRoomUpdateRequest) (reply *pb.ChatRoomUpdateReply, err error) {
chat_room_struct := vs.NewChatRoomUpdate(in)
if err = helper.Valiator(chat_room_struct); err != nil {
return
}
if err = helper.UpdateChatRoom(chat_room_struct); err != nil {
return
}
reply = &pb.ChatRoomUpdateReply{}
return
}
func (cr *ImChatRoomService) Delete(ctx context.Context, in *pb.ChatRoomDelRequest) (reply *pb.ChatRoomDelReply, err error) {
chat_room_struct := vs.NewChatRoomDel(in)
if err = helper.Valiator(chat_room_struct); err != nil {
return
}
if err = helper.DeleteChatRoom(chat_room_struct.RoomId); err != nil {
return
}
reply = &pb.ChatRoomDelReply{}
return
}
func (cr *ImChatRoomService) Info(ctx context.Context, in *pb.ChatRoomInfoRequest) (reply *pb.ChatRoomInfoReply, err error) {
chat_room_struct := vs.NewChatRoomInfo(in)
if err = helper.Valiator(chat_room_struct); err != nil {
return
}
db_chat_room, err := helper.ChatRoomInfo(chat_room_struct)
if err != nil {
return
}
reply = getchatroom(db_chat_room)
return
}
func getchatroom(room db.ImChatRoom) *pb.ChatRoomInfoReply {
return &pb.ChatRoomInfoReply{
RoomId: int64(room.Id),
Creator: room.Creator,
Name: room.Name,
Announcement: room.Announcement,
Status: int64(room.Status),
Ext: room.Ext,
Createtime: room.Createtime,
Updatetime: room.Updatetime,
}
}
func (cr *ImChatRoomService) All(ctx context.Context, in *pb.ChatRoomAllRequest) (reply *pb.GetChatRoomsReply, err error) {
results, err := helper.GetChatRooms(in)
if err != nil {
return
}
reply = &pb.GetChatRoomsReply{Paginate: &pb.Page{}}
db_rooms := results["list"].([]db.ImChatRoom)
for _, v := range db_rooms {
reply.List = append(reply.List, getchatroom(v))
}
reply.Paginate.PageSize = int64(results["page_size"].(int))
reply.Paginate.PagetNo = results["page"].(int64)
reply.Paginate.TotalCount = results["total_count"].(int64)
reply.Paginate.TotalPage = results["total_page"].(int64)
return
}
......@@ -55,7 +55,7 @@ func (cs *ConfigureSevice) Select(ctx context.Context, in *pb.GetAllRequest) (re
for _, v := range configs {
reply.GetAll = append(reply.GetAll, &pb.GetAllOneReply{
Reply:&pb.Public{
Reply: &pb.Public{
CompanyUserId: v.CompanyUserId,
MultideviceType: v.MultideviceType,
MsgHookUrl: v.MsgHookUrl,
......@@ -66,7 +66,6 @@ func (cs *ConfigureSevice) Select(ctx context.Context, in *pb.GetAllRequest) (re
return
}
func (cs *ConfigureSevice) Update(ctx context.Context, in *pb.UpdateRequest) (reply *pb.ConfigureReply, err error) {
configure_add_struct := vs.NewConfigureUpdateStruct(in)
......@@ -80,4 +79,3 @@ func (cs *ConfigureSevice) Update(ctx context.Context, in *pb.UpdateRequest) (re
reply = &pb.ConfigureReply{}
return
}
\ No newline at end of file
......@@ -8,3 +8,10 @@ message Common {
string Curtime = 3;
string Checksum = 4;
}
message Page {
int64 PagetNo = 1;
int64 PageSize = 2;
int64 TotalPage = 3;
int64 TotalCount = 4;
}
\ No newline at end of file
......@@ -42,5 +42,5 @@ service ConfigureSevice{
rpc Select(GetAllRequest) returns(GetAllReply) {}
rpc Add (ConfigureRequest) returns(ConfigureReply) {}
rpc Delete(ConfigureDelRequest) returns(ConfigureReply) {}
rpc Update(UpdateRequest) returns(ConfigureReply) {}
rpc Update(UpdateRequest) returns(GetAllReply) {}
}
syntax = "proto3";
package pb;
import "u-proto/common.proto";
// 添加聊天室
message ChatRoomAddRequest {
Common Common = 1;
string Creator = 2;
string Name = 3;
string Announcement = 4;
}
message ChatRoomAddReply{
int64 Id = 1;
}
// 更新聊天室
message ChatRoomUpdateRequest {
Common Common = 1;
int64 RoomId = 2;
string Name = 3;
int64 Status = 4;
string Announcement = 5;
}
message ChatRoomUpdateReply {}
// 删除聊天室
message ChatRoomDelRequest {
Common Common = 1;
int64 RoomId = 2;
}
message ChatRoomDelReply {}
// 获取单个聊天室信息
message ChatRoomInfoRequest {
Common Common = 1;
int64 RoomId = 2;
}
message ChatRoomInfoReply {
int64 Room_id = 1;
string Creator = 2;
string Name = 3;
string Announcement = 4;
int64 Status = 5;
string Ext = 6;
string Createtime = 7;
string Updatetime = 8;
}
// 获取所有房间
message ChatRoomAllRequest {
Common Common = 1;
int64 Page = 2;
string Creator = 3;
string Name = 4;
string Announcement = 5;
int64 Status = 6;
string Createtime = 7;
string Updatetime = 8;
}
message GetChatRoomsReply {
repeated ChatRoomInfoReply List = 1;
Page Paginate = 2;
}
service ChatRoomService {
rpc Add(ChatRoomAddRequest) returns(ChatRoomAddReply) {}
rpc Update(ChatRoomUpdateRequest) returns(ChatRoomUpdateReply) {}
rpc Delete(ChatRoomDelRequest) returns(ChatRoomDelReply) {}
rpc Info(ChatRoomInfoRequest) returns (ChatRoomInfoReply) {}
rpc All(ChatRoomAllRequest) returns (GetChatRoomsReply) {}
}
\ No newline at end of file
......@@ -2,38 +2,102 @@ package validator_struct
import "im-microservice/pb"
// 添加配置的参数检测
type ConfigureAddStruct struct {
CompanyUserId int64 `validate:"required,numeric"`
MultideviceType int64 `validate:"required,numeric"`
MsgHookUrl string `validate:"required"`
}
func NewConfigureAddStruct(in *pb.ConfigureRequest) *ConfigureAddStruct {
return &ConfigureAddStruct{
CompanyUserId: in.Public.GetCompanyUserId(),
MultideviceType: in.Public.GetMultideviceType(),
MsgHookUrl: in.Public.GetMsgHookUrl(),
}
}
// 修改配置
type ConfigureUpdateStruct struct {
CompanyUserId int64 `validate:"required,numeric"`
MultideviceType int64
MsgHookUrl string
}
type ConfigureDelStruct struct {
CompanyUserId int64 `validate:"required,numeric"`
}
func NewConfigureAddStruct(in *pb.ConfigureRequest) *ConfigureAddStruct {
return &ConfigureAddStruct{
func NewConfigureUpdateStruct(in *pb.UpdateRequest) *ConfigureUpdateStruct {
return &ConfigureUpdateStruct{
CompanyUserId: in.Public.GetCompanyUserId(),
MultideviceType: in.Public.GetMultideviceType(),
MsgHookUrl: in.Public.GetMsgHookUrl(),
}
}
// 删除配置
type ConfigureDelStruct struct {
CompanyUserId int64 `validate:"required,numeric"`
}
func NewConfigureDelStruct(in *pb.ConfigureDelRequest) *ConfigureDelStruct {
return &ConfigureDelStruct{CompanyUserId: in.GetCompanyUserId()}
}
func NewConfigureUpdateStruct(in *pb.UpdateRequest) *ConfigureUpdateStruct {
return &ConfigureUpdateStruct{
CompanyUserId: in.Public.GetCompanyUserId(),
MultideviceType: in.Public.GetMultideviceType(),
MsgHookUrl: in.Public.GetMsgHookUrl(),
// 创建聊天室
type ChatRoomAddStruct struct {
Creator string `validate:"required"`
Name string `validate:"required"`
Announcement string `validate:"required"`
}
func NewAddChatRoom(in *pb.ChatRoomAddRequest) *ChatRoomAddStruct {
return &ChatRoomAddStruct{
Creator: in.GetCreator(),
Name: in.GetName(),
Announcement: in.GetAnnouncement(),
}
}
// 修改聊天室
type ChatRoomUpdate struct {
RoomId int64 `validate:"required"`
Name string
Announcement string
Status int64
}
func NewChatRoomUpdate(in *pb.ChatRoomUpdateRequest) *ChatRoomUpdate {
return &ChatRoomUpdate{
RoomId: in.GetRoomId(),
Name: in.GetName(),
Announcement: in.GetAnnouncement(),
Status: in.GetStatus(),
}
}
// 删除聊天室
type ChatRoomDel struct {
RoomId int64 `validate:"required"`
}
func NewChatRoomDel(in *pb.ChatRoomDelRequest) *ChatRoomDel {
return &ChatRoomDel{RoomId: in.GetRoomId()}
}
// 获取单个聊天室
type ChatRoomInfo struct {
RoomId int64 `validate:"required"`
Creator string
Name string
Announcement string
Status int64
Ext string
Createtime string
Updatetime string
}
func NewChatRoomInfo(in *pb.ChatRoomInfoRequest) *ChatRoomInfo {
return &ChatRoomInfo{RoomId: in.GetRoomId()}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment