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 (
"golang.org/x/crypto/bcrypt"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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