Skip to content

Commit

Permalink
fixed linter issues with ireturn
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvodi committed Sep 2, 2024
1 parent b9e28fe commit dd762bd
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 98 deletions.
11 changes: 5 additions & 6 deletions internal/api/api_model_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ package api
import (
"github.com/go-playground/validator/v10"
"github.com/tomvodi/limepipes/internal/apigen/apimodel"
"github.com/tomvodi/limepipes/internal/interfaces"
)

type apiModelValidator struct {
type ModelValidator struct {
validator *validator.Validate
}

func (v *apiModelValidator) ValidateUpdateTune(tuneUpd apimodel.UpdateTune) error {
func (v *ModelValidator) ValidateUpdateTune(tuneUpd apimodel.UpdateTune) error {
return v.validator.Struct(tuneUpd)
}

func (v *apiModelValidator) ValidateUpdateSet(setUpd apimodel.UpdateSet) error {
func (v *ModelValidator) ValidateUpdateSet(setUpd apimodel.UpdateSet) error {
return v.validator.Struct(setUpd)
}

func NewAPIModelValidator(
validator *validator.Validate,
) interfaces.APIModelValidator {
return &apiModelValidator{
) *ModelValidator {
return &ModelValidator{
validator: validator,
}
}
41 changes: 20 additions & 21 deletions internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/google/uuid"
"github.com/tomvodi/limepipes-plugin-api/plugin/v1/file_type"
"github.com/tomvodi/limepipes/internal/apigen/apimodel"
api_interfaces "github.com/tomvodi/limepipes/internal/apigen/interfaces"
"github.com/tomvodi/limepipes/internal/common"
"github.com/tomvodi/limepipes/internal/interfaces"
"io"
Expand All @@ -16,17 +15,17 @@ import (
"path/filepath"
)

type apiHandler struct {
type Handler struct {
service interfaces.DataService
pluginLoader interfaces.PluginLoader
healthChecker interfaces.HealthChecker
}

func (a *apiHandler) Home(c *gin.Context) {
func (a *Handler) Home(c *gin.Context) {
c.Status(http.StatusOK)
}

func (a *apiHandler) Health(c *gin.Context) {
func (a *Handler) Health(c *gin.Context) {
handler, err := a.healthChecker.GetCheckHandler()
if err != nil {
httpErrorResponse(c, http.StatusInternalServerError, err)
Expand All @@ -37,7 +36,7 @@ func (a *apiHandler) Health(c *gin.Context) {
handleFunc(c)
}

func (a *apiHandler) ImportFile(c *gin.Context) {
func (a *Handler) ImportFile(c *gin.Context) {
iFile, err := c.FormFile("file")
if err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand Down Expand Up @@ -95,7 +94,7 @@ func (a *apiHandler) ImportFile(c *gin.Context) {
c.JSON(http.StatusOK, importResponse)
}

func (a *apiHandler) createImportFileInfo(
func (a *Handler) createImportFileInfo(
iFile *multipart.FileHeader,
fType file_type.Type,
) (*common.ImportFileInfo, error) {
Expand All @@ -118,7 +117,7 @@ func (a *apiHandler) createImportFileInfo(
return fInfo, nil
}

func (a *apiHandler) importFile(
func (a *Handler) importFile(
fInfo *common.ImportFileInfo,
fileExt string,
) ([]*apimodel.ImportTune, *apimodel.BasicMusicSet, error) {
Expand Down Expand Up @@ -152,11 +151,11 @@ func handleResponseForError(c *gin.Context, err error) {
})
}

func (a *apiHandler) Index(c *gin.Context) {
func (a *Handler) Index(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}

func (a *apiHandler) CreateTune(c *gin.Context) {
func (a *Handler) CreateTune(c *gin.Context) {
var createTune apimodel.CreateTune
if err := c.ShouldBindJSON(&createTune); err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand All @@ -172,7 +171,7 @@ func (a *apiHandler) CreateTune(c *gin.Context) {
c.JSON(http.StatusOK, tune)
}

func (a *apiHandler) GetTune(c *gin.Context) {
func (a *Handler) GetTune(c *gin.Context) {
tuneID, err := uuid.Parse(c.Param("tuneID"))
if err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand All @@ -188,7 +187,7 @@ func (a *apiHandler) GetTune(c *gin.Context) {
c.JSON(http.StatusOK, tune)
}

func (a *apiHandler) ListTunes(c *gin.Context) {
func (a *Handler) ListTunes(c *gin.Context) {
tunes, err := a.service.Tunes()
if err != nil {
httpErrorResponse(c, http.StatusInternalServerError, err)
Expand All @@ -197,7 +196,7 @@ func (a *apiHandler) ListTunes(c *gin.Context) {
c.JSON(http.StatusOK, tunes)
}

func (a *apiHandler) UpdateTune(c *gin.Context) {
func (a *Handler) UpdateTune(c *gin.Context) {
var updateTune apimodel.UpdateTune
if err := c.ShouldBindJSON(&updateTune); err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand All @@ -219,7 +218,7 @@ func (a *apiHandler) UpdateTune(c *gin.Context) {
c.JSON(http.StatusOK, tune)
}

func (a *apiHandler) DeleteTune(c *gin.Context) {
func (a *Handler) DeleteTune(c *gin.Context) {
tuneID, err := uuid.Parse(c.Param("tuneID"))
if err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand All @@ -234,7 +233,7 @@ func (a *apiHandler) DeleteTune(c *gin.Context) {
c.Status(http.StatusNoContent)
}

func (a *apiHandler) CreateSet(c *gin.Context) {
func (a *Handler) CreateSet(c *gin.Context) {
var createSet apimodel.CreateSet

if err := c.ShouldBindJSON(&createSet); err != nil {
Expand All @@ -251,7 +250,7 @@ func (a *apiHandler) CreateSet(c *gin.Context) {
c.JSON(http.StatusOK, set)
}

func (a *apiHandler) GetSet(c *gin.Context) {
func (a *Handler) GetSet(c *gin.Context) {
setID, err := uuid.Parse(c.Param("setID"))
if err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand All @@ -267,7 +266,7 @@ func (a *apiHandler) GetSet(c *gin.Context) {
c.JSON(http.StatusOK, set)
}

func (a *apiHandler) ListSets(c *gin.Context) {
func (a *Handler) ListSets(c *gin.Context) {
sets, err := a.service.MusicSets()
if err != nil {
httpErrorResponse(c, http.StatusInternalServerError, err)
Expand All @@ -276,7 +275,7 @@ func (a *apiHandler) ListSets(c *gin.Context) {
c.JSON(http.StatusOK, sets)
}

func (a *apiHandler) UpdateSet(c *gin.Context) {
func (a *Handler) UpdateSet(c *gin.Context) {
var updateSet apimodel.UpdateSet
if err := c.ShouldBindJSON(&updateSet); err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand All @@ -297,7 +296,7 @@ func (a *apiHandler) UpdateSet(c *gin.Context) {
c.JSON(http.StatusOK, set)
}

func (a *apiHandler) DeleteSet(c *gin.Context) {
func (a *Handler) DeleteSet(c *gin.Context) {
setID, err := uuid.Parse(c.Param("setID"))
if err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand All @@ -312,7 +311,7 @@ func (a *apiHandler) DeleteSet(c *gin.Context) {
c.Status(http.StatusNoContent)
}

func (a *apiHandler) AssignTunesToSet(c *gin.Context) {
func (a *Handler) AssignTunesToSet(c *gin.Context) {
var tuneIDs []uuid.UUID
if err := c.ShouldBindJSON(&tuneIDs); err != nil {
httpErrorResponse(c, http.StatusBadRequest, err)
Expand All @@ -338,8 +337,8 @@ func NewAPIHandler(
service interfaces.DataService,
pluginLoader interfaces.PluginLoader,
healthChecker interfaces.HealthChecker,
) api_interfaces.ApiHandler {
return &apiHandler{
) *Handler {
return &Handler{
service: service,
pluginLoader: pluginLoader,
healthChecker: healthChecker,
Expand Down
6 changes: 3 additions & 3 deletions internal/api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ type multipartRequest struct {
HTTPMethod string
}

var _ = Describe("Api handler", func() {
var _ = Describe("Api Handler", func() {
utils.SetupConsoleLogger()
var c *gin.Context
var httpRec *httptest.ResponseRecorder
var api *apiHandler
var api *Handler
var testID1 uuid.UUID
var dataService *mocks.DataService
var pluginLoader *mocks.PluginLoader
Expand All @@ -51,7 +51,7 @@ var _ = Describe("Api handler", func() {
dataService = mocks.NewDataService(GinkgoT())
pluginLoader = mocks.NewPluginLoader(GinkgoT())
lpPlugin = pmocks.NewLimePipesPlugin(GinkgoT())
api = &apiHandler{
api = &Handler{
service: dataService,
pluginLoader: pluginLoader,
}
Expand Down
Loading

0 comments on commit dd762bd

Please sign in to comment.