Skip to content

Commit

Permalink
add models
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyKomarovCoder committed Sep 27, 2023
1 parent d5bacf1 commit 9c0d2ff
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/models/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package models

import "github.com/google/uuid"

type Accounts struct {
ID uuid.UUID `json:"id"`
UserID uint `json:"user_id"`
Balance float64 `json:"balance"`
MeanPayment string `json:"mean_payment"`
}
17 changes: 17 additions & 0 deletions internal/models/category.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package models

import (
valid "github.com/asaskevich/govalidator"
"github.com/google/uuid"
)

type Category struct {
ID uuid.UUID `json:"id" valid:"-"`
UserID uint `json:"user_id" valid:"-"`
Name string `json:"name" valid:"required"`
}

func (c *Category) CategoryValidate() error {
_, err := valid.ValidateStruct(c)
return err
}
26 changes: 26 additions & 0 deletions internal/models/credit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package models

import (
"time"

valid "github.com/asaskevich/govalidator"
"github.com/google/uuid"
)

type Credit struct {
ID uuid.UUID `json:"id" valid:"-"`
AccountID uint `json:"account_id" valid:"-"`
Total float64 `json:"total" valid:"required,greaterzero"`
DateStart time.Time `json:"date_start" valid:"isdate"`
DateEnd time.Time `json:"date_end" valid:"isdate"`
IsAnnuity bool `json:"is_annuity" valid:"required"`
Creditor string `json:"creditor" valid:"-"`
Description string `json:"description" valid:"-"`
Payments int `json:"payments" valid:"-"`
Bank string `json:"bank" valid:"-"`
}

func (c *Credit) CreditValidate() error {
_, err := valid.ValidateStruct(c)
return err
}
22 changes: 22 additions & 0 deletions internal/models/debt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package models

import (
"time"

valid "github.com/asaskevich/govalidator"
"github.com/google/uuid"
)

type Debt struct {
ID uuid.UUID `json:"id" valid:"-"`
UserID uint `json:"user_id" valid:"-"`
Total float64 `json:"total" valid:"required,greaterzero"`
Date time.Time `json:"date" valid:"isdate"`
Creditor string `json:"creditor"`
Description string `json:"description" valid:"-"`
}

func (d *Debt) DebtValidate() error {
_, err := valid.ValidateStruct(d)
return err
}
23 changes: 23 additions & 0 deletions internal/models/deposit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package models

import (
"time"

valid "github.com/asaskevich/govalidator"
"github.com/google/uuid"
)

type deposit struct {
ID uuid.UUID `json:"id" valid:"-"`
AccountID uint `json:"account_id" valid:"-"`
Total float64 `json:"total" valid:"required,greaterzero"`
DateStart time.Time `json:"date_start" valid:"isdate"`
DateEnd time.Time `json:"date_end" valid:"isdate"`
InterestRate float64 `json:"interest_rate" valid:"required"`
Bank string `json:"bank"`
}

func (g *Goal) GoalValidate() error {
_, err := valid.ValidateStruct(g)
return err
}
22 changes: 22 additions & 0 deletions internal/models/goal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package models

import (
"time"

valid "github.com/asaskevich/govalidator"
"github.com/google/uuid"
)

type Goal struct {
ID uuid.UUID `json:"id" valid:"-"`
UserID uint `json:"user_id" valid:"-"`
Name string `json:"name" valid:"required"`
Description string `json:"description" valid:"-"`
Total float64 `json:"total" valid:"required,greaterzero"`
Date time.Time `json:"date" valid:"isdate"`
}

func (g *Goal) GoalValidate() error {
_, err := valid.ValidateStruct(g)
return err
}
24 changes: 24 additions & 0 deletions internal/models/investmet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package models

import (
"time"

valid "github.com/asaskevich/govalidator"
"github.com/google/uuid"
)

type Investment struct {
ID uuid.UUID `json:"id" valid:"-"`
UserID uint `json:"user_id" valid:"-"`
Name string `json:"name" valid:"required"`
Total float64 `json:"total" valid:"required,greaterzero"`
DateStart time.Time `json:"date_start" valid:"isdate"`
DateEnd time.Time `json:"date_end" valid:"isdate"`
Price float64 `json:"price" valid:"required"`
Percentage float64 `json:"percentage" valid:"required"`
}

func (i *Investment) InvestmentValidate() error {
_, err := valid.ValidateStruct(i)
return err
}
25 changes: 25 additions & 0 deletions internal/models/transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package models

import (
"time"

valid "github.com/asaskevich/govalidator"
"github.com/google/uuid"
)

type Transaction struct {
ID uuid.UUID `json:"id" valid:"-"`
UserID uint `json:"user_id" valid:"-"`
CategoryID uint `json:"category_id" valid:"-"`
AccountID uint `json:"account_id" valid:"-"`
Total float64 `json:"total" valid:"required,greaterzero"`
IsIncome bool `json:"is_income" valid:"required"`
Date time.Time `json:"date" valid:"isdate"`
Payer string `json:"payer" valid:"payer"`
Description string `json:"description" valid:"-"`
}

func (t *Transaction) TransactionValidate() error {
_, err := valid.ValidateStruct(t)
return err
}
30 changes: 30 additions & 0 deletions internal/models/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package models

import (
valid "github.com/asaskevich/govalidator"
"github.com/google/uuid"
)

type Sex string

const (
Male Sex = "M"
Female Sex = "F"
Other Sex = "O" // :-)
)

type User struct {
ID uuid.UUID `json:"id" valid:"-"`
Username string `json:"name" valid:"-"`
Email string `json:"email" valid:"required,email"`
FirstName string `json:"firstName" valid:"required,runelength(2|20)"`
LastName string `json:"lastName" valid:"required,runelength(2|20)"`
Password string `json:"password" valid:"required,runelength(7|30),passwordcheck"`
Sex Sex `json:"sex" valid:"required,in(F|M|O)"`
AvatarURL string `json:"avatar_url" vaild:"-"`
}

func (u *User) UserValidate() error {
_, err := valid.ValidateStruct(u)
return err
}
1 change: 1 addition & 0 deletions internal/models/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TO DO isdate, greaterzero, passwordcheck

0 comments on commit 9c0d2ff

Please sign in to comment.