model

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RoleAuthor mapping id of role author
	RoleAuthor int = 2

	// RoleGuest mapping id of role guest
	RoleGuest int = 3

	//OauthStateKey consists template key of oauth state for redis
	OauthStateKey string = "oauth_state"
)

Variables

View Source
var (
	// KeyJWTValidAccess is context key identifier for valid jwt token
	KeyJWTValidAccess = "ValidJWTAccess"

	// IsAllowedEmailInput is regex validator to allowing only valid email
	IsAllowedEmailInput *regexp.Regexp
)
View Source
var (
	// ErrTokenNotFound occurs when jwt token not found
	ErrTokenNotFound = errors.New("token not found")
	// ErrSignedToken occurs when failed sign a jwt token
	ErrSignedToken = errors.New("failed sign a token %v")
	// ErrInvalidToken occurs when jwt token is invalid
	ErrInvalidToken = errors.New("invalid jwt token")
	// ErrTokenExpire occurs when jwt token already expired
	ErrTokenExpire = errors.New("token already expired, please to relogin application")

	// ErrTypeAssertion occurs when doing invalid type assertion
	ErrTypeAssertion = errors.New("type assertion error")

	// ErrFailedParseBody occurs when failed parsing body
	ErrFailedParseBody = errors.New("parse body error")
	// ErrInvalidRequets occurs when client sent invalid request body
	ErrInvalidRequest = errors.New("invalid request body")

	// ErrEmailExisted occurs when email already used inside database
	ErrEmailExisted = errors.New("email is existed")
	// ErrTagNameExisted occurs when tag name already created inside database
	ErrTagNameExisted = errors.New("tag is existed")

	// ErrUserNotFound occurs when user is not found in databases
	ErrUserNotFound = errors.New("users is not found")
	// ErrTagNotFound occurs when tag is not found in database
	ErrTagNotFound = errors.New("tag is not found")
	// ErrBlogNotFound occurs when blog is not found in database
	ErrBlogNotFound = errors.New("blog is not found")
	// ErrCommentNotFound occurs when comment is not found in database
	ErrCommentNotFound = errors.New("comment is not found")
	// ErrLikeNotFound occurs when like is not found in database
	ErrLikeNotFound = errors.New("like is not found")

	// ErrInvalidPassword occurs when password user inputed is invalid
	ErrInvalidPassword = errors.New("invalid password")
	// ErrMismatchLogin occurs when user trying mismatch login method
	ErrMismatchLogin = errors.New("mismatch login, please use endpoint /api/v1/auth/google/login")
	// ErrAlreadyLikeBlog occurs when user trying to liking a blog more than 1 times
	ErrAlreadyLikeBlog = errors.New("already liking this blog")

	// ErrRedisKeyNotExisted occurs when key provided is not existed
	ErrRedisKeyNotExisted = errors.New("keys not existed")
	// ErrInvalidExchange occurs when client sent invalid state & code
	ErrInvalidExchange = errors.New("invalid exchange")

	// ErrRoleNotExisted occurs when role provided is not existed
	ErrRoleNotExisted = errors.New("role not existed")

	// ErrForbidenAccess occurs when user trying to access forbidden resource
	ErrForbiddenAccess = errors.New("forbidden access")

	// ErrForbiddenDeleteSelf occurs when user trying deleting their account by self
	ErrForbiddenDeleteSelf = errors.New("forbidden delete account self, make sure the id is corrent")
	// ErrForbiddenUpdate occurs when user trying updating forbidden resource
	ErrForbiddenUpdate = errors.New("forbidden updating data")
	// ErrForbiddenDelete occurs when user trying deleting forbidden resource
	ErrForbiddenDelete = errors.New("forbidden deleteing data")
)

Functions

func GetValidRoleByID

func GetValidRoleByID(roleID int) (string, error)

GetValidRoleByID will return valid role by its id

Types

type AuthUserDetails

type AuthUserDetails struct {
	UserID   int    `db:"user_id" json:"-"`
	FullName string `db:"full_name" json:"full_name"`
	Email    string `db:"email" json:"email"`
	RoleID   int    `db:"id" json:"role_id"`
	RoleName string `db:"name" json:"role_name"`
	Password string `db:"password" json:"-"`
}

AuthDetails consist data authorized users

type BlogResponse

type BlogResponse struct {
	ID        int       `db:"id" json:"id"`
	Title     string    `db:"title" json:"title"`
	Slug      string    `db:"slug" json:"slug"`
	Body      string    `db:"body" json:"body"`
	Footer    string    `db:"footer" json:"footer"`
	UserID    int       `db:"user_id" json:"user_id"`
	Comments  []int     `db:"comments" json:"comments"`
	Tags      []int     `db:"tags" json:"tags"`
	Likes     []int     `db:"likes" json:"likes"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
	CreatedBy string    `db:"created_by" json:"created_by"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at,omitempty"`
	UpdatedBy *string   `db:"updated_by" json:"updated_by,omitempty"`
}

type CommentRequest

type CommentRequest struct {
	Comment string `json:"comment"`
	UserID  int    `json:"user_id"`
}

CommentRequest consist data for requesting create/update comment

type CreateBlogRequest

type CreateBlogRequest struct {
	Title  string `json:"title"`
	Slug   string `json:"-"`
	Body   string `json:"body"`
	Footer string `json:"footer"`
	UserID int    `json:"user_id"`
	Tags   []int  `json:"tags"`
}

