ticket

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ticket provides ticket domain models and business logic.

Index

Constants

View Source
const (
	PriorityLow      = "low"
	PriorityNormal   = "normal"
	PriorityHigh     = "high"
	PriorityUrgent   = "urgent"
	PriorityCritical = "critical"
)

Priority levels.

View Source
const (
	StatusOpen       = "open"
	StatusPending    = "pending"
	StatusInProgress = "in_progress"
	StatusResolved   = "resolved"
	StatusClosed     = "closed"
	StatusOnHold     = "on_hold"
	StatusCancelled  = "cancelled"
)

Status values.

View Source
const (
	ArticleTypeEmail = "email"
	ArticleTypeNote  = "note"
	ArticleTypePhone = "phone"
	ArticleTypeChat  = "chat"
	ArticleTypeWeb   = "web"
)

Article types.

View Source
const (
	ActionCreated         = "created"
	ActionUpdated         = "updated"
	ActionStatusChanged   = "status_changed"
	ActionPriorityChanged = "priority_changed"
	ActionAssigned        = "assigned"
	ActionCommented       = "commented"
	ActionAttached        = "attached"
	ActionMerged          = "merged"
	ActionSplit           = "split"
	ActionEscalated       = "escalated"
)

History actions.

Variables

This section is empty.

Functions

func RegisterTicketServiceServer

func RegisterTicketServiceServer(s interface{}, srv TicketServiceServer)

RegisterTicketServiceServer registers the service with gRPC server.

Types

type Article

type Article struct {
	ID          string                 `json:"id" db:"id"`
	TicketID    string                 `json:"ticket_id" db:"ticket_id"`
	Type        string                 `json:"type" db:"type"` // email, note, phone, chat
	From        string                 `json:"from" db:"from_address"`
	To          string                 `json:"to" db:"to_address"`
	Subject     string                 `json:"subject" db:"subject"`
	Body        string                 `json:"body" db:"body"`
	IsInternal  bool                   `json:"is_internal" db:"is_internal"`
	CreatedBy   string                 `json:"created_by" db:"created_by"`
	CreatedAt   time.Time              `json:"created_at" db:"created_at"`
	Attachments []Attachment           `json:"attachments,omitempty"`
	Metadata    map[string]interface{} `json:"metadata" db:"metadata"`
}

Article represents a ticket article/message.

type Attachment

type Attachment struct {
	ID          string    `json:"id" db:"id"`
	TicketID    string    `json:"ticket_id" db:"ticket_id"`
	ArticleID   *string   `json:"article_id,omitempty" db:"article_id"`
	FileName    string    `json:"file_name" db:"file_name"`
	ContentType string    `json:"content_type" db:"content_type"`
	Size        int64     `json:"size" db:"size"`
	StoragePath string    `json:"storage_path" db:"storage_path"`
	UploadedBy  string    `json:"uploaded_by" db:"uploaded_by"`
	UploadedAt  time.Time `json:"uploaded_at" db:"uploaded_at"`
	Checksum    string    `json:"checksum" db:"checksum"`
}

Attachment represents a file attachment.

type CacheService

type CacheService interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
	Delete(ctx context.Context, key string) error
	Invalidate(ctx context.Context, pattern string) error
}

CacheService defines the interface for caching.

type CreateTicketRequest

type CreateTicketRequest struct {
	Title        string            `json:"title"`
	Description  string            `json:"description"`
	Priority     string            `json:"priority"`
	QueueId      string            `json:"queue_id"`
	CustomerId   string            `json:"customer_id"`
	Tags         []string          `json:"tags"`
	CustomFields map[string]string `json:"custom_fields"`
}

type CreateTicketResponse

type CreateTicketResponse struct {
	Ticket *TicketProto `json:"ticket"`
}

type DeleteTicketRequest

type DeleteTicketRequest struct {
	Id string `json:"id"`
}

type DeleteTicketResponse

type DeleteTicketResponse struct {
	Success bool `json:"success"`
}

type Event

