Files
services/threads/handler/streams.go
Dominic Wong 8e38c8b834 multi tenant threads (#78)
* multitenant threads

* auth for v1
2021-03-25 17:33:20 +00:00

61 lines
1.6 KiB
Go

package handler
import (
"time"
"github.com/micro/micro/v3/service/errors"
gorm2 "github.com/micro/services/pkg/gorm"
pb "github.com/micro/services/threads/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
var (
ErrMissingID = errors.BadRequest("MISSING_ID", "Missing ID")
ErrMissingGroupID = errors.BadRequest("MISSING_GROUP_ID", "Missing GroupID")
ErrMissingTopic = errors.BadRequest("MISSING_TOPIC", "Missing Topic")
ErrMissingAuthorID = errors.BadRequest("MISSING_AUTHOR_ID", "Missing Author ID")
ErrMissingText = errors.BadRequest("MISSING_TEXT", "Missing text")
ErrMissingConversationID = errors.BadRequest("MISSING_CONVERSATION_ID", "Missing Conversation ID")
ErrMissingConversationIDs = errors.BadRequest("MISSING_CONVERSATION_IDS", "One or more Conversation IDs are required")
ErrNotFound = errors.NotFound("NOT_FOUND", "Conversation not found")
)
type Threads struct {
gorm2.Helper
Time func() time.Time
}
type Message struct {
ID string
AuthorID string
ConversationID string
Text string
SentAt time.Time
}
func (m *Message) Serialize() *pb.Message {
return &pb.Message{
Id: m.ID,
AuthorId: m.AuthorID,
ConversationId: m.ConversationID,
Text: m.Text,
SentAt: timestamppb.New(m.SentAt),
}
}
type Conversation struct {
ID string
GroupID string
Topic string
CreatedAt time.Time
}
func (c *Conversation) Serialize() *pb.Conversation {
return &pb.Conversation{
Id: c.ID,
GroupId: c.GroupID,
Topic: c.Topic,
CreatedAt: timestamppb.New(c.CreatedAt),
}
}