Skip to content

Commit

Permalink
🌱Remove api/resource/book/api.go
Browse files Browse the repository at this point in the history
  • Loading branch information
dumindu committed Sep 14, 2023
1 parent 734ccac commit 40b27a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
22 changes: 0 additions & 22 deletions api/resource/book/api.go

This file was deleted.

22 changes: 19 additions & 3 deletions api/resource/book/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@ import (
"net/http"

"github.com/go-chi/chi/v5"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"gorm.io/gorm"

e "myapp/api/resource/common/err"
"myapp/util/validator"
"myapp/util/logger"
validatorUtil "myapp/util/validator"
)

type API struct {
logger *logger.Logger
validator *validator.Validate
repository *Repository
}

func New(logger *logger.Logger, validator *validator.Validate, db *gorm.DB) *API {
return &API{
logger: logger,
validator: validator,
repository: NewRepository(db),
}
}

// List godoc
//
// @summary List books
Expand Down Expand Up @@ -65,7 +81,7 @@ func (a *API) Create(w http.ResponseWriter, r *http.Request) {
}

if err := a.validator.Struct(form); err != nil {
resp := validator.ToErrResponse(err)
resp := validatorUtil.ToErrResponse(err)
if resp == nil {
e.ServerError(w, e.FormErrResponseFailure)
return
Expand Down Expand Up @@ -163,7 +179,7 @@ func (a *API) Update(w http.ResponseWriter, r *http.Request) {
}

if err := a.validator.Struct(form); err != nil {
resp := validator.ToErrResponse(err)
resp := validatorUtil.ToErrResponse(err)
if resp == nil {
e.ServerError(w, e.FormErrResponseFailure)
return
Expand Down

0 comments on commit 40b27a3

Please sign in to comment.