type Event struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`
	Timestamp time.Time              `json:"timestamp"`
	Data      map[string]interface{} `json:"data"`
	Source    string                 `json:"source"`
	Version   string                 `json:"version"`
}

Event represents a domain event.

type EventBus

type EventBus interface {
	Publish(ctx context.Context, event Event) error
	Subscribe(ctx context.Context, topic string, handler EventHandler) error
}

EventBus defines the interface for event publishing.

type EventHandler

type EventHandler func(ctx context.Context, event Event) error

EventHandler processes events.

type GetTicketRequest

type GetTicketRequest struct {
	Id string `json:"id"`
}

type GetTicketResponse

type GetTicketResponse struct {
	Ticket *TicketProto `json:"ticket"`
}

type HistoryItem

type HistoryItem struct {
	ID        string                 `json:"id" db:"id"`
	TicketID  string                 `json:"ticket_id" db:"ticket_id"`
	Action    string                 `json:"action" db:"action"`
	Field     string                 `json:"field" db:"field"`
	OldValue  *string                `json:"old_value,omitempty" db:"old_value"`
	NewValue  *string                `json:"new_value,omitempty" db:"new_value"`
	ChangedBy string                 `json:"changed_by" db:"changed_by"`
	ChangedAt time.Time              `json:"changed_at" db:"changed_at"`
	Comment   string                 `json:"comment,omitempty" db:"comment"`
	Metadata  map[string]interface{} `json:"metadata" db:"metadata"`
}

HistoryItem represents a ticket history entry.

type ListFilter

type ListFilter struct {
	Status      string    `json:"status,omitempty"`
	Priority    string    `json:"priority,omitempty"`
	QueueID     string    `json:"queue_id,omitempty"`
	AssignedTo  string    `json:"assigned_to,omitempty"`
	CustomerID  string    `json:"customer_id,omitempty"`
	Tags        []string  `json:"tags,omitempty"`
	CreatedFrom time.Time `json:"created_from,omitempty"`
	CreatedTo   time.Time `json:"created_to,omitempty"`
	UpdatedFrom time.Time `json:"updated_from,omitempty"`
	UpdatedTo   time.Time `json:"updated_to,omitempty"`
	SortBy      string    `json:"sort_by,omitempty"`
	SortOrder   string    `json:"sort_order,omitempty"`
	Limit       int       `json:"limit,omitempty"`
	Offset      int       `json:"offset,omitempty"`
}

ListFilter represents ticket list filtering options.

func (*ListFilter) Hash

func (f *ListFilter) Hash() string

Hash generates a hash of the filter for caching.

type ListTicketsRequest

type ListTicketsRequest struct {
	Status     string `json:"status"`
	Priority   string `json:"priority"`
	QueueId    string `json:"queue_id"`
	AssignedTo string `json:"assigned_to"`
	CustomerId string `json:"customer_id"`
	Limit      int32  `json:"limit"`
	Offset     int32  `json:"offset"`
}

type ListTicketsResponse

type ListTicketsResponse struct {
	Tickets []*TicketProto `json:"tickets"`
	Total   int32          `json:"total"`
}

type MetricsCollector

type MetricsCollector interface {
	IncrementCounter(name string, labels map[string]string)
	RecordDuration(name string, duration time.Duration, labels map[string]string)
	SetGauge(name string, value float64, labels map[string]string)
}

MetricsCollector defines the interface for metrics collection.

type SearchTicketsRequest

type SearchTicketsRequest struct {
	Query string `json:"query"`
	Limit int32  `json:"limit"`
}

type SearchTicketsResponse

type SearchTicketsResponse struct {
	Tickets []*TicketProto `json:"tickets"`
	Total   int32          `json:"total"`
}

type Ticket

type Ticket struct {
	ID              string                 `json:"id" db:"id"`
	Number          string                 `json:"number" db:"number"`
	Title           string                 `json:"title" db:"title"`
	Description     string                 `json:"description" db:"description"`
	Priority        string                 `json:"priority" db:"priority"`
	Status          string                 `json:"status" db:"status"`
	QueueID         string                 `json:"queue_id" db:"queue_id"`
	CustomerID      string                 `json:"customer_id" db:"customer_id"`
	AssignedTo      *string                `json:"assigned_to,omitempty" db:"assigned_to"`
	Tags            []string               `json:"tags" db:"tags"`
	CustomFields    map[string]interface{} `json:"custom_fields" db:"custom_fields"`
	CreatedAt       time.Time              `json:"created_at" db:"created_at"`
	UpdatedAt       time.Time              `json:"updated_at" db:"updated_at"`
	ResolvedAt      *time.Time             `json:"resolved_at,omitempty" db:"resolved_at"`
	ClosedAt        *time.Time             `json:"closed_at,omitempty" db:"closed_at"`
	DueAt           *time.Time             `json:"due_at,omitempty" db:"due_at"`
	FirstResponseAt *time.Time             `json:"first_response_at,omitempty" db:"first_response_at"`

	// Relationships
	Articles    []Article     `json:"articles,omitempty"`
	Attachments []Attachment  `json:"attachments,omitempty"`
	History     []HistoryItem `json:"history,omitempty"`
}

Ticket represents a support ticket.

func (*Ticket) Clone

func (t *Ticket) Clone() *Ticket

Clone creates a deep copy of the ticket.

func (*Ticket) ToProto

func (t *Ticket) ToProto() *TicketProto

ToProto converts the ticket to protobuf format.

type TicketProto

type TicketProto struct {
	Id              string   `json:"id"`
	Number          string   `json:"number"`
	Title           string   `json:"title"`
	Description     string   `json:"description"`
	Priority        string   `json:"priority"`
	Status          string   `json:"status"`
	QueueId         string   `json:"queue_id"`
	CustomerId      string   `json:"customer_id"`
	AssignedTo      string   `json:"assigned_to"`
	Tags            []string `json:"tags"`
	CreatedAt       int64    `json:"created_at"`
	UpdatedAt       int64    `json:"updated_at"`
	ResolvedAt      int64    `json:"resolved_at"`
	ClosedAt        int64    `json:"closed_at"`
	DueAt           int64    `json:"due_at"`
	FirstResponseAt int64    `json:"first_response_at"`
}

TicketProto represents a ticket in protobuf format.

type TicketRepository

type TicketRepository interface {
	Create(ctx context.Context, ticket *Ticket) error
	GetByID(ctx context.Context, id string) (*Ticket, error)
	Update(ctx context.Context, ticket *Ticket) error
	Delete(ctx context.Context, id string) error
	List(ctx context.Context, filter *ListFilter) ([]*Ticket, error)
	Search(ctx context.Context, query string) ([]*Ticket, error)
}

TicketRepository defines the interface for ticket data access.

type TicketService

type TicketService struct {
	UnimplementedTicketServiceServer
	// contains filtered or unexported fields
}

TicketService handles all ticket-related operations as a microservice.

func NewTicketService

func NewTicketService(repo TicketRepository, cache CacheService, events EventBus, metrics MetricsCollector) *TicketService

NewTicketService creates a new ticket service instance.

func (*TicketService) CreateTicket

CreateTicket creates a new ticket.

func (*TicketService) GetTicket

GetTicket retrieves a ticket by ID.

func (*TicketService) ListTickets

ListTickets lists tickets with filtering.

func (*TicketService) SearchTickets

SearchTickets searches tickets.

func (*TicketService) Start

func (s *TicketService) Start(port int) error

Start starts the gRPC server.

func (*TicketService) UpdateTicket

UpdateTicket updates an existing ticket.

type UnimplementedTicketServiceServer

type UnimplementedTicketServiceServer struct{}

UnimplementedTicketServiceServer can be embedded to have forward compatible implementations.

func (UnimplementedTicketServiceServer) CreateTicket

func (UnimplementedTicketServiceServer) DeleteTicket

func (UnimplementedTicketServiceServer) GetTicket

func (UnimplementedTicketServiceServer) ListTickets

func (UnimplementedTicketServiceServer) SearchTickets

func (UnimplementedTicketServiceServer) UpdateTicket

type UpdateTicketRequest

type UpdateTicketRequest struct {
	Id          string   `json:"id"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Priority    string   `json:"priority"`
	Status      string   `json:"status"`
	AssignedTo  string   `json:"assigned_to"`
	Tags        []string `json:"tags"`
}

type UpdateTicketResponse

type UpdateTicketResponse struct {
	Ticket *TicketProto `json:"ticket"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL