DB & Route Organization
This commit is contained in:
81
cmd/cmd.go
81
cmd/cmd.go
@@ -1,14 +1,17 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
// "reichard.io/imagini/routes"
|
||||
"fmt"
|
||||
"errors"
|
||||
"reichard.io/imagini/routes"
|
||||
"reichard.io/imagini/internal/db"
|
||||
"reichard.io/imagini/internal/auth"
|
||||
"reichard.io/imagini/internal/models"
|
||||
"reichard.io/imagini/internal/config"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
// "net/http"
|
||||
// "log"
|
||||
"fmt"
|
||||
"net/http"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var CmdServe = cli.Command{
|
||||
@@ -19,32 +22,66 @@ var CmdServe = cli.Command{
|
||||
}
|
||||
|
||||
var CmdDBTest = cli.Command{
|
||||
Name: "db",
|
||||
Aliases: []string{"d"},
|
||||
Name: "test",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "test db.",
|
||||
Action: testDatabase,
|
||||
}
|
||||
|
||||
func serveWeb(ctx *cli.Context) error {
|
||||
c := config.NewConfig()
|
||||
db.ConnectDB(c)
|
||||
//db.PopulateTestData()
|
||||
newItems := db.ItemsFromAlbum(1, 2)
|
||||
|
||||
fmt.Printf("%+v\n", newItems)
|
||||
log.Info("Serving Web")
|
||||
routes.RegisterRoutes()
|
||||
if err := http.ListenAndServe(":8080", nil); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return nil
|
||||
|
||||
|
||||
// routes.RegisterRoutes()
|
||||
|
||||
// if err := http.ListenAndServe(":8080", nil); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// return nil
|
||||
}
|
||||
|
||||
func testDatabase(ctx *cli.Context) error {
|
||||
resp := db.ItemsFromAlbum(1, 3)
|
||||
fmt.Printf("%v", resp)
|
||||
log.Info("Testing Database")
|
||||
c := config.NewConfig()
|
||||
db.ConnectDB(c)
|
||||
|
||||
err := auth.CreateUser(models.User{
|
||||
Username: "User12346",
|
||||
Email: "user26@evan.pub",
|
||||
FirstName: "User",
|
||||
LastName: "Reichard",
|
||||
AuthType: "Local",
|
||||
}, "myPassword123")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
resp := auth.AuthenticateUser("User123", "myPassword123")
|
||||
if resp == true {
|
||||
log.Info("USER SUCCESSFULLY AUTHENTICATED BY USERNAME")
|
||||
}else {
|
||||
log.Info("USER NOT AUTHENTICATED")
|
||||
}
|
||||
|
||||
resp = auth.AuthenticateUser("user@evan.pub", "myPassword123")
|
||||
if resp == true {
|
||||
log.Info("USER SUCCESSFULLY AUTHENTICATED BY EMAIL")
|
||||
}else {
|
||||
log.Info("USER NOT AUTHENTICATED")
|
||||
}
|
||||
|
||||
resp = auth.AuthenticateUser("user@evan.pub", "myPassword12")
|
||||
if resp == true {
|
||||
log.Info("USER SUCCESSFULLY AUTHENTICATED BY EMAIL")
|
||||
}else {
|
||||
log.Info("USER NOT AUTHENTICATED")
|
||||
}
|
||||
|
||||
// foundUser, err := db.GetUser(db.User{Username: "User123"})
|
||||
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// log.Warn("RECORD NOT FOUND")
|
||||
// } else {
|
||||
// log.Info("FOUND USER", foundUser)
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user