Skip to content

Commit

Permalink
refactor: rename files using flatcase
Browse files Browse the repository at this point in the history
  • Loading branch information
bastean committed May 27, 2024
1 parent 0f6a21e commit 28d3e5f
Show file tree
Hide file tree
Showing 35 changed files with 90 additions and 110 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ install-deps:
curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sudo sh -s -- -b /usr/local/bin v3.63.11

copy-deps:
go run ./scripts/copy-deps
go run ./scripts/copydeps

#* Generators
generate-required:
Expand Down Expand Up @@ -140,7 +140,7 @@ sync-env-reset:
${git-reset-hard}

sync-env:
cd deployments && go run ../scripts/sync-env
cd deployments && go run ../scripts/syncenv

#* Git
commit:
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/JGLTechnologies/gin-rate-limit v1.5.4 h1:1hIaXIdGM9MZFZlXgjWJLpxaK0WHEa5MeloK49nmQsc=
github.com/JGLTechnologies/gin-rate-limit v1.5.4/go.mod h1:mGEhNzlHEg/Tk+KH/mKylZLTfDjACnx7MVYaAlj07eU=
github.com/a-h/templ v0.2.697 h1:OILxtWvD0NRJaoCOiZCopRDPW8paroKlGsrAiHLykNE=
github.com/a-h/templ v0.2.697/go.mod h1:5cqsugkq9IerRNucNsI4DEamdHPsoGMQy99DzydLhM8=
github.com/a-h/templ v0.2.707 h1:T1Gkd2ugbRglZ9rYw/VBchWOSZVKmetDbBkm4YubM7U=
github.com/a-h/templ v0.2.707/go.mod h1:5cqsugkq9IerRNucNsI4DEamdHPsoGMQy99DzydLhM8=
github.com/brianvoe/gofakeit/v7 v7.0.3 h1:tGCt+eYfhTMWE1ko5G2EO1f/yE44yNpIwUb4h32O0wo=
Expand Down Expand Up @@ -36,8 +34,6 @@ github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80N
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
github.com/gin-contrib/secure v1.1.0 h1:wy/psCWbgUBDCLH13KgB/m06NHXb1jczSTRp+H2hK7E=
Expand Down Expand Up @@ -182,8 +178,6 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d h1:N0hmiNbwsSNwHBAvR3QB5w25pUwH4tK0Y/RltD1j1h4=
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package form
package user

import (
"net/http"
Expand All @@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin"
)

