role

package
v0.0.0-...-20be885 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxCountUnlimited = -1
	RankLowest        = 2147483647
)
View Source
var (
	FieldsAll = []string{
		"id",
		"name",
		"rank",
		"max_count",
	}

	FieldsAllExceptId = []string{
		"name",
		"rank",
		"max_count",
	}

	FieldsMaxCount = []string{
		"max_count",
	}

	FieldsPatchable = []string{
		"name",
		"rank",
		"max_count",
	}
)

Functions

This section is empty.

Types

type Controller

type Controller struct {
	ConfigService     *config.Service
	LocalErrorService *localerror.Service
	RoleService       *Service
}

func NewController

func NewController(cfg *config.Service, les *localerror.Service, svc *Service) *Controller

func (*Controller) Delete

func (c *Controller) Delete(w http.ResponseWriter, r *http.Request)

Delete Roles : HTTP endpoint to delete roles @Tags Roles @Description Delete a role @Produce json @Param id path string true "Role ID" @Success 200 {object} DeleteResponseDto "Success Response" @Failure 400 "BadRequest" @Failure 500 "InternalServerError" @Router /roles/{id} [DELETE]

func (*Controller) Get

func (c *Controller) Get(w http.ResponseWriter, r *http.Request)

Get Roles : HTTP endpoint to get a role @Tags Roles @Description Get a role @Produce json @Param id path string true "Role ID" @Success 200 {object} GetResponseDto "Success Response" @Failure 400 "BadRequest" @Failure 500 "InternalServerError" @Router /roles/{id} [GET]

func (*Controller) Patch

func (c *Controller) Patch(w http.ResponseWriter, r *http.Request)

Patch Roles : HTTP endpoint to patch a role @Tags Roles @Description Patch a role @Accept json @Produce json @Param id path string true "Role ID" @Param data body PatchRequestDto true "Role Patch Request" @Success 200 {object} PatchResponseDto "Success Response" @Failure 400 "BadRequest" @Failure 500 "InternalServerError" @Router /roles/{id} [PATCH]

func (*Controller) Post

func (c *Controller) Post(w http.ResponseWriter, r *http.Request)

Post Roles : HTTP endpoint to post new roles @Tags Roles @Description Post a new role @Accept json @Produce json @Param data body PostRequestDto true "Role Request" @Success 200 {object} PostResponseDto "Success Response" @Failure 400 "BadRequest" @Failure 500 "InternalServerError" @Router /roles [POST]

type DeleteResponseDto

type DeleteResponseDto = dtorespwithoutdata.Class

type Entity

type Entity struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Rank     int    `json:"rank"`
	MaxCount int    `json:"max_count"`
}

type GetResponseDto

type GetResponseDto = dtorespwithdata.Class[Entity]

type PatchRequestDto

type PatchRequestDto struct {
	Fields map[string]interface{} `json:"fields"`
}

type PatchResponseDto

type PatchResponseDto = dtorespwithoutdata.Class

type PostRequestDto

type PostRequestDto struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Rank     int    `json:"rank"`
	MaxCount int    `json:"max_count"`
}

type PostResponseDto

type PostResponseDto = dtorespwithdata.Class[Entity]

type Query

type Query interface {
	SelectById(fields []string, id string) *gorm.DB
}

func NewQuery

func NewQuery(db *gorm.DB, tableName string) Query

type QueryImpl

type QueryImpl struct {
	Db        *gorm.DB
	TableName string
}

func (*QueryImpl) SelectById

func (q *QueryImpl) SelectById(fields []string, id string) *gorm.DB

type Repository

type Repository interface {
	Create(req *Entity) (*Entity, error)
	FindById(id string) (*Entity, error)
	UpdateById(fields map[string]interface{}, ehid string) error
	DeleteById(id string) error
	CountById(id string) int64
}

func NewRepository

func NewRepository(cfg *config.Service) Repository

type RepositoryImpl

type RepositoryImpl struct {
	ConfigService *config.Service
	TableName     string
	Query         Query
}

func (*RepositoryImpl) CountById

func (r *RepositoryImpl) CountById(id string) int64

func (*RepositoryImpl) Create

func (r *RepositoryImpl) Create(req *Entity) (*Entity, error)

func (*RepositoryImpl) DeleteById

func (r *RepositoryImpl) DeleteById(id string) error

func (*RepositoryImpl) FindById

func (r *RepositoryImpl) FindById(id string) (*Entity, error)

func (*RepositoryImpl) UpdateById

func (r *RepositoryImpl) UpdateById(
	fields map[string]interface{},
	id string,
) error

type Service

type Service struct {
	ConfigService  *config.Service
	RoleRepository Repository
}

func NewService

func NewService(
	cfg *config.Service,
	r Repository,
) *Service

func (*Service) Create

func (s *Service) Create(req PostRequestDto) (*Entity, error)

func (*Service) DeleteById

func (s *Service) DeleteById(id string) error

func (*Service) RetrieveById

func (s *Service) RetrieveById(id string) (*Entity, error)

func (*Service) UpdateById

func (s *Service) UpdateById(fields map[string]interface{}, id string) error

Jump to

Keyboard shortcuts

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