Skip to content

Commit

Permalink
🔇 silent changes: changed access modifier for entity model #9
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Oct 1, 2023
1 parent e6e15bb commit 0e9c278
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
98 changes: 49 additions & 49 deletions entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,182 +9,182 @@ import (
"github.com/sivaosorg/govm/utils"
)

func NewResponseEntity() *ResponseEntity {
r := &ResponseEntity{}
func NewResponseEntity() *responseEntity {
r := &responseEntity{}
r.SetHeaders(make(map[string]interface{}))
r.SetMeta(*NewMetaEntity())
return r
}

func NewPaginationEntity() *PaginationEntity {
p := &PaginationEntity{}
func NewPaginationEntity() *paginationEntity {
p := &paginationEntity{}
p.SetIsLast(false)
return p
}

func NewMetaEntity() *MetaEntity {
m := &MetaEntity{}
func NewMetaEntity() *metaEntity {
m := &metaEntity{}
m.SetCustomFields(make(map[string]interface{}))
m.SetRequestedTime(time.Now())
m.SetApiVersion("v1.0.0")
return m
}

func (m *MetaEntity) SetApiVersion(value string) *MetaEntity {
func (m *metaEntity) SetApiVersion(value string) *metaEntity {
m.ApiVersion = utils.TrimSpaces(value)
return m
}

func (m *MetaEntity) SetRequestId(value string) *MetaEntity {
func (m *metaEntity) SetRequestId(value string) *metaEntity {
m.RequestId = value
return m
}

func (m *MetaEntity) SetRequestedTime(value time.Time) *MetaEntity {
func (m *metaEntity) SetRequestedTime(value time.Time) *metaEntity {
m.RequestedTime = value
return m
}

func (m *MetaEntity) SetCustomFields(value map[string]interface{}) *MetaEntity {
func (m *metaEntity) SetCustomFields(value map[string]interface{}) *metaEntity {
m.CustomFields = value
return m
}

func (m *MetaEntity) AppendCustomField(value string, key interface{}) *MetaEntity {
func (m *metaEntity) AppendCustomField(value string, key interface{}) *metaEntity {
m.CustomFields[value] = key
return m
}

func (m *MetaEntity) AppendCustomFields(value string, keys ...interface{}) *MetaEntity {
func (m *metaEntity) AppendCustomFields(value string, keys ...interface{}) *metaEntity {
m.CustomFields[value] = keys
return m
}

func (m *MetaEntity) Json() string {
func (m *metaEntity) Json() string {
return utils.ToJson(m)
}

func (p *PaginationEntity) SetPage(value int) *PaginationEntity {
func (p *paginationEntity) SetPage(value int) *paginationEntity {
if value <= 0 {
log.Panicf("Invalid page: %v", value)
}
p.Page = value
return p
}

func (p *PaginationEntity) SetPerPage(value int) *PaginationEntity {
func (p *paginationEntity) SetPerPage(value int) *paginationEntity {
if value < 0 {
log.Panicf("Invalid per_page: %v", value)
}
p.PerPage = value
return p
}

func (p *PaginationEntity) SetTotalPages(value int) *PaginationEntity {
func (p *paginationEntity) SetTotalPages(value int) *paginationEntity {
if value < 0 {
log.Panicf("Invalid total_pages: %v", value)
}
p.TotalPages = value
return p
}

func (p *PaginationEntity) SetTotalItems(value int) *PaginationEntity {
func (p *paginationEntity) SetTotalItems(value int) *paginationEntity {
if value < 0 {
log.Panicf("Invalid total_items: %v", value)
}
p.TotalItems = value
return p
}

func (p *PaginationEntity) SetIsLast(value bool) *PaginationEntity {
func (p *paginationEntity) SetIsLast(value bool) *paginationEntity {
p.IsLast = value
return p
}

func (p *PaginationEntity) Json() string {
func (p *paginationEntity) Json() string {
return utils.ToJson(p)
}

func PaginationEntityValidator(p *PaginationEntity) {
func PaginationEntityValidator(p *paginationEntity) {
p.SetPage(p.Page).
SetPerPage(p.PerPage).
SetTotalPages(p.TotalPages).
SetTotalItems(p.TotalItems)
}

func (r *ResponseEntity) SetStatusCode(value int) *ResponseEntity {
func (r *responseEntity) SetStatusCode(value int) *responseEntity {
r.StatusCode = value
return r
}

func (r *ResponseEntity) SetTotal(value int) *ResponseEntity {
func (r *responseEntity) SetTotal(value int) *responseEntity {
if value < 0 {
log.Panicf("Invalid total: %v", value)
}
r.Total = value
return r
}

func (r *ResponseEntity) SetMessage(value string) *ResponseEntity {
func (r *responseEntity) SetMessage(value string) *responseEntity {
r.Message = value
return r
}

func (r *ResponseEntity) AppendMessage(value ...string) *ResponseEntity {
func (r *responseEntity) AppendMessage(value ...string) *responseEntity {
r.Message = strings.Join(value, ",")
return r
}

func (r *ResponseEntity) SetData(value interface{}) *ResponseEntity {
func (r *responseEntity) SetData(value interface{}) *responseEntity {
r.Data = value
return r
}

func (r *ResponseEntity) SetErrors(value interface{}) *ResponseEntity {
func (r *responseEntity) SetErrors(value interface{}) *responseEntity {
r.Errors = value
return r
}

func (r *ResponseEntity) SetError(value error) *ResponseEntity {
func (r *responseEntity) SetError(value error) *responseEntity {
r.Errors = value.Error()
return r
}

func (r *ResponseEntity) SetHeaders(value map[string]interface{}) *ResponseEntity {
func (r *responseEntity) SetHeaders(value map[string]interface{}) *responseEntity {
r.Headers = value
return r
}

func (r *ResponseEntity) AppendHeader(key string, value string) *ResponseEntity {
func (r *responseEntity) AppendHeader(key string, value string) *responseEntity {
r.Headers[key] = value
return r
}

func (r *ResponseEntity) AppendHeaders(key string, value ...string) *ResponseEntity {
func (r *responseEntity) AppendHeaders(key string, value ...string) *responseEntity {
r.Headers[key] = value
return r
}

func (r *ResponseEntity) AppendHeaderWith(key string, value interface{}) *ResponseEntity {
func (r *responseEntity) AppendHeaderWith(key string, value interface{}) *responseEntity {
r.Headers[key] = value
return r
}

func (r *ResponseEntity) SetMeta(value MetaEntity) *ResponseEntity {
func (r *responseEntity) SetMeta(value metaEntity) *responseEntity {
r.Meta = value
return r
}

func (r *ResponseEntity) SetPagination(value PaginationEntity) *ResponseEntity {
func (r *responseEntity) SetPagination(value paginationEntity) *responseEntity {
r.Pagination = value
return r
}

func (r *ResponseEntity) Json() string {
func (r *responseEntity) Json() string {
return utils.ToJson(r)
}

func (ResponseEntity) Ok(message string, data interface{}) ResponseEntity {
func (responseEntity) Ok(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusOK).
SetMessage(message).
Expand All @@ -193,7 +193,7 @@ func (ResponseEntity) Ok(message string, data interface{}) ResponseEntity {
return *r
}

func (ResponseEntity) Created(message string, data interface{}) ResponseEntity {
func (responseEntity) Created(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusCreated).
SetMessage(message).
Expand All @@ -202,7 +202,7 @@ func (ResponseEntity) Created(message string, data interface{}) ResponseEntity {
return *r
}

func (ResponseEntity) BadRequest(message string, data interface{}) ResponseEntity {
func (responseEntity) BadRequest(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusBadRequest).
SetMessage(message).
Expand All @@ -211,7 +211,7 @@ func (ResponseEntity) BadRequest(message string, data interface{}) ResponseEntit
return *r
}

func (ResponseEntity) NotFound(message string, data interface{}) ResponseEntity {
func (responseEntity) NotFound(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusNotFound).
SetMessage(message).
Expand All @@ -220,7 +220,7 @@ func (ResponseEntity) NotFound(message string, data interface{}) ResponseEntity
return *r
}

func (ResponseEntity) NotImplemented(message string, data interface{}) ResponseEntity {
func (responseEntity) NotImplemented(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusNotImplemented).
SetMessage(message).
Expand All @@ -229,7 +229,7 @@ func (ResponseEntity) NotImplemented(message string, data interface{}) ResponseE
return *r
}

func (ResponseEntity) TooManyRequest(message string, data interface{}) ResponseEntity {
func (responseEntity) TooManyRequest(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusTooManyRequests).
SetMessage(message).
Expand All @@ -238,7 +238,7 @@ func (ResponseEntity) TooManyRequest(message string, data interface{}) ResponseE
return *r
}

func (ResponseEntity) Locked(message string, data interface{}) ResponseEntity {
func (responseEntity) Locked(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusLocked).
SetMessage(message).
Expand All @@ -247,7 +247,7 @@ func (ResponseEntity) Locked(message string, data interface{}) ResponseEntity {
return *r
}

func (ResponseEntity) NoContent(message string, data interface{}) ResponseEntity {
func (responseEntity) NoContent(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusNoContent).
SetMessage(message).
Expand All @@ -256,7 +256,7 @@ func (ResponseEntity) NoContent(message string, data interface{}) ResponseEntity
return *r
}

func (ResponseEntity) Processing(message string, data interface{}) ResponseEntity {
func (responseEntity) Processing(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusProcessing).
SetMessage(message).
Expand All @@ -265,7 +265,7 @@ func (ResponseEntity) Processing(message string, data interface{}) ResponseEntit
return *r
}

func (ResponseEntity) UpgradeRequired(message string, data interface{}) ResponseEntity {
func (responseEntity) UpgradeRequired(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusUpgradeRequired).
SetMessage(message).
Expand All @@ -274,7 +274,7 @@ func (ResponseEntity) UpgradeRequired(message string, data interface{}) Response
return *r
}

func (ResponseEntity) ServiceUnavailable(message string, data interface{}) ResponseEntity {
func (responseEntity) ServiceUnavailable(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusServiceUnavailable).
SetMessage(message).
Expand All @@ -283,7 +283,7 @@ func (ResponseEntity) ServiceUnavailable(message string, data interface{}) Respo
return *r
}

func (ResponseEntity) InternalServerError(message string, data interface{}) ResponseEntity {
func (responseEntity) InternalServerError(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusInternalServerError).
SetMessage(message).
Expand All @@ -292,7 +292,7 @@ func (ResponseEntity) InternalServerError(message string, data interface{}) Resp
return *r
}

func (ResponseEntity) GatewayTimeout(message string, data interface{}) ResponseEntity {
func (responseEntity) GatewayTimeout(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusGatewayTimeout).
SetMessage(message).
Expand All @@ -301,7 +301,7 @@ func (ResponseEntity) GatewayTimeout(message string, data interface{}) ResponseE
return *r
}

func (ResponseEntity) MethodNotAllowed(message string, data interface{}) ResponseEntity {
func (responseEntity) MethodNotAllowed(message string, data interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(http.StatusMethodNotAllowed).
SetMessage(message).
Expand All @@ -310,7 +310,7 @@ func (ResponseEntity) MethodNotAllowed(message string, data interface{}) Respons
return *r
}

func (ResponseEntity) BuildX(statusCode int, message string, data interface{}, errors interface{}) ResponseEntity {
func (responseEntity) BuildX(statusCode int, message string, data interface{}, errors interface{}) responseEntity {
r := NewResponseEntity().
SetStatusCode(statusCode).
SetMessage(message).
Expand Down
10 changes: 5 additions & 5 deletions entity/entity_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import (
"time"
)

type ResponseEntity struct {
type responseEntity struct {
StatusCode int `json:"status_code" binding:"required"`
Total int `json:"total"`
Message string `json:"message"`
Data interface{} `json:"data"`
Errors interface{} `json:"errors"`
Headers map[string]interface{} `json:"headers"`
Meta MetaEntity `json:"meta,omitempty"`
Pagination PaginationEntity `json:"pagination,omitempty"`
Meta metaEntity `json:"meta,omitempty"`
Pagination paginationEntity `json:"pagination,omitempty"`
}

type PaginationEntity struct {
type paginationEntity struct {
Page int `json:"page,omitempty"`
PerPage int `json:"per_page,omitempty"`
TotalPages int `json:"total_pages,omitempty"`
TotalItems int `json:"total_items,omitempty"`
IsLast bool `json:"is_last,omitempty"`
}

type MetaEntity struct {
type metaEntity struct {
ApiVersion string `json:"api_version,omitempty"`
RequestId string `json:"request_id,omitempty"`
Locale string `json:"locale,omitempty"`
Expand Down

0 comments on commit 0e9c278

Please sign in to comment.