فهرست منبع

Ticket

- refactoring
Alexey Kim 1 سال پیش
والد
کامیت
bfd799febd
3فایلهای تغییر یافته به همراه56 افزوده شده و 66 حذف شده
  1. 6 39
      v2/ticket.go
  2. 47 27
      v2/ticket.pb.go
  3. 3 0
      v2/ticket.proto

+ 6 - 39
v2/ticket.go

@@ -1,7 +1,6 @@
 package ticket
 
 import (
-	"encoding/json"
 	"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
 	"google.golang.org/protobuf/types/known/timestamppb"
 	"time"
@@ -9,12 +8,10 @@ import (
 
 func (x *Ticket) Scan(row driver.Rows) error {
 	var (
-		from       map[string]string
-		createdAt  time.Time
-		updatedAt  time.Time
-		messageIds []string
-		subjects   []string
-		err        error
+		from      map[string]string
+		createdAt time.Time
+		updatedAt time.Time
+		err       error
 	)
 
 	if err = row.Scan(
@@ -27,8 +24,8 @@ func (x *Ticket) Scan(row driver.Rows) error {
 		&x.Tags,
 		&createdAt,
 		&updatedAt,
-		&messageIds,
-		&subjects,
+		&x.MessageIds,
+		&x.Subjects,
 	); err != nil {
 		return err
 	}
@@ -41,35 +38,5 @@ func (x *Ticket) Scan(row driver.Rows) error {
 	x.CreatedAt = timestamppb.New(createdAt)
 	x.UpdatedAt = timestamppb.New(updatedAt)
 
-	if len(messageIds) > 0 {
-		if d, err := json.Marshal(messageIds); err == nil {
-			x.Meta["message_ids"] = string(d)
-		}
-	}
-
-	if len(subjects) > 0 {
-		if d, err := json.Marshal(subjects); err == nil {
-			x.Meta["subjects"] = string(d)
-		}
-	}
-
 	return nil
 }
-
-func (x *Ticket) MessageIds() []string {
-	var ids []string
-	if v, ok := x.Meta["message_ids"]; ok {
-		_ = json.Unmarshal([]byte(v), &ids)
-	}
-
-	return ids
-}
-
-func (x *Ticket) Subjects() []string {
-	var ids []string
-	if v, ok := x.Meta["subjects"]; ok {
-		_ = json.Unmarshal([]byte(v), &ids)
-	}
-
-	return ids
-}

+ 47 - 27
v2/ticket.pb.go

@@ -603,16 +603,18 @@ type Ticket struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	TicketId  string                 `protobuf:"bytes,1,opt,name=ticket_id,proto3" json:"ticket_id,omitempty"`
-	ThreadId  string                 `protobuf:"bytes,2,opt,name=thread_id,proto3" json:"thread_id,omitempty"`
-	To        string                 `protobuf:"bytes,3,opt,name=to,proto3" json:"to,omitempty"`
-	From      *EmailAddress          `protobuf:"bytes,4,opt,name=from,proto3" json:"from,omitempty"`
-	Flags     []byte                 `protobuf:"bytes,5,opt,name=flags,proto3" json:"flags,omitempty"`
-	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=created_at,proto3" json:"created_at,omitempty"`
-	UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=updated_at,proto3" json:"updated_at,omitempty"`
-	Messages  []*Message             `protobuf:"bytes,10,rep,name=messages,proto3" json:"messages,omitempty"`
-	Meta      map[string]string      `protobuf:"bytes,11,rep,name=meta,proto3" json:"meta,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
-	Tags      []string               `protobuf:"bytes,12,rep,name=tags,proto3" json:"tags,omitempty"`
+	TicketId   string                 `protobuf:"bytes,1,opt,name=ticket_id,proto3" json:"ticket_id,omitempty"`
+	ThreadId   string                 `protobuf:"bytes,2,opt,name=thread_id,proto3" json:"thread_id,omitempty"`
+	To         string                 `protobuf:"bytes,3,opt,name=to,proto3" json:"to,omitempty"`
+	From       *EmailAddress          `protobuf:"bytes,4,opt,name=from,proto3" json:"from,omitempty"`
+	Flags      []byte                 `protobuf:"bytes,5,opt,name=flags,proto3" json:"flags,omitempty"`
+	CreatedAt  *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=created_at,proto3" json:"created_at,omitempty"`
+	UpdatedAt  *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=updated_at,proto3" json:"updated_at,omitempty"`
+	Messages   []*Message             `protobuf:"bytes,10,rep,name=messages,proto3" json:"messages,omitempty"`
+	Meta       map[string]string      `protobuf:"bytes,11,rep,name=meta,proto3" json:"meta,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
+	Tags       []string               `protobuf:"bytes,12,rep,name=tags,proto3" json:"tags,omitempty"`
+	MessageIds []string               `protobuf:"bytes,100,rep,name=message_ids,proto3" json:"message_ids,omitempty"`
+	Subjects   []string               `protobuf:"bytes,101,rep,name=subjects,proto3" json:"subjects,omitempty"`
 }
 
 func (x *Ticket) Reset() {
@@ -717,6 +719,20 @@ func (x *Ticket) GetTags() []string {
 	return nil
 }
 
+func (x *Ticket) GetMessageIds() []string {
+	if x != nil {
+		return x.MessageIds
+	}
+	return nil
+}
+
+func (x *Ticket) GetSubjects() []string {
+	if x != nil {
+		return x.Subjects
+	}
+	return nil
+}
+
 var File_ticket_proto protoreflect.FileDescriptor
 
 var file_ticket_proto_rawDesc = []byte{
@@ -800,7 +816,7 @@ var file_ticket_proto_rawDesc = []byte{
 	0x08, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x45, 0x58, 0x54, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05,
 	0x45, 0x4d, 0x41, 0x49, 0x4c, 0x10, 0x02, 0x12, 0x16, 0x0a, 0x12, 0x41, 0x53, 0x53, 0x49, 0x53,
 	0x54, 0x41, 0x4e, 0x54, 0x5f, 0x43, 0x41, 0x4c, 0x4c, 0x42, 0x41, 0x43, 0x4b, 0x10, 0x03, 0x22,
-	0xb4, 0x03, 0x0a, 0x06, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69,
+	0xf2, 0x03, 0x0a, 0x06, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69,
 	0x63, 0x6b, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74,
 	0x69, 0x63, 0x6b, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x68, 0x72, 0x65,
 	0x61, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x68, 0x72,
@@ -823,22 +839,26 @@ var file_ticket_proto_rawDesc = []byte{
 	0x65, 0x74, 0x61, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x74, 0x69, 0x63, 0x6b,
 	0x65, 0x74, 0x2e, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x45, 0x6e,
 	0x74, 0x72, 0x79, 0x52, 0x04, 0x6d, 0x65, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67,
-	0x73, 0x18, 0x0c, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x1a, 0x37, 0x0a,
-	0x09, 0x4d, 0x65, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65,
-	0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05,
-	0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c,
-	0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x43, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
-	0x65, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x1c, 0x0a, 0x14, 0x75, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e,
-	0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x10, 0x00, 0x1a,
-	0x02, 0x08, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x45, 0x4e, 0x54, 0x10, 0x01, 0x12, 0x0c, 0x0a,
-	0x08, 0x4d, 0x4f, 0x44, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x02, 0x2a, 0x33, 0x0a, 0x0a, 0x54,
-	0x69, 0x63, 0x6b, 0x65, 0x74, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x1b, 0x0a, 0x13, 0x75, 0x6e, 0x6b,
-	0x6e, 0x6f, 0x77, 0x6e, 0x5f, 0x74, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x5f, 0x66, 0x6c, 0x61, 0x67,
-	0x10, 0x00, 0x1a, 0x02, 0x08, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x52, 0x45, 0x41, 0x44, 0x10, 0x01,
-	0x42, 0x2d, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x73, 0x68, 0x6f, 0x70, 0x70, 0x65, 0x72,
-	0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x74, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x42, 0x05,
-	0x70, 0x72, 0x6f, 0x74, 0x6f, 0x5a, 0x08, 0x2e, 0x2f, 0x74, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x62,
-	0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x73, 0x18, 0x0c, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x12, 0x20, 0x0a,
+	0x0b, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x64, 0x20, 0x03,
+	0x28, 0x09, 0x52, 0x0b, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x64, 0x73, 0x12,
+	0x1a, 0x0a, 0x08, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x18, 0x65, 0x20, 0x03, 0x28,
+	0x09, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x1a, 0x37, 0x0a, 0x09, 0x4d,
+	0x65, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
+	0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
+	0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
+	0x3a, 0x02, 0x38, 0x01, 0x2a, 0x43, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x46,
+	0x6c, 0x61, 0x67, 0x12, 0x1c, 0x0a, 0x14, 0x75, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x5f, 0x6d,
+	0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x10, 0x00, 0x1a, 0x02, 0x08,
+	0x01, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x45, 0x4e, 0x54, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x4d,
+	0x4f, 0x44, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x02, 0x2a, 0x33, 0x0a, 0x0a, 0x54, 0x69, 0x63,
+	0x6b, 0x65, 0x74, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x1b, 0x0a, 0x13, 0x75, 0x6e, 0x6b, 0x6e, 0x6f,
+	0x77, 0x6e, 0x5f, 0x74, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x10, 0x00,
+	0x1a, 0x02, 0x08, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x52, 0x45, 0x41, 0x44, 0x10, 0x01, 0x42, 0x2d,
+	0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x73, 0x68, 0x6f, 0x70, 0x70, 0x65, 0x72, 0x2e, 0x63,
+	0x72, 0x6d, 0x2e, 0x74, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x2e, 0x76, 0x32, 0x42, 0x05, 0x70, 0x72,
+	0x6f, 0x74, 0x6f, 0x5a, 0x08, 0x2e, 0x2f, 0x74, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x62, 0x06, 0x70,
+	0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (

+ 3 - 0
v2/ticket.proto

@@ -85,4 +85,7 @@ message Ticket {
   repeated Message messages = 10 [json_name = "messages"];
   map<string, string> meta = 11 [json_name = "meta"];
   repeated string tags = 12 [json_name = "tags"];
+
+  repeated string message_ids = 100 [json_name = "message_ids"];
+  repeated string subjects = 101 [json_name = "subjects"];
 }