discussion

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_ARRAY_FIELD_NUM = 10

Variables

View Source
var (
	ErrInvalidID    = errors.New("invalid discussion ID")
	ErrInvalidType  = fmt.Errorf("discussion type is invalid, supported types are: %s", strings.Join(SupportedTypes, ","))
	ErrInvalidState = fmt.Errorf("discussion state is invalid, supported states are: %s", strings.Join(SupportedStates, ","))
)
View Source
var SupportedStates = []string{StateOpen.String(), StateClosed.String()}
View Source
var SupportedTypes = []string{TypeOpenEnded.String(), TypeIssues.String(), TypeQAndA.String()}

Functions

func IsStateStringValid

func IsStateStringValid(ss string) bool

IsStateStringValid returns true if state string is valid/supported

func IsTypeStringValid

func IsTypeStringValid(ts string) bool

IsTypeStringValid returns true if type string is valid/supported

Types

type Comment

type Comment struct {
	ID           string    `json:"id" db:"id"`
	DiscussionID string    `json:"discussion_id" db:"discussion_id"`
	Body         string    `json:"body" db:"body"`
	Owner        user.User `json:"owner" db:"owner"`
	UpdatedBy    user.User `json:"updated_by" db:"updated_by"`
	CreatedAt    time.Time `json:"created_at" db:"created_at"`
	UpdatedAt    time.Time `json:"updated_at" db:"updated_at"`
}

func (Comment) Validate

func (c Comment) Validate() error

Validate checks emptyness required fields and constraint in comment and return error if the required is empty

type Discussion

type Discussion struct {
	ID        string    `json:"id"`
	Title     string    `json:"title"`
	Body      string    `json:"body"`
	Type      Type      `json:"type"`
	State     State     `json:"state"`
	Labels    []string  `json:"labels"`
	Assets    []string  `json:"assets"`
	Assignees []string  `json:"assignees"`
	Owner     user.User `json:"owner"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (Discussion) IsEmpty

func (d Discussion) IsEmpty() bool

IsEmpty returns true if all fields inside discussion are considered empty

func (Discussion) Validate

func (d Discussion) Validate() error

Validate checks emptyness required fields and constraint in discussion and return error if the required is empty

func (Discussion) ValidateConstraint

func (d Discussion) ValidateConstraint() error

ValidateConstraint checks whether non empty/nil fields fulfill the contract

type Filter

type Filter struct {
	Type                  string `json:"type" validate:"omitempty,oneof=openended issues qanda all"`
	State                 string `json:"state" validate:"omitempty,oneof=open closed all"`
	Assets                []string
	Owner                 string
	Assignees             []string
	Labels                []string
	SortBy                string `json:"sort" validate:"omitempty,oneof=created_at updated_at"`
	SortDirection         string `json:"direction" validate:"omitempty,oneof=asc desc"`
	Size                  int    `json:"size" validate:"omitempty,gte=0"`
	Offset                int    `json:"offset" validate:"omitempty,gte=0"`
	DisjointAssigneeOwner bool
}

func (*Filter) AssignDefault

func (f *Filter) AssignDefault()

AssignDefault will populate default value to filter

func (*Filter) Validate

func (f *Filter) Validate() error

Validate will check whether fields in the filter fulfills the constraint

type InvalidError

type InvalidError struct {
	CommentID    string
	DiscussionID string
}

func (InvalidError) Error

func (e InvalidError) Error() string

type NotFoundError

type NotFoundError struct {
	CommentID    string
	DiscussionID string
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Repository

type Repository interface {
	GetAll(ctx context.Context, filter Filter) ([]Discussion, error)
	Create(ctx context.Context, discussion *Discussion) (string, error)
	Get(ctx context.Context, did string) (Discussion, error)
	Patch(ctx context.Context, discussion *Discussion) error
	GetAllComments(ctx context.Context, discussionID string, filter Filter) ([]Comment, error)
	CreateComment(ctx context.Context, cmt *Comment) (string, error)
	GetComment(ctx context.Context, commentID, discussionID string) (Comment, error)
	UpdateComment(ctx context.Context, cmt *Comment) error
	DeleteComment(ctx context.Context, commentID, discussionID string) error
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(discussionRepository Repository) *Service

func (*Service) CreateComment

func (s *Service) CreateComment(ctx context.Context, cmt *Comment) (string, error)

func (*Service) CreateDiscussion

func (s *Service) CreateDiscussion(ctx context.Context, dsc *Discussion) (string, error)

func (*Service) DeleteComment

func (s *Service) DeleteComment(ctx context.Context, commentID, discussionID string) error

func (*Service) GetComment

func (s *Service) GetComment(ctx context.Context, commentID, discussionID string) (Comment, error)

func (*Service) GetComments

func (s *Service) GetComments(ctx context.Context, discussionID string, filter Filter) ([]Comment, error)

func (*Service) GetDiscussion

func (s *Service) GetDiscussion(ctx context.Context, did string) (Discussion, error)

func (*Service) GetDiscussions

func (s *Service) GetDiscussions(ctx context.Context, filter Filter) ([]Discussion, error)

func (*Service) PatchDiscussion

func (s *Service) PatchDiscussion(ctx context.Context, dsc *Discussion) error

func (*Service) UpdateComment

func (s *Service) UpdateComment(ctx context.Context, cmt *Comment) error

type State

type State string
const (
	StateOpen   State = "open"
	StateClosed State = "closed"
)

func GetStateEnum

func GetStateEnum(ds string) State

GetStateEnum converts string to state enum

func (State) String

func (ds State) String() string

String returns state enum as string

type Type

type Type string
const (
	TypeOpenEnded Type = "openended"
	TypeIssues    Type = "issues"
	TypeQAndA     Type = "qanda"
)

func GetTypeEnum

func GetTypeEnum(dt string) Type

GetTypeEnum converts string to type enum

func (Type) String

func (dt Type) String() string

String returns type enum as string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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