Documentation ¶
Index ¶
- Constants
- Variables
- func IsStateStringValid(ss string) bool
- func IsTypeStringValid(ts string) bool
- type Comment
- type Discussion
- type Filter
- type InvalidError
- type NotFoundError
- type Repository
- type Service
- func (s *Service) CreateComment(ctx context.Context, cmt *Comment) (string, error)
- func (s *Service) CreateDiscussion(ctx context.Context, dsc *Discussion) (string, error)
- func (s *Service) DeleteComment(ctx context.Context, commentID, discussionID string) error
- func (s *Service) GetComment(ctx context.Context, commentID, discussionID string) (Comment, error)
- func (s *Service) GetComments(ctx context.Context, discussionID string, filter Filter) ([]Comment, error)
- func (s *Service) GetDiscussion(ctx context.Context, did string) (Discussion, error)
- func (s *Service) GetDiscussions(ctx context.Context, filter Filter) ([]Discussion, error)
- func (s *Service) PatchDiscussion(ctx context.Context, dsc *Discussion) error
- func (s *Service) UpdateComment(ctx context.Context, cmt *Comment) error
- type State
- type Type
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 ¶
IsStateStringValid returns true if state string is valid/supported
func IsTypeStringValid ¶
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"` }
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
type InvalidError ¶
func (InvalidError) Error ¶
func (e InvalidError) Error() string
type NotFoundError ¶
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 (*Service) CreateDiscussion ¶
func (*Service) DeleteComment ¶
func (*Service) GetComment ¶
func (*Service) GetComments ¶
func (*Service) GetDiscussion ¶
func (*Service) GetDiscussions ¶
func (*Service) PatchDiscussion ¶
func (s *Service) PatchDiscussion(ctx context.Context, dsc *Discussion) error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.