diff --git a/jwt/login.go b/jwt/login.go index 1090cd3..0494e44 100644 --- a/jwt/login.go +++ b/jwt/login.go @@ -51,7 +51,7 @@ var ( ) // VerifyToken verifys a given string-token. -func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error) { +func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error) { //nolint:ireturn token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { return nil, fmt.Errorf("method '%v': %w", token.Header["alg"], ErrUnexpectedSigningMethod) diff --git a/postgres/budgetservice.go b/postgres/budgetservice.go index bcb4512..82372dd 100644 --- a/postgres/budgetservice.go +++ b/postgres/budgetservice.go @@ -8,7 +8,7 @@ import ( "github.com/google/uuid" ) -// NewBudget creates a budget and adds it to the current user +// NewBudget creates a budget and adds it to the current user. func (s *Database) NewBudget(context context.Context, name string, userID uuid.UUID) (*Budget, error) { tx, err := s.BeginTx(context, &sql.TxOptions{}) if err != nil { diff --git a/postgres/conn.go b/postgres/conn.go index 6a5c814..6c04480 100644 --- a/postgres/conn.go +++ b/postgres/conn.go @@ -17,7 +17,7 @@ type Database struct { *sql.DB } -// Connect to a database +// Connect connects to a database. func Connect(typ string, connString string) (*Database, error) { conn, err := sql.Open(typ, connString) if err != nil { diff --git a/postgres/ynab-import.go b/postgres/ynab-import.go index 8892d8f..3c80bad 100644 --- a/postgres/ynab-import.go +++ b/postgres/ynab-import.go @@ -56,7 +56,7 @@ func NewYNABImport(context context.Context, queries *Queries, budgetID uuid.UUID // "Month" "Category Group/Category" "Category Group" "Category" "Budgeted" "Activity" "Available" // "Apr 2019" "Income: Next Month" "Income" "Next Month" 0,00€ 0,00€ 0,00€ // -// Activity and Available are not imported, since they are determined by the transactions and historic assignments +// Activity and Available are not imported, since they are determined by the transactions and historic assignments. func (ynab *YNABImport) ImportAssignments(context context.Context, r io.Reader) error { csv := csv.NewReader(r) csv.Comma = '\t' @@ -184,7 +184,8 @@ func (ynab *YNABImport) ImportTransactions(context context.Context, r io.Reader) // Transaction is a transfer to var shouldReturn bool var returnValue error - openTransfers, shouldReturn, returnValue = ynab.ImportTransaction(payeeName, context, transaction, accountName, openTransfers, account, amount) + openTransfers, shouldReturn, returnValue = ynab.ImportTransaction( + payeeName, context, transaction, accountName, openTransfers, account, amount) if shouldReturn { return returnValue } @@ -368,13 +369,15 @@ func (ynab *YNABImport) GetCategory(context context.Context, group string, name } } - categoryGroup, err := ynab.queries.CreateCategoryGroup(context, CreateCategoryGroupParams{Name: group, BudgetID: ynab.budgetID}) + newGroup := CreateCategoryGroupParams{Name: group, BudgetID: ynab.budgetID} + categoryGroup, err := ynab.queries.CreateCategoryGroup(context, newGroup) if err != nil { return uuid.NullUUID{}, err } ynab.categoryGroups = append(ynab.categoryGroups, categoryGroup) - category, err := ynab.queries.CreateCategory(context, CreateCategoryParams{Name: name, CategoryGroupID: categoryGroup.ID}) + newCategory := CreateCategoryParams{Name: name, CategoryGroupID: categoryGroup.ID} + category, err := ynab.queries.CreateCategory(context, newCategory) if err != nil { return uuid.NullUUID{}, err } diff --git a/server/account_test.go b/server/account_test.go index d7ee98e..8ea523a 100644 --- a/server/account_test.go +++ b/server/account_test.go @@ -14,7 +14,7 @@ import ( "github.com/gin-gonic/gin" ) -func init() { +func init() { //nolint:gochecknoinits txdb.Register("pgtx", "pgx", "postgres://budgeteer_test:budgeteer_test@localhost:5432/budgeteer_test") } diff --git a/server/autocomplete.go b/server/autocomplete.go index 626b9ee..46dfb3c 100644 --- a/server/autocomplete.go +++ b/server/autocomplete.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "net/http" "git.javil.eu/jacob1123/budgeteer/postgres" @@ -13,7 +12,7 @@ func (h *Handler) autocompleteCategories(c *gin.Context) { budgetID := c.Param("budgetid") budgetUUID, err := uuid.Parse(budgetID) if err != nil { - c.AbortWithError(http.StatusBadRequest, fmt.Errorf("budgetid missing from URL")) + c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budgetid missing from URL"}) return } @@ -35,7 +34,7 @@ func (h *Handler) autocompletePayee(c *gin.Context) { budgetID := c.Param("budgetid") budgetUUID, err := uuid.Parse(budgetID) if err != nil { - c.AbortWithError(http.StatusBadRequest, fmt.Errorf("budgetid missing from URL")) + c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budgetid missing from URL"}) return } diff --git a/server/budget.go b/server/budget.go index e330659..dd66e43 100644 --- a/server/budget.go +++ b/server/budget.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "net/http" "git.javil.eu/jacob1123/budgeteer" @@ -20,7 +19,7 @@ func (h *Handler) newBudget(c *gin.Context) { } if newBudget.Name == "" { - c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("Budget name is needed")) + c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budget name is required"}) return } diff --git a/server/budgeting.go b/server/budgeting.go index 48ff479..6addb2e 100644 --- a/server/budgeting.go +++ b/server/budgeting.go @@ -85,7 +85,8 @@ func (h *Handler) budgetingForMonth(c *gin.Context) { } // skip everything in the future - categoriesWithBalance, moneyUsed, err := h.calculateBalances(c, budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances) + categoriesWithBalance, moneyUsed, err := h.calculateBalances( + c, budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances) if err != nil { return } diff --git a/server/http.go b/server/http.go index bdc8d66..569464b 100644 --- a/server/http.go +++ b/server/http.go @@ -104,7 +104,11 @@ func (h *Handler) ServeStaticFile(c *gin.Context, fullPath string) { return } - http.ServeContent(c.Writer, c.Request, stat.Name(), stat.ModTime(), file.(io.ReadSeeker)) + if file, ok := file.(io.ReadSeeker); ok { + http.ServeContent(c.Writer, c.Request, stat.Name(), stat.ModTime(), file) + } else { + panic("File does not implement ReadSeeker") + } } func enableCachingForStaticFiles() gin.HandlerFunc { diff --git a/server/transaction.go b/server/transaction.go index c11afdb..36e6380 100644 --- a/server/transaction.go +++ b/server/transaction.go @@ -50,7 +50,7 @@ func (h *Handler) newTransaction(c *gin.Context) { }*/ // if !transactionUUID.Valid { - new := postgres.CreateTransactionParams{ + newTransaction := postgres.CreateTransactionParams{ Memo: payload.Memo, Date: time.Time(payload.Date), Amount: amount, @@ -59,7 +59,7 @@ func (h *Handler) newTransaction(c *gin.Context) { CategoryID: payload.Category.ID, // TODO handle new category Status: postgres.TransactionStatus(payload.State), } - _, err = h.Service.CreateTransaction(c.Request.Context(), new) + _, err = h.Service.CreateTransaction(c.Request.Context(), newTransaction) if err != nil { c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err)) }