Rename 'backend' module to 'database'

This commit is contained in:
Ivan R. 2023-07-22 15:24:01 +05:00
parent 3c9e30375e
commit de76c90f3c
No known key found for this signature in database
GPG key ID: 56C7BAAE859B302C
10 changed files with 23 additions and 23 deletions

View file

@ -1,4 +1,4 @@
package backend package database
import ( import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"

View file

@ -1,4 +1,4 @@
package backend package database
import ( import (
"github.com/ordinary-dev/phoenix/config" "github.com/ordinary-dev/phoenix/config"

View file

@ -1,4 +1,4 @@
package backend package database
type Group struct { type Group struct {
ID uint64 `gorm:"primaryKey"` ID uint64 `gorm:"primaryKey"`

View file

@ -1,4 +1,4 @@
package backend package database
type Link struct { type Link struct {
ID uint64 `gorm:"primaryKey"` ID uint64 `gorm:"primaryKey"`

View file

@ -1,8 +1,8 @@
package main package main
import ( import (
"github.com/ordinary-dev/phoenix/backend"
"github.com/ordinary-dev/phoenix/config" "github.com/ordinary-dev/phoenix/config"
"github.com/ordinary-dev/phoenix/database"
"github.com/ordinary-dev/phoenix/views" "github.com/ordinary-dev/phoenix/views"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -25,7 +25,7 @@ func main() {
logrus.Infof("Setting log level to %v", logLevel) logrus.Infof("Setting log level to %v", logLevel)
// Connect to the database // Connect to the database
db, err := backend.GetDatabaseConnection(cfg) db, err := database.GetDatabaseConnection(cfg)
if err != nil { if err != nil {
logrus.Fatalf("%v", err) logrus.Fatalf("%v", err)
} }

View file

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v5" "github.com/golang-jwt/jwt/v5"
"github.com/ordinary-dev/phoenix/backend"
"github.com/ordinary-dev/phoenix/config" "github.com/ordinary-dev/phoenix/config"
"github.com/ordinary-dev/phoenix/database"
"gorm.io/gorm" "gorm.io/gorm"
"net/http" "net/http"
"time" "time"
@ -92,7 +92,7 @@ func CreateUser(c *gin.Context, db *gorm.DB, cfg *config.Config) {
// Try to create a user. // Try to create a user.
username := c.PostForm("username") username := c.PostForm("username")
password := c.PostForm("password") password := c.PostForm("password")
_, err := backend.CreateAdmin(db, username, password) _, err := database.CreateAdmin(db, username, password)
if err != nil { if err != nil {
ShowError(c, err) ShowError(c, err)
return return
@ -114,7 +114,7 @@ func AuthorizeUser(c *gin.Context, db *gorm.DB, cfg *config.Config) {
// Check credentials. // Check credentials.
username := c.PostForm("username") username := c.PostForm("username")
password := c.PostForm("password") password := c.PostForm("password")
_, err := backend.AuthorizeAdmin(db, username, password) _, err := database.AuthorizeAdmin(db, username, password)
if err != nil { if err != nil {
ShowError(c, err) ShowError(c, err)
return return

View file

@ -2,7 +2,7 @@ package views
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/ordinary-dev/phoenix/backend" "github.com/ordinary-dev/phoenix/database"
"gorm.io/gorm" "gorm.io/gorm"
"net/http" "net/http"
"strconv" "strconv"
@ -10,7 +10,7 @@ import (
func CreateGroup(c *gin.Context, db *gorm.DB) { func CreateGroup(c *gin.Context, db *gorm.DB) {
// Save new group to the database. // Save new group to the database.
group := backend.Group{ group := database.Group{
Name: c.PostForm("groupName"), Name: c.PostForm("groupName"),
} }
if result := db.Create(&group); result.Error != nil { if result := db.Create(&group); result.Error != nil {
@ -29,7 +29,7 @@ func UpdateGroup(c *gin.Context, db *gorm.DB) {
return return
} }
var group backend.Group var group database.Group
if result := db.First(&group, id); result.Error != nil { if result := db.First(&group, id); result.Error != nil {
ShowError(c, result.Error) ShowError(c, result.Error)
return return
@ -52,7 +52,7 @@ func DeleteGroup(c *gin.Context, db *gorm.DB) {
return return
} }
if result := db.Delete(&backend.Group{}, id); result.Error != nil { if result := db.Delete(&database.Group{}, id); result.Error != nil {
ShowError(c, result.Error) ShowError(c, result.Error)
return return
} }

View file

@ -2,16 +2,16 @@ package views
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/ordinary-dev/phoenix/backend" "github.com/ordinary-dev/phoenix/database"
"gorm.io/gorm" "gorm.io/gorm"
"net/http" "net/http"
) )
func ShowMainPage(c *gin.Context, db *gorm.DB) { func ShowMainPage(c *gin.Context, db *gorm.DB) {
// Get a list of groups with links // Get a list of groups with links
var groups []backend.Group var groups []database.Group
result := db. result := db.
Model(&backend.Group{}). Model(&database.Group{}).
Preload("Links"). Preload("Links").
Find(&groups) Find(&groups)

View file

@ -2,7 +2,7 @@ package views
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/ordinary-dev/phoenix/backend" "github.com/ordinary-dev/phoenix/database"
"gorm.io/gorm" "gorm.io/gorm"
"net/http" "net/http"
"strconv" "strconv"
@ -15,7 +15,7 @@ func CreateLink(c *gin.Context, db *gorm.DB) {
return return
} }
link := backend.Link{ link := database.Link{
Name: c.PostForm("linkName"), Name: c.PostForm("linkName"),
Href: c.PostForm("href"), Href: c.PostForm("href"),
GroupID: groupID, GroupID: groupID,
@ -36,7 +36,7 @@ func UpdateLink(c *gin.Context, db *gorm.DB) {
return return
} }
var link backend.Link var link database.Link
if result := db.First(&link, id); result.Error != nil { if result := db.First(&link, id); result.Error != nil {
ShowError(c, err) ShowError(c, err)
return return
@ -60,7 +60,7 @@ func DeleteLink(c *gin.Context, db *gorm.DB) {
return return
} }
if result := db.Delete(&backend.Link{}, id); result.Error != nil { if result := db.Delete(&database.Link{}, id); result.Error != nil {
ShowError(c, result.Error) ShowError(c, result.Error)
return return
} }

View file

@ -2,16 +2,16 @@ package views
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/ordinary-dev/phoenix/backend" "github.com/ordinary-dev/phoenix/database"
"gorm.io/gorm" "gorm.io/gorm"
"net/http" "net/http"
) )
func ShowSettings(c *gin.Context, db *gorm.DB) { func ShowSettings(c *gin.Context, db *gorm.DB) {
// Get a list of groups with links // Get a list of groups with links
var groups []backend.Group var groups []database.Group
result := db. result := db.
Model(&backend.Group{}). Model(&database.Group{}).
Preload("Links"). Preload("Links").
Find(&groups) Find(&groups)