talkie

package module
v0.0.0-...-3ea9707 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 5 Imported by: 0

README

talkie

Self-hosted comment system for static websites

Documentation

Index

Constants

View Source
const (
	ErrInvalid      = "invalid"
	ErrUnauthorized = "unauthorized"
	ErrNotFound     = "not_found"
	ErrConflict     = "conflict"
)
View Source
const (
	ProviderGoogle = "google"
)

Variables

View Source
var (
	ErrUserNotFound    = errors.New("user not found")
	ErrCommentNotFound = errors.New("comment not found")
)

Functions

This section is empty.

Types

type AuthGoogleRequest

type AuthGoogleRequest struct {
	Credential string `json:"credential"`
}

AuthGoogleRequest represents a request body when creating new comment

type Comment

type Comment struct {
	ID        int       `json:"id" db:"id"`
	PostSlug  string    `json:"post_slug" db:"post_slug"`
	UserID    int       `json:"user_id" db:"user_id"`
	Content   string    `json:"content" db:"content"`
	ParentID  *int      `json:"parent_id,omitempty" db:"parent_id"`
	Comments  []Comment `pg:",array" json:"comments,omitempty" db:"comments"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at,omitempty" db:"updated_at"`
	DeletedAt time.Time `json:"deleted_at,omitempty" db:"deleted_at"`

	UserComment `db:"user_account"`
}

Comment represents a post comment

type CommentPathParam

type CommentPathParam struct {
	ID int `json:"id" uri:"id"`
}

CommentPathParam represents path parameters when editing a comment

type CommentService

type CommentService interface {
	Create(ctx context.Context, comment *CreateCommentRequest) error
	GetByPostSlug(ctx context.Context, postSlug string) ([]*Comment, error)
	GetByID(ctx context.Context, id int) (*Comment, error)
	UpdateByID(ctx context.Context, id int, comment *Comment) error
	List(ctx context.Context) ([]*Comment, error)
}

CommentService is the interface that wraps the CRUD methods

type Config

type Config struct {
	Port string `envconfig:"PORT"`

	DBHost     string `envconfig:"DB_HOST"`
	DBPort     string `envconfig:"DB_PORT"`
	DBUser     string `envconfig:"DB_USER"`
	DBPassword string `envconfig:"DB_PASSWORD"`
	DBName     string `envconfig:"DB_NAME"`
}

Config represents the app config

type CreateCommentRequest

type CreateCommentRequest struct {
	PostSlug string `json:"post_slug"`
	UserID   int    `json:"user_id"`
	Content  string `json:"content"`
	ParentID *int   `json:"parent_id,omitempty"`
}

CreateCommentRequest represents a request body when creating new comment

type CreateTokenRequest

type CreateTokenRequest struct {
	UserID       int    `json:"user_id"`
	RefreshToken string `json:"refresh_token"`
}

CreateTokenRequest represents a request body when creating new token

type CreateUserRequest

type CreateUserRequest struct {
	Name           string `json:"name"`
	Email          string `json:"email"`
	ProfilePicture string `json:"profile_picture"`
	Provider       string `json:"provider"`
	ProviderID     string `json:"provider_id"`
}

CreateUserRequest represents a request body when creating new user

type EditCommentRequest

type EditCommentRequest struct {
	Content string `json:"content"`
}

EditCommentRequest represents a request body when editing a comment

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message,omitempty"`
	Err     error  `json:"err,omitempty"`
}

Error represents an app error This can be used to distinguish between client and server error

func (*Error) Error

func (e *Error) Error() string

type GetCommentPathParam

type GetCommentPathParam struct {
	PostSlug string `json:"post_slug" uri:"post_slug"`
}

GetCommentPathParam represents path parameters when getting comments of a post

type RefreshTokenRequest

type RefreshTokenRequest struct {
	PostSlug     string `json:"post_slug"`
	UserID       string `json:"user_id"`
	Content      string `json:"content"`
	ParentID     *int   `json:"parent_id,omitempty"`
	RefreshToken string `json:"refresh_token"`
}

RefreshTokenRequest represents a request body when rotating tokens

type Token

type Token struct {
	ID           int       `json:"id" db:"id"`
	UserID       int       `json:"user_id" db:"user_id"`
	RefreshToken string    `json:"refresh_token" db:"refresh_token"`
	CreatedAt    time.Time `json:"created_at" db:"created_at"`
}

Token represents a refresh token

type TokenService

type TokenService interface {
	Create(ctx context.Context, user *CreateUserRequest) (*User, error)
	GetByID(ctx context.Context, id int) (*User, error)
	GetByProviderID(ctx context.Context, provider, providerID string) (*User, error)
}

TokenService is the interface that wraps the CRUD methods

type User

type User struct {
	ID         int       `json:"id" db:"id"`
	Provider   string    `json:"provider" db:"provider"`
	ProviderID string    `json:"provider_id" db:"provider_id"`
	CreatedAt  time.Time `json:"created_at" db:"created_at"`

	UserComment
}

User represents a social user

type UserComment

type UserComment struct {
	Email          string `json:"email" db:"email"`
	Name           string `json:"name" db:"name"`
	ProfilePicture string `json:"profile_picture" db:"profile_picture"`
}

type UserService

type UserService interface {
	Create(ctx context.Context, user *CreateUserRequest) (*User, error)
	GetByID(ctx context.Context, id int) (*User, error)
	GetByProviderID(ctx context.Context, provider, providerID string) (*User, error)
}

UserService is the interface that wraps the CRUD methods

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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