diff --git a/internal/models/account.go b/internal/models/account.go new file mode 100644 index 00000000..d66ccea8 --- /dev/null +++ b/internal/models/account.go @@ -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"` +} diff --git a/internal/models/category.go b/internal/models/category.go new file mode 100644 index 00000000..22270d8b --- /dev/null +++ b/internal/models/category.go @@ -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 +} diff --git a/internal/models/credit.go b/internal/models/credit.go new file mode 100644 index 00000000..1e2ff3b9 --- /dev/null +++ b/internal/models/credit.go @@ -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 +} diff --git a/internal/models/debt.go b/internal/models/debt.go new file mode 100644 index 00000000..6c281db4 --- /dev/null +++ b/internal/models/debt.go @@ -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 +} diff --git a/internal/models/deposit.go b/internal/models/deposit.go new file mode 100644 index 00000000..026cbb99 --- /dev/null +++ b/internal/models/deposit.go @@ -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 +} diff --git a/internal/models/goal.go b/internal/models/goal.go new file mode 100644 index 00000000..bbb03f78 --- /dev/null +++ b/internal/models/goal.go @@ -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 +} diff --git a/internal/models/investmet.go b/internal/models/investmet.go new file mode 100644 index 00000000..52eb1bd1 --- /dev/null +++ b/internal/models/investmet.go @@ -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 +} diff --git a/internal/models/transaction.go b/internal/models/transaction.go new file mode 100644 index 00000000..7aa95c8c --- /dev/null +++ b/internal/models/transaction.go @@ -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 +} diff --git a/internal/models/user.go b/internal/models/user.go new file mode 100644 index 00000000..b1ee7657 --- /dev/null +++ b/internal/models/user.go @@ -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 +} diff --git a/internal/models/validate.go b/internal/models/validate.go new file mode 100644 index 00000000..d7bae4d4 --- /dev/null +++ b/internal/models/validate.go @@ -0,0 +1 @@ +// TO DO isdate, greaterzero, passwordcheck \ No newline at end of file