CreateBlogRequest consist data for creating a blog

type CreateTagRequest

type CreateTagRequest struct {
	Name string `json:"name"`
}

CreateTagRequest consist data of creating a tag

type CreateUserRequest

type CreateUserRequest struct {
	FullName string `json:"full_name"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

CreateUserRequest consist data for creating a user

type FilterBlogRequest

type FilterBlogRequest struct {
	StartDate string `query:"start_date"`
	EndDate   string `query:"end_date"`
	Tags      []int  `query:"tags"`
}

FilterBlogRequest consitss data for filter request blog

type GoogleOauthResponse

type GoogleOauthResponse struct {
	ID            string `json:"id"`
	Email         string `json:"email"`
	VerifiedEmail bool   `json:"verified_email"`
	Name          string `json:"name,omitempty"`
	GivenName     string `json:"given_name,omitempty"`
	Picture       string `json:"picture,omitempty"`
	Locale        string `json:"locale"`
	Time          string `json:"time"`
}

GoogleOauthResponse consist data from response google services user info

type LikeRequest

type LikeRequest struct {
	Like   int `json:"like"`
	UserID int `json:"user_id"`
}

LikeRequest consist data for requesting create like

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

LoginRequest consist data for log-in a user

type Metadata

type Metadata struct {
	Page      int               `json:"page,omitempty"`
	Size      int               `json:"size,omitempty"`
	Order     string            `json:"order,omitempty"`
	TotalData int               `json:"total_data,omitempty"`
	TotalPage int               `json:"total_page,omitempty"`
	Links     map[string]string `json:"links,omitempty"`
}

Metadata consists data meta responses

type SuccessLoginResponse

type SuccessLoginResponse struct {
	AccessToken string    `json:"access_token"`
	ExpiredAt   time.Time `json:"expired_at"`
	Role        string    `json:"role"`
}

SuccessLoginResponse consist data of success login

type UpdateBlogRequest

type UpdateBlogRequest struct {
	Title  string `json:"title"`
	Slug   string `json:"-"`
	Body   string `json:"body"`
	Footer string `json:"footer"`
	UserID int    `json:"-"`
}

UpdateBlogRequest consist data for update a blog

type UpdateTagRequest

type UpdateTagRequest struct {
	Name string `json:"name"`
}

UpdateTagRequest consist data of updating a tag

type UpdateUserRequest

type UpdateUserRequest struct {
	FullName string `json:"full_name"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

UpdateUserRequest consist data of updating a user

type ViewBlogResponse

type ViewBlogResponse struct {
	ID        int             `db:"id" json:"id"`
	Title     string          `db:"title" json:"title"`
	Slug      string          `db:"slug" json:"slug"`
	Body      string          `db:"body" json:"body"`
	Footer    string          `db:"footer" json:"footer"`
	UserID    int             `db:"user_id" json:"user_id"`
	Comments  []sql.NullInt32 `db:"comments" json:"comments"`
	Tags      []sql.NullInt32 `db:"tags" json:"tags"`
	Likes     []sql.NullInt32 `db:"likes" json:"likes"`
	CreatedAt time.Time       `db:"created_at" json:"created_at"`
	CreatedBy string          `db:"created_by" json:"created_by"`
	UpdatedAt time.Time       `db:"updated_at" json:"updated_at,omitempty"`
	UpdatedBy *string         `db:"updated_by" json:"updated_by,omitempty"`
}

ViewBlogResponse consists data of blog responses

type ViewCommentResponse

type ViewCommentResponse struct {
	ID        int       `db:"id" json:"id"`
	Comment   string    `db:"comment" json:"comment"`
	BlogID    int       `db:"article_id" json:"blog_id"`
	UserID    int       `db:"user_id" json:"user_id"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
	CreatedBy string    `db:"created_by" json:"created_by"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at,omitempty"`
	UpdatedBy *string   `db:"updated_by" json:"updated_by,omitempty"`
}

ViewCommentResponse consist data of comments

type ViewLikeResponse

type ViewLikeResponse struct {
	ID     int `db:"id" json:"id"`
	Like   int `db:"like_count" json:"like"`
	UserID int `db:"user_id" json:"user_id"`
	BlogID int `db:"article_id" json:"blog_id"`
}

ViewLikeResponse consist data of like response

type ViewTagResponse

type ViewTagResponse struct {
	ID        int       `db:"id" json:"id,omitempty"`
	Name      string    `db:"name" json:"name,omitempty"`
	CreatedAt time.Time `db:"created_at" json:"created_at,omitempty"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at,omitempty"`
	CreatedBy string    `db:"created_by" json:"created_by,omitempty"`
	UpdatedBy *string   `db:"updated_by" json:"updated_by,omitempty"`
}

ViewTagResponse consist data of tag

type ViewUserResponse

type ViewUserResponse struct {
	ID        int       `db:"id" json:"id,omitempty"`
	FullName  string    `db:"full_name" json:"full_name,omitempty"`
	Email     string    `db:"email" json:"email,omitempty"`
	CreatedAt time.Time `db:"created_at" json:"created_at,omitempty"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at,omitempty"`
	CreatedBy string    `db:"created_by" json:"created_by,omitempty"`
	UpdatedBy *string   `db:"updated_by" json:"updated_by,omitempty"`
}

ViewUserResponse consist data of user

Jump to

Keyboard shortcuts

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