func UserCreate() gin.HandlerFunc {
func Create() gin.HandlerFunc {
return func(c *gin.Context) {
command := new(user.CreateCommand)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package form
package user

import (
"net/http"
Expand All @@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
)

func UserDelete() gin.HandlerFunc {
func Delete() gin.HandlerFunc {
return func(c *gin.Context) {
id, exists := c.Get(key.UserId)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package form
package user

import (
"net/http"
Expand All @@ -12,7 +12,7 @@ import (
"github.com/gin-gonic/gin"
)

func UserLogin() gin.HandlerFunc {
func Login() gin.HandlerFunc {
return func(c *gin.Context) {
query := new(user.LoginQuery)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package form
package user

import (
"net/http"
Expand All @@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
)

func UserUpdate() gin.HandlerFunc {
func Update() gin.HandlerFunc {
return func(c *gin.Context) {
id, exists := c.Get(key.UserId)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package param
package user

import (
"net/http"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/gin-gonic/gin"
)

func UserVerify() gin.HandlerFunc {
func Verify() gin.HandlerFunc {
return func(c *gin.Context) {
id := c.Param(key.Id)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions pkg/cmd/server/router/routes.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package router

import (
"github.com/bastean/codexgo/pkg/cmd/server/handler/form"
"github.com/bastean/codexgo/pkg/cmd/server/handler/page"
"github.com/bastean/codexgo/pkg/cmd/server/handler/param"
"github.com/bastean/codexgo/pkg/cmd/server/handler/user"
"github.com/bastean/codexgo/pkg/cmd/server/middleware"
)

Expand All @@ -13,14 +12,14 @@ func InitRoutes() {
public := router.Group("/")

public.GET("/", page.Home())
public.PUT("/", form.UserCreate())
public.POST("/", form.UserLogin())
public.PUT("/", user.Create())
public.POST("/", user.Login())

public.GET("/verify/:id", param.UserVerify())
public.GET("/verify/:id", user.Verify())

auth := public.Group("/dashboard", middleware.VerifyAuthentication())

auth.GET("/", page.Dashboard())
auth.PATCH("/", form.UserUpdate())
auth.DELETE("/", form.UserDelete())
auth.PATCH("/", user.Update())
auth.DELETE("/", user.Delete())
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ type AlreadyExist struct {
*Bubble
}

type NotExist struct {
*Bubble
}

func NewAlreadyExist(bubble *Bubble) error {
return &AlreadyExist{
Bubble: NewBubble(
Expand All @@ -14,3 +18,14 @@ func NewAlreadyExist(bubble *Bubble) error {
),
}
}

func NewNotExist(bubble *Bubble) error {
return &NotExist{
Bubble: NewBubble(
bubble.Where,
bubble.What,
bubble.Why,
bubble.Who,
),
}
}
File renamed without changes.
16 changes: 0 additions & 16 deletions pkg/context/shared/domain/errors/notExist.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"errors"
)

func Join(errs ...error) error {
return errors.Join(errs...)
}

func As(err error, target any) bool {
return errors.As(err, target)
}
9 changes: 0 additions & 9 deletions pkg/context/shared/domain/errors/wrap.join.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/context/shared/domain/models/commandHandler.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package models

type CommandHandler[Command any] interface {
Handle(Command) error
}

type QueryHandler[Query, Response any] interface {
Handle(Query) (Response, error)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 0 additions & 40 deletions pkg/context/shared/infrastructure/persistences/mongo.error.go

This file was deleted.

62 changes: 48 additions & 14 deletions pkg/context/shared/infrastructure/persistences/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@ package persistences

import (
"context"
"regexp"
"strings"

"github.com/bastean/codexgo/pkg/context/shared/domain/errors"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

type MongoDB struct {
*mongo.Client
*mongo.Database
}

func CloseMongoDatabase(ctx context.Context, mdb *MongoDB) error {
err := mdb.Client.Disconnect(ctx)

if err != nil {
return errors.NewInternal(&errors.Bubble{
Where: "CloseMongoDatabase",
What: "failure to close connection with mongodb",
Who: err,
})
}

return nil
}

func NewMongoDatabase(uri, databaseName string) (*MongoDB, error) {
var err error

Expand Down Expand Up @@ -57,3 +47,47 @@ func NewMongoDatabase(uri, databaseName string) (*MongoDB, error) {
Database: client.Database(databaseName),
}, nil
}

func HandleMongoDuplicateKeyError(err error) error {
re := regexp.MustCompile(`{ [A-Za-z0-9]+:`)

rawField := re.FindString(err.Error())

toTitle := cases.Title(language.English)

field := toTitle.String(strings.TrimSuffix(strings.Split(rawField, " ")[1], ":"))

return errors.NewAlreadyExist(&errors.Bubble{
Where: "HandleMongoDuplicateKeyError",
What: "already registered",
Why: errors.Meta{
"Field": field,
},
Who: err,
})
}

func HandleMongoDocumentNotFound(index string, err error) error {
return errors.NewNotExist(&errors.Bubble{
Where: "HandleMongoDocumentNotFound",
What: "not found",
Why: errors.Meta{
"Index": index,
},
Who: err,
})
}

func CloseMongoDatabase(ctx context.Context, mdb *MongoDB) error {
err := mdb.Client.Disconnect(ctx)

if err != nil {
return errors.NewInternal(&errors.Bubble{
Where: "CloseMongoDatabase",
What: "failure to close connection with mongodb",
Who: err,
})
}

return nil
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
)

const cli = "sync-env"
const cli = "syncenv"

var envFilesDir string
var envFileModel string
Expand Down

0 comments on commit 28d3e5f

Please sign in to comment.