Minimal linting improvements
This commit is contained in:
parent
545f223a97
commit
c03d16878a
@ -51,7 +51,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// VerifyToken verifys a given string-token.
|
// 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) {
|
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
|
||||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
return nil, fmt.Errorf("method '%v': %w", token.Header["alg"], ErrUnexpectedSigningMethod)
|
return nil, fmt.Errorf("method '%v': %w", token.Header["alg"], ErrUnexpectedSigningMethod)
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"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) {
|
func (s *Database) NewBudget(context context.Context, name string, userID uuid.UUID) (*Budget, error) {
|
||||||
tx, err := s.BeginTx(context, &sql.TxOptions{})
|
tx, err := s.BeginTx(context, &sql.TxOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,7 +17,7 @@ type Database struct {
|
|||||||
*sql.DB
|
*sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to a database
|
// Connect connects to a database.
|
||||||
func Connect(typ string, connString string) (*Database, error) {
|
func Connect(typ string, connString string) (*Database, error) {
|
||||||
conn, err := sql.Open(typ, connString)
|
conn, err := sql.Open(typ, connString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -56,7 +56,7 @@ func NewYNABImport(context context.Context, queries *Queries, budgetID uuid.UUID
|
|||||||
// "Month" "Category Group/Category" "Category Group" "Category" "Budgeted" "Activity" "Available"
|
// "Month" "Category Group/Category" "Category Group" "Category" "Budgeted" "Activity" "Available"
|
||||||
// "Apr 2019" "Income: Next Month" "Income" "Next Month" 0,00€ 0,00€ 0,00€
|
// "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 {
|
func (ynab *YNABImport) ImportAssignments(context context.Context, r io.Reader) error {
|
||||||
csv := csv.NewReader(r)
|
csv := csv.NewReader(r)
|
||||||
csv.Comma = '\t'
|
csv.Comma = '\t'
|
||||||
@ -184,7 +184,8 @@ func (ynab *YNABImport) ImportTransactions(context context.Context, r io.Reader)
|
|||||||
// Transaction is a transfer to
|
// Transaction is a transfer to
|
||||||
var shouldReturn bool
|
var shouldReturn bool
|
||||||
var returnValue error
|
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 {
|
if shouldReturn {
|
||||||
return returnValue
|
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 {
|
if err != nil {
|
||||||
return uuid.NullUUID{}, err
|
return uuid.NullUUID{}, err
|
||||||
}
|
}
|
||||||
ynab.categoryGroups = append(ynab.categoryGroups, categoryGroup)
|
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 {
|
if err != nil {
|
||||||
return uuid.NullUUID{}, err
|
return uuid.NullUUID{}, err
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() { //nolint:gochecknoinits
|
||||||
txdb.Register("pgtx", "pgx", "postgres://budgeteer_test:budgeteer_test@localhost:5432/budgeteer_test")
|
txdb.Register("pgtx", "pgx", "postgres://budgeteer_test:budgeteer_test@localhost:5432/budgeteer_test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||||
@ -13,7 +12,7 @@ func (h *Handler) autocompleteCategories(c *gin.Context) {
|
|||||||
budgetID := c.Param("budgetid")
|
budgetID := c.Param("budgetid")
|
||||||
budgetUUID, err := uuid.Parse(budgetID)
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("budgetid missing from URL"))
|
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budgetid missing from URL"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ func (h *Handler) autocompletePayee(c *gin.Context) {
|
|||||||
budgetID := c.Param("budgetid")
|
budgetID := c.Param("budgetid")
|
||||||
budgetUUID, err := uuid.Parse(budgetID)
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("budgetid missing from URL"))
|
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budgetid missing from URL"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer"
|
"git.javil.eu/jacob1123/budgeteer"
|
||||||
@ -20,7 +19,7 @@ func (h *Handler) newBudget(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if newBudget.Name == "" {
|
if newBudget.Name == "" {
|
||||||
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("Budget name is needed"))
|
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budget name is required"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,8 @@ func (h *Handler) budgetingForMonth(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// skip everything in the future
|
// 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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,11 @@ func (h *Handler) ServeStaticFile(c *gin.Context, fullPath string) {
|
|||||||
return
|
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 {
|
func enableCachingForStaticFiles() gin.HandlerFunc {
|
||||||
|
@ -50,7 +50,7 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
// if !transactionUUID.Valid {
|
// if !transactionUUID.Valid {
|
||||||
new := postgres.CreateTransactionParams{
|
newTransaction := postgres.CreateTransactionParams{
|
||||||
Memo: payload.Memo,
|
Memo: payload.Memo,
|
||||||
Date: time.Time(payload.Date),
|
Date: time.Time(payload.Date),
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
@ -59,7 +59,7 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
CategoryID: payload.Category.ID, // TODO handle new category
|
CategoryID: payload.Category.ID, // TODO handle new category
|
||||||
Status: postgres.TransactionStatus(payload.State),
|
Status: postgres.TransactionStatus(payload.State),
|
||||||
}
|
}
|
||||||
_, err = h.Service.CreateTransaction(c.Request.Context(), new)
|
_, err = h.Service.CreateTransaction(c.Request.Context(), newTransaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user