added documentation comments to methods

This commit is contained in:
Fran Jurmanovic
2021-08-02 10:19:58 -07:00
parent 05a13112f1
commit 0195528428
31 changed files with 175 additions and 33 deletions

View File

@@ -2,13 +2,15 @@ package migrate
import (
"fmt"
"github.com/go-pg/pg/v10"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
// Creates api table if it does not exist.
func CreateTableApi(db pg.DB) error {
models := []interface{}{
@@ -20,10 +22,10 @@ func CreateTableApi(db pg.DB) error {
IfNotExists: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
log.Printf("Error creating table \"api\": %s", err)
return err
} else {
fmt.Println("Table created successfully")
fmt.Println("Table \"api\" created successfully")
}
}
return nil

View File

@@ -2,14 +2,15 @@ package migrate
import (
"fmt"
"github.com/go-pg/pg/v10"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
// Creates api users if it does not exist.
func CreateTableUsers(db pg.DB) error {
models := []interface{}{
(*models.User)(nil),
@@ -20,10 +21,10 @@ func CreateTableUsers(db pg.DB) error {
IfNotExists: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
log.Printf("Error creating table \"users\": %s", err)
return err
} else {
fmt.Println("Table created successfully")
fmt.Println("Table \"users\" created successfully")
}
}
return nil

View File

@@ -2,13 +2,15 @@ package migrate
import (
"fmt"
"github.com/go-pg/pg/v10"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
// Creates wallets table if it does not exist.
func CreateTableWallets(db pg.DB) error {
models := []interface{}{
(*models.Wallet)(nil),
@@ -20,10 +22,10 @@ func CreateTableWallets(db pg.DB) error {
FKConstraints: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
log.Printf("Error creating table \"wallets\": %s", err)
return err
} else {
fmt.Println("Table created successfully")
fmt.Println("Table \"wallets\" created successfully")
}
}
return nil

View File

@@ -2,13 +2,15 @@ package migrate
import (
"fmt"
"github.com/go-pg/pg/v10"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
// Creates transactionTypes table if it does not exist.
func CreateTableTransactionTypes(db pg.DB) error {
models := []interface{}{
(*models.TransactionType)(nil),
@@ -20,10 +22,10 @@ func CreateTableTransactionTypes(db pg.DB) error {
FKConstraints: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
log.Printf("Error creating table \"api\": %s", err)
return err
} else {
fmt.Println("Table created successfully")
fmt.Println("Table \"api\" created successfully")
}
}
return nil

View File

@@ -2,14 +2,15 @@ package migrate
import (
"fmt"
"github.com/go-pg/pg/v10"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
// Creates api transactions if it does not exist.
func CreateTableTransactions(db pg.DB) error {
models := []interface{}{
(*models.Transaction)(nil),
@@ -21,10 +22,10 @@ func CreateTableTransactions(db pg.DB) error {
FKConstraints: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
log.Printf("Error creating table \"transactions\": %s", err)
return err
} else {
fmt.Println("Table created successfully")
fmt.Println("Table \"transactions\" created successfully")
}
}
return nil

View File

@@ -2,13 +2,15 @@ package migrate
import (
"fmt"
"github.com/go-pg/pg/v10"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
// Creates subscriptionTypes table if it does not exist.
func CreateTableSubscriptionTypes(db pg.DB) error {
models := []interface{}{
(*models.SubscriptionType)(nil),
@@ -20,10 +22,10 @@ func CreateTableSubscriptionTypes(db pg.DB) error {
FKConstraints: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
log.Printf("Error creating table \"subscriptionTypes\": %s", err)
return err
} else {
fmt.Println("Table created successfully")
fmt.Println("Table \"subscriptionTypes\" created successfully")
}
}
return nil

View File

@@ -2,12 +2,14 @@ package migrate
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
// Creates subscriptions table if it does not exist.
func CreateTableSubscriptions(db pg.DB) error {
models := []interface{}{
(*models.Subscription)(nil),
@@ -19,10 +21,10 @@ func CreateTableSubscriptions(db pg.DB) error {
FKConstraints: true,
})
if err != nil {
log.Printf("Error Creating Table: %s", err)
log.Printf("Error creating table \"subscriptions\": %s", err)
return err
} else {
fmt.Println("Table created successfully")
fmt.Println("Table \"subscriptions\" created successfully")
}
}
return nil

View File

@@ -1,10 +1,14 @@
package migrate
import (
"github.com/go-pg/pg/v10"
"fmt"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
)
// Populates subscriptionTypes table if it does not exist.
func PopulateSubscriptionTypes(db pg.DB) error {
daily := new(models.SubscriptionType)
weekly := new(models.SubscriptionType)
@@ -28,12 +32,35 @@ func PopulateSubscriptionTypes(db pg.DB) error {
yearly.Type = "yearly"
_, err := db.Model(daily).Where("? = ?", pg.Ident("type"), daily.Type).SelectOrInsert()
if err != nil {
log.Printf("Error inserting row into \"subscriptionTypes\" table: %s", err)
return err
} else {
fmt.Println("Row inserted successfully into \"subscriptionTypes\" table.")
}
_, err = db.Model(weekly).Where("? = ?", pg.Ident("type"), weekly.Type).SelectOrInsert()
if err != nil {
log.Printf("Error inserting row into \"subscriptionTypes\" table: %s", err)
return err
} else {
fmt.Println("Row inserted successfully into \"subscriptionTypes\" table.")
}
_, err = db.Model(monthly).Where("? = ?", pg.Ident("type"), monthly.Type).SelectOrInsert()
if err != nil {
log.Printf("Error inserting row into \"subscriptionTypes\" table: %s", err)
return err
} else {
fmt.Println("Row inserted successfully into \"subscriptionTypes\" table.")
}
_, err = db.Model(yearly).Where("? = ?", pg.Ident("type"), yearly.Type).SelectOrInsert()
if err != nil {
log.Printf("Error inserting row into \"subscriptionTypes\" table: %s", err)
return err
} else {
fmt.Println("Row inserted successfully into \"subscriptionTypes\" table.")
}
return err
}

View File

@@ -1,10 +1,14 @@
package migrate
import (
"github.com/go-pg/pg/v10"
"fmt"
"log"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
)
// Populates transactionTypes table if it does not exist.
func PopulateTransactionTypes(db pg.DB) error {
gain := new(models.TransactionType)
expense := new(models.TransactionType)
@@ -18,8 +22,20 @@ func PopulateTransactionTypes(db pg.DB) error {
expense.Type = "expense"
_, err := db.Model(gain).Where("? = ?", pg.Ident("type"), gain.Type).SelectOrInsert()
if err != nil {
log.Printf("Error inserting row into \"transactionTypes\" table: %s", err)
return err
} else {
fmt.Println("Row inserted successfully into \"transactionTypes\" table.")
}
_, err = db.Model(expense).Where("? = ?", pg.Ident("type"), expense.Type).SelectOrInsert()
if err != nil {
log.Printf("Error inserting row into \"transactionTypes\" table: %s", err)
return err
} else {
fmt.Println("Row inserted successfully into \"transactionTypes\" table.")
}
return err
}

View File

@@ -4,6 +4,7 @@ import (
"github.com/go-pg/pg/v10"
)
// Starts database migration.
func Start(conn *pg.DB, version string) {
migration001 := Migration{
Version: "001",
@@ -43,7 +44,6 @@ func Start(conn *pg.DB, version string) {
}
type Migration struct {
Version string
Version string
Migrations []interface{}
}