Documentation
¶
Index ¶
- Constants
- Variables
- type AuthGoogleRequest
- type Comment
- type CommentPathParam
- type CommentService
- type Config
- type CreateCommentRequest
- type CreateTokenRequest
- type CreateUserRequest
- type EditCommentRequest
- type Error
- type GetCommentPathParam
- type RefreshTokenRequest
- type Token
- type TokenService
- type User
- type UserComment
- type UserService
Constants ¶
const ( ErrInvalid = "invalid" ErrNotFound = "not_found" ErrConflict = "conflict" )
const (
ProviderGoogle = "google"
)
Variables ¶
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
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 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