Refactored code into modules per database model.
This commit is contained in:
		
							parent
							
								
									06cb11ed8c
								
							
						
					
					
						commit
						767499a9ed
					
				
					 50 changed files with 1165 additions and 781 deletions
				
			
		| 
						 | 
				
			
			@ -1,8 +1,6 @@
 | 
			
		|||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	api "example.com/api"
 | 
			
		||||
	authdiscord "example.com/auth/discord"
 | 
			
		||||
	databasecommands "example.com/database/commands"
 | 
			
		||||
| 
						 | 
				
			
			@ -12,8 +10,8 @@ import (
 | 
			
		|||
 | 
			
		||||
func main() {
 | 
			
		||||
	api.GlobalDatabase = databasecommands.InitializeDatabase()
 | 
			
		||||
	api.GlobalConfig.ParseConfig("../config.toml")
 | 
			
		||||
	api.GlobalOAuth = authdiscord.CreateDiscordOAuthConfig(api.GlobalConfig)
 | 
			
		||||
	log.Println(api.GlobalConfig)
 | 
			
		||||
	app := gin.Default()
 | 
			
		||||
	// Authentication Workflow
 | 
			
		||||
	app.GET("/auth/callback", api.AuthCallback)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										47
									
								
								src/go.mod
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								src/go.mod
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -4,22 +4,34 @@ go 1.24.2
 | 
			
		|||
 | 
			
		||||
replace example.com/database/commands => ./lib/database/commands
 | 
			
		||||
 | 
			
		||||
replace example.com/database/user => ./lib/database/user
 | 
			
		||||
 | 
			
		||||
replace example.com/database/character => ./lib/database/character
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functionset => ./lib/database/functionset
 | 
			
		||||
 | 
			
		||||
replace example.com/database/inventoryslot => ./lib/database/inventoryslot
 | 
			
		||||
 | 
			
		||||
replace example.com/database/customization => ./lib/database/customization
 | 
			
		||||
 | 
			
		||||
replace example.com/database/item => ./lib/database/item
 | 
			
		||||
 | 
			
		||||
replace example.com/database/itemtag => ./lib/database/itemtag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/person => ./lib/database/person
 | 
			
		||||
 | 
			
		||||
replace example.com/database/role => ./lib/database/role
 | 
			
		||||
 | 
			
		||||
replace example.com/database/schematic => ./lib/database/schematic
 | 
			
		||||
 | 
			
		||||
replace example.com/database/tier => ./lib/database/tier
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ./lib/database/group
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ./lib/database/function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ./lib/database/functiontag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/commands/create => ./lib/database/commands/create
 | 
			
		||||
 | 
			
		||||
replace example.com/database/commands/get => ./lib/database/commands/get
 | 
			
		||||
 | 
			
		||||
replace example.com/database/commands/update => ./lib/database/commands/update
 | 
			
		||||
 | 
			
		||||
replace example.com/database/commands/delete => ./lib/database/commands/delete
 | 
			
		||||
 | 
			
		||||
replace example.com/database/models => ./lib/database/models
 | 
			
		||||
 | 
			
		||||
replace example.com/config/server => ./lib/config/server
 | 
			
		||||
 | 
			
		||||
replace example.com/auth/discord => ./lib/auth/discord
 | 
			
		||||
| 
						 | 
				
			
			@ -35,13 +47,20 @@ require (
 | 
			
		|||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/config/server v0.0.0 // indirect
 | 
			
		||||
	example.com/database/commands/create v0.0.0 // indirect
 | 
			
		||||
	example.com/database/commands/get v0.0.0 // indirect
 | 
			
		||||
	example.com/database/commands/update v0.0.0 // indirect
 | 
			
		||||
	example.com/database/character v0.0.0 // indirect
 | 
			
		||||
	example.com/database/customization v0.0.0 // indirect
 | 
			
		||||
	example.com/database/function v0.0.0 // indirect
 | 
			
		||||
	example.com/database/functionset v0.0.0 // indirect
 | 
			
		||||
	example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/group v0.0.0 // indirect
 | 
			
		||||
	example.com/database/models v0.0.0 // indirect
 | 
			
		||||
	example.com/database/inventoryslot v0.0.0 // indirect
 | 
			
		||||
	example.com/database/item v0.0.0 // indirect
 | 
			
		||||
	example.com/database/itemtag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/person v0.0.0 // indirect
 | 
			
		||||
	example.com/database/role v0.0.0 // indirect
 | 
			
		||||
	example.com/database/schematic v0.0.0 // indirect
 | 
			
		||||
	example.com/database/tier v0.0.0 // indirect
 | 
			
		||||
	example.com/database/user v0.0.0 // indirect
 | 
			
		||||
	github.com/bytedance/sonic v1.11.6 // indirect
 | 
			
		||||
	github.com/bytedance/sonic/loader v0.1.1 // indirect
 | 
			
		||||
	github.com/cloudwego/base64x v0.1.4 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,13 +9,10 @@ import (
 | 
			
		|||
	authdiscord "example.com/auth/discord"
 | 
			
		||||
	configserver "example.com/config/server"
 | 
			
		||||
	databasecommands "example.com/database/commands"
 | 
			
		||||
	create "example.com/database/commands/create"
 | 
			
		||||
	get "example.com/database/commands/get"
 | 
			
		||||
	update "example.com/database/commands/update"
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
	functiontag "example.com/database/functiontag"
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	databasemodels "example.com/database/models"
 | 
			
		||||
	user "example.com/database/user"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"github.com/xyproto/randomstring"
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +44,6 @@ func AuthCallback(context *gin.Context) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func AuthLoginRedirect(context *gin.Context) {
 | 
			
		||||
	log.Println(GlobalOAuth.AuthCodeURL(context.GetString("state")))
 | 
			
		||||
	context.Redirect(302, GlobalOAuth.AuthCodeURL(context.GetString("state")))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -82,7 +78,7 @@ func CreateOrUpdateUser(context *gin.Context) {
 | 
			
		|||
	}
 | 
			
		||||
	var currentDiscordUser authdiscord.DiscordUser
 | 
			
		||||
	currentDiscordUser.GetDiscordUser(context, oauthToken, GlobalConfig, GlobalOAuth)
 | 
			
		||||
	updatedDatabaseUser := databasemodels.User{
 | 
			
		||||
	updatedDatabaseUser := user.User{
 | 
			
		||||
		DisplayName:      currentDiscordUser.Global_Name,
 | 
			
		||||
		Username:         currentDiscordUser.Username,
 | 
			
		||||
		Id:               currentDiscordUser.Id,
 | 
			
		||||
| 
						 | 
				
			
			@ -92,21 +88,21 @@ func CreateOrUpdateUser(context *gin.Context) {
 | 
			
		|||
		LoggedIn:         true,
 | 
			
		||||
		ApiKey:           nil,
 | 
			
		||||
	}
 | 
			
		||||
	if get.GetDatabaseUserExists(GlobalDatabase, currentDiscordUser.Id) {
 | 
			
		||||
		dbOAuthToken := get.GetDatabaseUserToken(GlobalDatabase, currentDiscordUser.Id)
 | 
			
		||||
		if get.GetDatabaseUserLoggedInFromDiscordId(GlobalDatabase, currentDiscordUser.Id) {
 | 
			
		||||
	if user.Exists(GlobalDatabase, currentDiscordUser.Id) {
 | 
			
		||||
		dbOAuthToken := user.GetTokenFromUserId(GlobalDatabase, currentDiscordUser.Id)
 | 
			
		||||
		if user.GetLoggedInFromDiscordId(GlobalDatabase, currentDiscordUser.Id) {
 | 
			
		||||
			context.SetCookie("discord-oauthtoken", dbOAuthToken, 0, "", GlobalConfig.API.Domain, false, false)
 | 
			
		||||
			updatedDatabaseUser.LoginToken = string(dbOAuthToken)
 | 
			
		||||
		} else {
 | 
			
		||||
			context.SetCookie("discord-oauthtoken", string(oauthTokenJSON), 0, "", GlobalConfig.API.Domain, false, false)
 | 
			
		||||
		}
 | 
			
		||||
		err := update.UpdateDatabaseUser(GlobalDatabase, updatedDatabaseUser)
 | 
			
		||||
		err := updatedDatabaseUser.Update(GlobalDatabase)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Println(err)
 | 
			
		||||
			context.AbortWithStatus(http.StatusInternalServerError)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		err := create.CreateDatabaseUser(GlobalDatabase, updatedDatabaseUser)
 | 
			
		||||
		err := updatedDatabaseUser.Create(GlobalDatabase)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Println(err)
 | 
			
		||||
			context.Copy().AbortWithStatus(http.StatusInternalServerError)
 | 
			
		||||
| 
						 | 
				
			
			@ -138,19 +134,18 @@ func CreateDatabaseFunction(context *gin.Context) {
 | 
			
		|||
		tags, tagsOk := context.GetQueryArray("tags")
 | 
			
		||||
		requirements, requirementsOk := context.GetQueryArray("requirements")
 | 
			
		||||
		if nameOk {
 | 
			
		||||
			var newTags *[]functiontag.FunctionTag
 | 
			
		||||
			var newRequirements *[]function.Function
 | 
			
		||||
			var newTags []functiontag.FunctionTag
 | 
			
		||||
			var newRequirements []function.Function
 | 
			
		||||
			if tagsOk {
 | 
			
		||||
				newTags = functiontag.Get(GlobalDatabase, tags)
 | 
			
		||||
				newTags = *functiontag.Get(GlobalDatabase, tags)
 | 
			
		||||
			}
 | 
			
		||||
			if requirementsOk {
 | 
			
		||||
				newRequirements = function.Get(GlobalDatabase, requirements)
 | 
			
		||||
				newRequirements = *function.Get(GlobalDatabase, requirements)
 | 
			
		||||
			}
 | 
			
		||||
			log.Printf("OKAY\nName: %s\nTags: %v\nRequirements: %v", name, *newTags, *newRequirements)
 | 
			
		||||
			function.Function{
 | 
			
		||||
				Name:         name,
 | 
			
		||||
				Tags:         *newTags,
 | 
			
		||||
				Requirements: *newRequirements,
 | 
			
		||||
				Tags:         newTags,
 | 
			
		||||
				Requirements: newRequirements,
 | 
			
		||||
			}.Create(GlobalDatabase)
 | 
			
		||||
			context.Status(http.StatusOK)
 | 
			
		||||
		} else {
 | 
			
		||||
| 
						 | 
				
			
			@ -164,7 +159,6 @@ func CreateDatabaseFunction(context *gin.Context) {
 | 
			
		|||
func CreateDatabaseFunctionTag(context *gin.Context) {
 | 
			
		||||
	GetIsUserAuthorized(context)
 | 
			
		||||
	isAuthorized := context.GetBool("is-authorized")
 | 
			
		||||
	log.Println(isAuthorized)
 | 
			
		||||
	if isAuthorized {
 | 
			
		||||
		name := context.Query("name")
 | 
			
		||||
		if name != "" {
 | 
			
		||||
| 
						 | 
				
			
			@ -189,10 +183,10 @@ func GetUserInfo(context *gin.Context) {
 | 
			
		|||
		err := json.Unmarshal([]byte(oauthTokenJSON), &oauthToken)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			if oauthToken.Valid() {
 | 
			
		||||
				var user authdiscord.DiscordUser
 | 
			
		||||
				user.GetDiscordUser(context, oauthToken, GlobalConfig, GlobalOAuth)
 | 
			
		||||
				if get.GetDatabaseUserLoggedInFromDiscordId(GlobalDatabase, user.Id) {
 | 
			
		||||
					context.JSON(http.StatusOK, user)
 | 
			
		||||
				var discordUser authdiscord.DiscordUser
 | 
			
		||||
				discordUser.GetDiscordUser(context, oauthToken, GlobalConfig, GlobalOAuth)
 | 
			
		||||
				if user.GetLoggedInFromDiscordId(GlobalDatabase, discordUser.Id) {
 | 
			
		||||
					context.JSON(http.StatusOK, discordUser)
 | 
			
		||||
				} else {
 | 
			
		||||
					context.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%slogout", GlobalConfig.GetAPIRootDomain()))
 | 
			
		||||
				}
 | 
			
		||||
| 
						 | 
				
			
			@ -219,7 +213,7 @@ func GetIsUserAuthorized(context *gin.Context) {
 | 
			
		|||
		err := json.Unmarshal([]byte(oauthTokenJSON), &oauthToken)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			if oauthToken.Valid() {
 | 
			
		||||
				if get.GetDatabaseUserLoggedIn(GlobalDatabase, oauthTokenJSON) {
 | 
			
		||||
				if user.GetLoggedInFromOAuthToken(GlobalDatabase, oauthTokenJSON) {
 | 
			
		||||
					context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
						"message": true,
 | 
			
		||||
					})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,22 +2,36 @@ module example.com/api
 | 
			
		|||
 | 
			
		||||
replace example.com/database/commands => ../database/commands
 | 
			
		||||
 | 
			
		||||
replace example.com/database/user => ../database/user
 | 
			
		||||
 | 
			
		||||
replace example.com/database/character => ../database/character
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functionset => ../database/functionset
 | 
			
		||||
 | 
			
		||||
replace example.com/database/inventoryslot => ../database/inventoryslot
 | 
			
		||||
 | 
			
		||||
replace example.com/database/customization => ../database/customization
 | 
			
		||||
 | 
			
		||||
replace example.com/database/item => ../database/item
 | 
			
		||||
 | 
			
		||||
replace example.com/database/itemtag => ../database/itemtag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/person => ../database/person
 | 
			
		||||
 | 
			
		||||
replace example.com/database/role => ../database/role
 | 
			
		||||
 | 
			
		||||
replace example.com/database/schematic => ../database/schematic
 | 
			
		||||
 | 
			
		||||
replace example.com/database/tier => ../database/tier
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../database/group
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../database/function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../database/functiontag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/commands/create => ../database/commands/create
 | 
			
		||||
 | 
			
		||||
replace example.com/database/commands/get => ../database/commands/get
 | 
			
		||||
 | 
			
		||||
replace example.com/database/commands/update => ../database/commands/update
 | 
			
		||||
 | 
			
		||||
replace example.com/auth/discord => ../auth/discord
 | 
			
		||||
 | 
			
		||||
replace example.com/database/models => ../database/models
 | 
			
		||||
 | 
			
		||||
replace example.com/config/server => ../config/server
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
| 
						 | 
				
			
			@ -26,13 +40,10 @@ require (
 | 
			
		|||
	example.com/auth/discord v0.0.0
 | 
			
		||||
	example.com/config/server v0.0.0
 | 
			
		||||
	example.com/database/commands v0.0.0
 | 
			
		||||
	example.com/database/commands/create v0.0.0
 | 
			
		||||
	example.com/database/commands/get v0.0.0
 | 
			
		||||
	example.com/database/commands/update v0.0.0
 | 
			
		||||
	example.com/database/function v0.0.0
 | 
			
		||||
	example.com/database/functiontag v0.0.0
 | 
			
		||||
	example.com/database/group v0.0.0
 | 
			
		||||
	example.com/database/models v0.0.0
 | 
			
		||||
	example.com/database/user v0.0.0
 | 
			
		||||
	github.com/gin-gonic/gin v1.10.0
 | 
			
		||||
	github.com/xyproto/randomstring v1.2.0
 | 
			
		||||
	golang.org/x/oauth2 v0.29.0
 | 
			
		||||
| 
						 | 
				
			
			@ -40,6 +51,16 @@ require (
 | 
			
		|||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/character v0.0.0 // indirect
 | 
			
		||||
	example.com/database/customization v0.0.0 // indirect
 | 
			
		||||
	example.com/database/functionset v0.0.0 // indirect
 | 
			
		||||
	example.com/database/inventoryslot v0.0.0 // indirect
 | 
			
		||||
	example.com/database/item v0.0.0 // indirect
 | 
			
		||||
	example.com/database/itemtag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/person v0.0.0 // indirect
 | 
			
		||||
	example.com/database/role v0.0.0 // indirect
 | 
			
		||||
	example.com/database/schematic v0.0.0 // indirect
 | 
			
		||||
	example.com/database/tier v0.0.0 // indirect
 | 
			
		||||
	github.com/bytedance/sonic v1.11.6 // indirect
 | 
			
		||||
	github.com/bytedance/sonic/loader v0.1.1 // indirect
 | 
			
		||||
	github.com/cloudwego/base64x v0.1.4 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,7 +31,6 @@ func (config AppConfig) GetAPIRootDomain() string {
 | 
			
		|||
	if config.API.Https {
 | 
			
		||||
		protocol = "https://"
 | 
			
		||||
	}
 | 
			
		||||
	log.Println(config.API)
 | 
			
		||||
	return fmt.Sprintf("%s%s:%s/", protocol, config.API.Domain, config.API.Port)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +39,6 @@ func (config AppConfig) GetFrontendRootDomain() string {
 | 
			
		|||
	if config.Frontend.Https {
 | 
			
		||||
		protocol = "https://"
 | 
			
		||||
	}
 | 
			
		||||
	log.Println(config.Frontend)
 | 
			
		||||
	return fmt.Sprintf("%s%s:%s/", protocol, config.Frontend.Domain, config.Frontend.Port)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										70
									
								
								src/lib/database/character/character.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								src/lib/database/character/character.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,70 @@
 | 
			
		|||
package character
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	functionset "example.com/database/functionset"
 | 
			
		||||
	inventoryslot "example.com/database/inventoryslot"
 | 
			
		||||
	person "example.com/database/person"
 | 
			
		||||
	role "example.com/database/role"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Character struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name         string                        `gorm:"primaryKey; uniqueIndex" json:"name"`
 | 
			
		||||
	Owners       []person.Person               `gorm:"many2many:character_owner_associations" json:"owners"` // Unique
 | 
			
		||||
	Roles        []role.Role                   `gorm:"many2many:character_role_associations" json:"roles"`   // Unique
 | 
			
		||||
	FunctionSets []functionset.FunctionSet     `gorm:"many2many:character_functionset_associations" json:"function_sets"`
 | 
			
		||||
	Inventory    []inventoryslot.InventorySlot `gorm:"many2many:character_inventory_associations" json:"inventory"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseCharacter(db *gorm.DB, character Character) error {
 | 
			
		||||
	result := db.Create(&character)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseCharacter(db *gorm.DB, inputCharacter string) Character {
 | 
			
		||||
	var outputCharacter Character
 | 
			
		||||
	result := db.Model(&Character{}).Where("name = ?", inputCharacter).Take(&outputCharacter)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return Character{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputCharacter).Association("Owners").Find(&outputCharacter.Owners)
 | 
			
		||||
	db.Model(&outputCharacter).Association("Roles").Find(&outputCharacter.Roles)
 | 
			
		||||
	db.Model(&outputCharacter).Association("FunctionSets").Find(&outputCharacter.FunctionSets)
 | 
			
		||||
	db.Model(&outputCharacter).Association("Inventory").Find(&outputCharacter.Inventory)
 | 
			
		||||
	return outputCharacter
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseCharacters(db *gorm.DB, inputCharacters []string) []Character {
 | 
			
		||||
	var outputCharacters []Character
 | 
			
		||||
	for _, inputCharacter := range inputCharacters {
 | 
			
		||||
		outputCharacters = append(outputCharacters, GetDatabaseCharacter(db, inputCharacter))
 | 
			
		||||
	}
 | 
			
		||||
	return outputCharacters
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseCharacters(db *gorm.DB) []Character {
 | 
			
		||||
	var outputCharacters []Character
 | 
			
		||||
	result := db.Find(&outputCharacters)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputCharacter := range outputCharacters {
 | 
			
		||||
		outputCharacters[index] = GetDatabaseCharacter(db, outputCharacter.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputCharacters
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseCharacter(db *gorm.DB, character Character) error {
 | 
			
		||||
	result := db.Save(&character)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										46
									
								
								src/lib/database/character/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/lib/database/character/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,46 @@
 | 
			
		|||
module example.com/database/character
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functionset => ../functionset
 | 
			
		||||
 | 
			
		||||
replace example.com/database/inventoryslot => ../inventoryslot
 | 
			
		||||
 | 
			
		||||
replace example.com/database/person => ../person
 | 
			
		||||
 | 
			
		||||
replace example.com/database/role => ../role
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/item => ../item
 | 
			
		||||
 | 
			
		||||
replace example.com/database/itemtag => ../itemtag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
replace example.com/database/tier => ../tier
 | 
			
		||||
 | 
			
		||||
replace example.com/database/customization => ../customization
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/functionset v0.0.0
 | 
			
		||||
	example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/inventoryslot v0.0.0
 | 
			
		||||
	example.com/database/person v0.0.0
 | 
			
		||||
	example.com/database/role v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/customization v0.0.0 // indirect
 | 
			
		||||
	example.com/database/function v0.0.0 // indirect
 | 
			
		||||
	example.com/database/group v0.0.0 // indirect
 | 
			
		||||
	example.com/database/item v0.0.0 // indirect
 | 
			
		||||
	example.com/database/itemtag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/tier v0.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -3,10 +3,20 @@ package databasecommands
 | 
			
		|||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	character "example.com/database/character"
 | 
			
		||||
	customization "example.com/database/customization"
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
	functionset "example.com/database/functionset"
 | 
			
		||||
	functiontag "example.com/database/functiontag"
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	databasemodels "example.com/database/models"
 | 
			
		||||
	inventoryslot "example.com/database/inventoryslot"
 | 
			
		||||
	item "example.com/database/item"
 | 
			
		||||
	itemtag "example.com/database/itemtag"
 | 
			
		||||
	person "example.com/database/person"
 | 
			
		||||
	role "example.com/database/role"
 | 
			
		||||
	schematic "example.com/database/schematic"
 | 
			
		||||
	tier "example.com/database/tier"
 | 
			
		||||
	user "example.com/database/user"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/driver/sqlite"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
| 
						 | 
				
			
			@ -18,24 +28,24 @@ func InitializeDatabase() *gorm.DB {
 | 
			
		|||
		log.Fatal("Failed to connect to database.")
 | 
			
		||||
	}
 | 
			
		||||
	db.AutoMigrate(
 | 
			
		||||
		&databasemodels.User{},
 | 
			
		||||
		&user.User{},
 | 
			
		||||
		&group.Group{},
 | 
			
		||||
		&functiontag.FunctionTag{},
 | 
			
		||||
		&databasemodels.ItemTag{},
 | 
			
		||||
		&itemtag.ItemTag{},
 | 
			
		||||
		&function.Function{},
 | 
			
		||||
		&databasemodels.FunctionSet{},
 | 
			
		||||
		&databasemodels.Tier{},
 | 
			
		||||
		&databasemodels.Role{},
 | 
			
		||||
		&databasemodels.Person{},
 | 
			
		||||
		&databasemodels.Item{},
 | 
			
		||||
		&databasemodels.InventorySlot{},
 | 
			
		||||
		&databasemodels.Character{},
 | 
			
		||||
		&databasemodels.Customization{},
 | 
			
		||||
		&databasemodels.Schematic{},
 | 
			
		||||
		&functionset.FunctionSet{},
 | 
			
		||||
		&tier.Tier{},
 | 
			
		||||
		&role.Role{},
 | 
			
		||||
		&person.Person{},
 | 
			
		||||
		&item.Item{},
 | 
			
		||||
		&inventoryslot.InventorySlot{},
 | 
			
		||||
		&character.Character{},
 | 
			
		||||
		&customization.Customization{},
 | 
			
		||||
		&schematic.Schematic{},
 | 
			
		||||
	)
 | 
			
		||||
	return db
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func LogoutDatabaseUser(db *gorm.DB, oauthToken string) {
 | 
			
		||||
	db.Model(&databasemodels.User{}).Where("login_token = ?", oauthToken).Update("logged_in", false)
 | 
			
		||||
	db.Model(&user.User{}).Where("login_token = ?", oauthToken).Update("logged_in", false)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,97 +0,0 @@
 | 
			
		|||
package create
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	databasemodels "example.com/database/models"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Create Functions
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseUser(db *gorm.DB, user databasemodels.User) error {
 | 
			
		||||
	result := db.Create(&user)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabasePerson(db *gorm.DB, person databasemodels.Person) error {
 | 
			
		||||
	result := db.Create(&person)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseCharacter(db *gorm.DB, character databasemodels.Character) error {
 | 
			
		||||
	result := db.Create(&character)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseRole(db *gorm.DB, role databasemodels.Role) error {
 | 
			
		||||
	result := db.Create(&role)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseTier(db *gorm.DB, tier databasemodels.Tier) error {
 | 
			
		||||
	result := db.Create(&tier)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseFunctionSet(db *gorm.DB, functionSet databasemodels.FunctionSet) error {
 | 
			
		||||
	result := db.Create(&functionSet)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseInventorySlot(db *gorm.DB, inventorySlot databasemodels.InventorySlot) error {
 | 
			
		||||
	result := db.Create(&inventorySlot)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseItem(db *gorm.DB, item databasemodels.Item) error {
 | 
			
		||||
	result := db.Create(&item)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseItemTag(db *gorm.DB, itemTag databasemodels.ItemTag) error {
 | 
			
		||||
	result := db.Create(&itemTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseCustomization(db *gorm.DB, customization databasemodels.Customization) error {
 | 
			
		||||
	result := db.Create(&customization)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseSchematic(db *gorm.DB, schematic databasemodels.Schematic) error {
 | 
			
		||||
	result := db.Create(&schematic)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,16 +0,0 @@
 | 
			
		|||
module example.com/database/commands/create
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/models => ../../models
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/models v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -1,3 +0,0 @@
 | 
			
		|||
package delete
 | 
			
		||||
 | 
			
		||||
// Delete Functions
 | 
			
		||||
| 
						 | 
				
			
			@ -1,3 +0,0 @@
 | 
			
		|||
module gin-cpularp
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
| 
						 | 
				
			
			@ -1,366 +0,0 @@
 | 
			
		|||
package get
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	databasemodels "example.com/database/models"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Read Functions
 | 
			
		||||
 | 
			
		||||
func GetDatabaseUserToken(db *gorm.DB, id string) string {
 | 
			
		||||
	var dbUser databasemodels.User
 | 
			
		||||
	result := db.Where("id = ?", id).Select("login_token").Take(&dbUser)
 | 
			
		||||
	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
 | 
			
		||||
		return ""
 | 
			
		||||
	} else {
 | 
			
		||||
		return dbUser.LoginToken
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseUserExists(db *gorm.DB, id string) bool {
 | 
			
		||||
	var queryUser databasemodels.User
 | 
			
		||||
	result := db.Where("id = ?", id).Take(&queryUser)
 | 
			
		||||
	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
 | 
			
		||||
		return false
 | 
			
		||||
	} else {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseUserLoggedIn(db *gorm.DB, oauthTokenJSON string) bool {
 | 
			
		||||
	var queryUser databasemodels.User
 | 
			
		||||
	result := db.Where("login_token = ?", oauthTokenJSON).Take(&queryUser)
 | 
			
		||||
	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
 | 
			
		||||
		return false
 | 
			
		||||
	} else {
 | 
			
		||||
		return queryUser.LoggedIn
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseUserLoggedInFromDiscordId(db *gorm.DB, discordId string) bool {
 | 
			
		||||
	var queryUser databasemodels.User
 | 
			
		||||
	result := db.Where("id = ?", discordId).Take(&queryUser)
 | 
			
		||||
	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
 | 
			
		||||
		return false
 | 
			
		||||
	} else {
 | 
			
		||||
		return queryUser.LoggedIn
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabasePerson(db *gorm.DB, inputPerson string) databasemodels.Person {
 | 
			
		||||
	var outputPerson databasemodels.Person
 | 
			
		||||
	result := db.Model(&databasemodels.Person{}).Where("name = ?", inputPerson).Take(&outputPerson)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Person{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputPerson).Association("Groups").Find(&outputPerson.Groups)
 | 
			
		||||
	return outputPerson
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabasePersons(db *gorm.DB, inputPersons []string) []databasemodels.Person {
 | 
			
		||||
	var outputPersons []databasemodels.Person
 | 
			
		||||
	for _, inputPerson := range inputPersons {
 | 
			
		||||
		outputPersons = append(outputPersons, GetDatabasePerson(db, inputPerson))
 | 
			
		||||
	}
 | 
			
		||||
	return outputPersons
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabasePersons(db *gorm.DB) []databasemodels.Person {
 | 
			
		||||
	var outputPersons []databasemodels.Person
 | 
			
		||||
	result := db.Find(&outputPersons)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputPerson := range outputPersons {
 | 
			
		||||
		outputPersons[index] = GetDatabasePerson(db, outputPerson.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputPersons
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseCharacter(db *gorm.DB, inputCharacter string) databasemodels.Character {
 | 
			
		||||
	var outputCharacter databasemodels.Character
 | 
			
		||||
	result := db.Model(&databasemodels.Character{}).Where("name = ?", inputCharacter).Take(&outputCharacter)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Character{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputCharacter).Association("Owners").Find(&outputCharacter.Owners)
 | 
			
		||||
	db.Model(&outputCharacter).Association("Roles").Find(&outputCharacter.Roles)
 | 
			
		||||
	db.Model(&outputCharacter).Association("FunctionSets").Find(&outputCharacter.FunctionSets)
 | 
			
		||||
	db.Model(&outputCharacter).Association("Inventory").Find(&outputCharacter.Inventory)
 | 
			
		||||
	return outputCharacter
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseCharacters(db *gorm.DB, inputCharacters []string) []databasemodels.Character {
 | 
			
		||||
	var outputCharacters []databasemodels.Character
 | 
			
		||||
	for _, inputCharacter := range inputCharacters {
 | 
			
		||||
		outputCharacters = append(outputCharacters, GetDatabaseCharacter(db, inputCharacter))
 | 
			
		||||
	}
 | 
			
		||||
	return outputCharacters
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseCharacters(db *gorm.DB) []databasemodels.Character {
 | 
			
		||||
	var outputCharacters []databasemodels.Character
 | 
			
		||||
	result := db.Find(&outputCharacters)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputCharacter := range outputCharacters {
 | 
			
		||||
		outputCharacters[index] = GetDatabaseCharacter(db, outputCharacter.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputCharacters
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseRole(db *gorm.DB, inputRole string) databasemodels.Role {
 | 
			
		||||
	var outputRole databasemodels.Role
 | 
			
		||||
	result := db.Model(&databasemodels.Role{}).Where("name = ?", inputRole).Take(&outputRole)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Role{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputRole).Association("Tiers").Find(&outputRole.Tiers)
 | 
			
		||||
	db.Model(&outputRole).Association("Visibility").Find(&outputRole.Visibility)
 | 
			
		||||
	return outputRole
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseRoles(db *gorm.DB) []databasemodels.Role {
 | 
			
		||||
	var outputRoles []databasemodels.Role
 | 
			
		||||
	db.Find(&outputRoles)
 | 
			
		||||
	for _, outputRole := range outputRoles {
 | 
			
		||||
		outputRoles = append(outputRoles, GetDatabaseRole(db, outputRole.Name))
 | 
			
		||||
	}
 | 
			
		||||
	return outputRoles
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseRoles(db *gorm.DB) []databasemodels.Role {
 | 
			
		||||
	var outputRoles []databasemodels.Role
 | 
			
		||||
	result := db.Find(&outputRoles)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputRole := range outputRoles {
 | 
			
		||||
		outputRoles[index] = GetDatabaseRole(db, outputRole.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputRoles
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseTier(db *gorm.DB, inputTier int) databasemodels.Tier {
 | 
			
		||||
	var outputTier databasemodels.Tier
 | 
			
		||||
	result := db.Model(&databasemodels.Tier{}).Where("id = ?", inputTier).Take(&outputTier)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Tier{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputTier).Association("FunctionSets").Find(&outputTier.FunctionSets)
 | 
			
		||||
	return outputTier
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseTiers(db *gorm.DB, inputTiers []int) []databasemodels.Tier {
 | 
			
		||||
	var outputTiers []databasemodels.Tier
 | 
			
		||||
	for _, inputTier := range inputTiers {
 | 
			
		||||
		outputTiers = append(outputTiers, GetDatabaseTier(db, inputTier))
 | 
			
		||||
	}
 | 
			
		||||
	return outputTiers
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseTiers(db *gorm.DB) []databasemodels.Tier {
 | 
			
		||||
	var outputTiers []databasemodels.Tier
 | 
			
		||||
	result := db.Find(&outputTiers)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputTier := range outputTiers {
 | 
			
		||||
		outputTiers[index] = GetDatabaseTier(db, int(outputTier.ID))
 | 
			
		||||
	}
 | 
			
		||||
	return outputTiers
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctionSet(db *gorm.DB, inputFunctionSet int) databasemodels.FunctionSet {
 | 
			
		||||
	var outputFunctionSet databasemodels.FunctionSet
 | 
			
		||||
	result := db.Model(&databasemodels.FunctionSet{}).Where("id = ?", inputFunctionSet).Take(&outputFunctionSet)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.FunctionSet{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputFunctionSet).Association("Functions").Find(&outputFunctionSet.Functions)
 | 
			
		||||
	return outputFunctionSet
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctionSets(db *gorm.DB, inputFunctionSets []int) []databasemodels.FunctionSet {
 | 
			
		||||
	var outputFunctionSets []databasemodels.FunctionSet
 | 
			
		||||
	db.Find(&outputFunctionSets)
 | 
			
		||||
	for _, inputFunctionSet := range inputFunctionSets {
 | 
			
		||||
		outputFunctionSets = append(outputFunctionSets, GetDatabaseFunctionSet(db, inputFunctionSet))
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctionSets
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseFunctionSets(db *gorm.DB) []databasemodels.FunctionSet {
 | 
			
		||||
	var outputFunctionSets []databasemodels.FunctionSet
 | 
			
		||||
	result := db.Find(&outputFunctionSets)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputFunctionSet := range outputFunctionSets {
 | 
			
		||||
		outputFunctionSets[index] = GetDatabaseFunctionSet(db, int(outputFunctionSet.ID))
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctionSets
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseInventorySlot(db *gorm.DB, inputInventorySlot int) databasemodels.InventorySlot {
 | 
			
		||||
	var outputInventorySlot databasemodels.InventorySlot
 | 
			
		||||
	result := db.Model(&databasemodels.InventorySlot{}).Where("id = ?", inputInventorySlot).Take(&outputInventorySlot)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.InventorySlot{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputInventorySlot).Association("Item").Find(&outputInventorySlot.Item)
 | 
			
		||||
	return outputInventorySlot
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseInventorySlots(db *gorm.DB, inputInventorySlots []int) []databasemodels.InventorySlot {
 | 
			
		||||
	var outputInventorySlots []databasemodels.InventorySlot
 | 
			
		||||
	for _, inputInventorySlot := range inputInventorySlots {
 | 
			
		||||
		outputInventorySlots = append(outputInventorySlots, GetDatabaseInventorySlot(db, inputInventorySlot))
 | 
			
		||||
	}
 | 
			
		||||
	return outputInventorySlots
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseInventorySlots(db *gorm.DB) []databasemodels.InventorySlot {
 | 
			
		||||
	var outputInventorySlots []databasemodels.InventorySlot
 | 
			
		||||
	result := db.Find(&outputInventorySlots)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputInventorySlot := range outputInventorySlots {
 | 
			
		||||
		outputInventorySlots[index] = GetDatabaseInventorySlot(db, int(outputInventorySlot.ID))
 | 
			
		||||
	}
 | 
			
		||||
	return outputInventorySlots
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseItem(db *gorm.DB, inputItem string) databasemodels.Item {
 | 
			
		||||
	var outputItem databasemodels.Item
 | 
			
		||||
	result := db.Model(&databasemodels.Item{}).Where("name = ?", inputItem).Take(&outputItem)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Item{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputItem).Association("Functions").Find(&outputItem.Functions)
 | 
			
		||||
	db.Model(&outputItem).Association("Tags").Find(&outputItem.Tags)
 | 
			
		||||
	db.Model(&outputItem).Association("Customizations").Find(&outputItem.Customizations)
 | 
			
		||||
	db.Model(&outputItem).Association("Visibility").Find(&outputItem.Visibility)
 | 
			
		||||
	return outputItem
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseItems(db *gorm.DB, inputItems []string) []databasemodels.Item {
 | 
			
		||||
	var outputItems []databasemodels.Item
 | 
			
		||||
	for _, inputItem := range inputItems {
 | 
			
		||||
		outputItems = append(outputItems, GetDatabaseItem(db, inputItem))
 | 
			
		||||
	}
 | 
			
		||||
	return outputItems
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseItems(db *gorm.DB) []databasemodels.Item {
 | 
			
		||||
	var outputItems []databasemodels.Item
 | 
			
		||||
	result := db.Find(&outputItems)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputItem := range outputItems {
 | 
			
		||||
		outputItems[index] = GetDatabaseItem(db, outputItem.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputItems
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseItemTag(db *gorm.DB, inputItemTag string) databasemodels.ItemTag {
 | 
			
		||||
	var outputItemTag databasemodels.ItemTag
 | 
			
		||||
	result := db.Model(&databasemodels.ItemTag{}).Where("name = ?", outputItemTag).Take(&outputItemTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.ItemTag{}
 | 
			
		||||
	}
 | 
			
		||||
	return outputItemTag
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseItemTags(db *gorm.DB, inputItemTags []string) []databasemodels.ItemTag {
 | 
			
		||||
	var outputItemTags []databasemodels.ItemTag
 | 
			
		||||
	for _, inputItemTag := range inputItemTags {
 | 
			
		||||
		outputItemTags = append(outputItemTags, GetDatabaseItemTag(db, inputItemTag))
 | 
			
		||||
	}
 | 
			
		||||
	return outputItemTags
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseItemTags(db *gorm.DB) []databasemodels.ItemTag {
 | 
			
		||||
	var outputItemTags []databasemodels.ItemTag
 | 
			
		||||
	result := db.Find(&outputItemTags)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputItemTag := range outputItemTags {
 | 
			
		||||
		outputItemTags[index] = GetDatabaseItemTag(db, outputItemTag.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputItemTags
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseCustomization(db *gorm.DB, inputCustomization string) databasemodels.Customization {
 | 
			
		||||
	var outputCustomization databasemodels.Customization
 | 
			
		||||
	result := db.Model(&databasemodels.Customization{}).Where("name = ?", inputCustomization).Take(&outputCustomization)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Customization{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputCustomization).Association("Functions").Find(&outputCustomization.Functions)
 | 
			
		||||
	db.Model(&outputCustomization).Association("Tags").Find(&outputCustomization.Tags)
 | 
			
		||||
	db.Model(&outputCustomization).Association("Visibility").Find(&outputCustomization.Visibility)
 | 
			
		||||
	return outputCustomization
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseCustomizations(db *gorm.DB, inputCustomizations []string) []databasemodels.Customization {
 | 
			
		||||
	var outputCustomizations []databasemodels.Customization
 | 
			
		||||
	for _, inputCustomization := range inputCustomizations {
 | 
			
		||||
		outputCustomizations = append(outputCustomizations, GetDatabaseCustomization(db, inputCustomization))
 | 
			
		||||
	}
 | 
			
		||||
	return outputCustomizations
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseCustomizations(db *gorm.DB) []databasemodels.Customization {
 | 
			
		||||
	var outputCustomizations []databasemodels.Customization
 | 
			
		||||
	result := db.Find(&outputCustomizations)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputCustomization := range outputCustomizations {
 | 
			
		||||
		outputCustomizations[index] = GetDatabaseCustomization(db, outputCustomization.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputCustomizations
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseSchematic(db *gorm.DB, inputSchematic int) databasemodels.Schematic {
 | 
			
		||||
	var outputSchematic databasemodels.Schematic
 | 
			
		||||
	result := db.Model(&databasemodels.Schematic{}).Where("id = ?", inputSchematic).Take(&outputSchematic)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Schematic{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputSchematic).Association("Material").Find(&outputSchematic.Material)
 | 
			
		||||
	db.Model(&outputSchematic).Association("Tools").Find(&outputSchematic.Tools)
 | 
			
		||||
	db.Model(&outputSchematic).Association("Requirements").Find(&outputSchematic.Requirements)
 | 
			
		||||
	db.Model(&outputSchematic).Association("Result").Find(&outputSchematic.Result)
 | 
			
		||||
	db.Model(&outputSchematic).Association("Visibility").Find(&outputSchematic.Visibility)
 | 
			
		||||
	return outputSchematic
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseSchematics(db *gorm.DB, inputSchematics []int) []databasemodels.Schematic {
 | 
			
		||||
	var outputSchematics []databasemodels.Schematic
 | 
			
		||||
	for _, inputSchematic := range inputSchematics {
 | 
			
		||||
		outputSchematics = append(outputSchematics, GetDatabaseSchematic(db, inputSchematic))
 | 
			
		||||
	}
 | 
			
		||||
	return outputSchematics
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseSchematics(db *gorm.DB) []databasemodels.Schematic {
 | 
			
		||||
	var outputSchematics []databasemodels.Schematic
 | 
			
		||||
	result := db.Find(&outputSchematics)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputSchematic := range outputSchematics {
 | 
			
		||||
		outputSchematics[index] = GetDatabaseSchematic(db, int(outputSchematic.ID))
 | 
			
		||||
	}
 | 
			
		||||
	return outputSchematics
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,27 @@ module example.com/database/commands
 | 
			
		|||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/models => ../models
 | 
			
		||||
replace example.com/database/user => ../user
 | 
			
		||||
 | 
			
		||||
replace example.com/database/character => ../character
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functionset => ../functionset
 | 
			
		||||
 | 
			
		||||
replace example.com/database/inventoryslot => ../inventoryslot
 | 
			
		||||
 | 
			
		||||
replace example.com/database/customization => ../customization
 | 
			
		||||
 | 
			
		||||
replace example.com/database/item => ../item
 | 
			
		||||
 | 
			
		||||
replace example.com/database/itemtag => ../itemtag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/person => ../person
 | 
			
		||||
 | 
			
		||||
replace example.com/database/role => ../role
 | 
			
		||||
 | 
			
		||||
replace example.com/database/schematic => ../schematic
 | 
			
		||||
 | 
			
		||||
replace example.com/database/tier => ../tier
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -11,7 +31,17 @@ replace example.com/database/function => ../function
 | 
			
		|||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/models v0.0.0
 | 
			
		||||
	example.com/database/character v0.0.0
 | 
			
		||||
	example.com/database/customization v0.0.0
 | 
			
		||||
	example.com/database/functionset v0.0.0
 | 
			
		||||
	example.com/database/inventoryslot v0.0.0
 | 
			
		||||
	example.com/database/item v0.0.0
 | 
			
		||||
	example.com/database/itemtag v0.0.0
 | 
			
		||||
	example.com/database/person v0.0.0
 | 
			
		||||
	example.com/database/role v0.0.0
 | 
			
		||||
	example.com/database/schematic v0.0.0
 | 
			
		||||
	example.com/database/tier v0.0.0
 | 
			
		||||
	example.com/database/user v0.0.0
 | 
			
		||||
	gorm.io/driver/sqlite v1.5.7 // direct
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,16 +0,0 @@
 | 
			
		|||
module example.com/database/commands/update
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/models => ../../models
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/models v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -1,97 +0,0 @@
 | 
			
		|||
package update
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	databasemodels "example.com/database/models"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Update Functions
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseUser(db *gorm.DB, user databasemodels.User) error {
 | 
			
		||||
	result := db.Save(&user)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabasePerson(db *gorm.DB, person databasemodels.Person) error {
 | 
			
		||||
	result := db.Save(&person)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseCharacter(db *gorm.DB, character databasemodels.Character) error {
 | 
			
		||||
	result := db.Save(&character)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseRole(db *gorm.DB, role databasemodels.Role) error {
 | 
			
		||||
	result := db.Save(&role)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseTier(db *gorm.DB, tier databasemodels.Tier) error {
 | 
			
		||||
	result := db.Save(&tier)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseFunctionSet(db *gorm.DB, functionSet databasemodels.FunctionSet) error {
 | 
			
		||||
	result := db.Save(&functionSet)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseInventorySlot(db *gorm.DB, inventoySlot databasemodels.InventorySlot) error {
 | 
			
		||||
	result := db.Save(&inventoySlot)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseItem(db *gorm.DB, item databasemodels.Item) error {
 | 
			
		||||
	result := db.Save(&item)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseItemTag(db *gorm.DB, itemTag databasemodels.ItemTag) error {
 | 
			
		||||
	result := db.Save(&itemTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseCustomization(db *gorm.DB, customization databasemodels.Customization) error {
 | 
			
		||||
	result := db.Save(&customization)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseSchematic(db *gorm.DB, schematic databasemodels.Schematic) error {
 | 
			
		||||
	result := db.Save(&schematic)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										70
									
								
								src/lib/database/customization/customization.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								src/lib/database/customization/customization.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,70 @@
 | 
			
		|||
package customization
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	itemtag "example.com/database/itemtag"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Customization struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name                string              `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
	Functions           []function.Function `gorm:"many2many:customization_function_associations" json:"functions"`
 | 
			
		||||
	FlavorText          string              `json:"flavor_text"`
 | 
			
		||||
	RulesDescription    string              `json:"rules_description"`
 | 
			
		||||
	PhysrepRequirements string              `json:"physrep_requirements"`
 | 
			
		||||
	Tags                []itemtag.ItemTag   `gorm:"many2many:customization_tag_associations" json:"tags"`              // Unique
 | 
			
		||||
	Visibility          []group.Group       `gorm:"many2many:customization_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseCustomization(db *gorm.DB, customization Customization) error {
 | 
			
		||||
	result := db.Create(&customization)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseCustomization(db *gorm.DB, inputCustomization string) Customization {
 | 
			
		||||
	var outputCustomization Customization
 | 
			
		||||
	result := db.Model(&Customization{}).Where("name = ?", inputCustomization).Take(&outputCustomization)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return Customization{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputCustomization).Association("Functions").Find(&outputCustomization.Functions)
 | 
			
		||||
	db.Model(&outputCustomization).Association("Tags").Find(&outputCustomization.Tags)
 | 
			
		||||
	db.Model(&outputCustomization).Association("Visibility").Find(&outputCustomization.Visibility)
 | 
			
		||||
	return outputCustomization
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseCustomizations(db *gorm.DB, inputCustomizations []string) []Customization {
 | 
			
		||||
	var outputCustomizations []Customization
 | 
			
		||||
	for _, inputCustomization := range inputCustomizations {
 | 
			
		||||
		outputCustomizations = append(outputCustomizations, GetDatabaseCustomization(db, inputCustomization))
 | 
			
		||||
	}
 | 
			
		||||
	return outputCustomizations
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseCustomizations(db *gorm.DB) []Customization {
 | 
			
		||||
	var outputCustomizations []Customization
 | 
			
		||||
	result := db.Find(&outputCustomizations)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputCustomization := range outputCustomizations {
 | 
			
		||||
		outputCustomizations[index] = GetDatabaseCustomization(db, outputCustomization.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputCustomizations
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseCustomization(db *gorm.DB, customization Customization) error {
 | 
			
		||||
	result := db.Save(&customization)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,20 +1,22 @@
 | 
			
		|||
module example.com/database/models
 | 
			
		||||
module example.com/database/customization
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
require gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
replace example.com/database/itemtag => ../itemtag
 | 
			
		||||
 | 
			
		||||
require example.com/database/group v0.0.0
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
require example.com/database/function v0.0.0
 | 
			
		||||
 | 
			
		||||
require example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/function v0.0.0
 | 
			
		||||
	example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/group v0.0.0
 | 
			
		||||
	example.com/database/itemtag v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
| 
						 | 
				
			
			@ -23,7 +23,6 @@ func (function *Function) getAssociations(db *gorm.DB) {
 | 
			
		|||
func (function *Function) Get(db *gorm.DB, inputFunction string) {
 | 
			
		||||
	db.Where("name = ?", inputFunction).Take(&function)
 | 
			
		||||
	function.getAssociations(db)
 | 
			
		||||
	log.Printf("Name: %s\nTags: %v\nRequirements: %v", function.Name, function.Tags, function.Requirements)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (function Function) Update(db *gorm.DB) error {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										61
									
								
								src/lib/database/functionset/functionset.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/lib/database/functionset/functionset.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,61 @@
 | 
			
		|||
package functionset
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type FunctionSet struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Functions []function.Function `gorm:"many2many:functionset_function_associations" json:"functions"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseFunctionSet(db *gorm.DB, functionSet FunctionSet) error {
 | 
			
		||||
	result := db.Create(&functionSet)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctionSet(db *gorm.DB, inputFunctionSet int) FunctionSet {
 | 
			
		||||
	var outputFunctionSet FunctionSet
 | 
			
		||||
	result := db.Model(&FunctionSet{}).Where("id = ?", inputFunctionSet).Take(&outputFunctionSet)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return FunctionSet{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputFunctionSet).Association("Functions").Find(&outputFunctionSet.Functions)
 | 
			
		||||
	return outputFunctionSet
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctionSets(db *gorm.DB, inputFunctionSets []int) []FunctionSet {
 | 
			
		||||
	var outputFunctionSets []FunctionSet
 | 
			
		||||
	db.Find(&outputFunctionSets)
 | 
			
		||||
	for _, inputFunctionSet := range inputFunctionSets {
 | 
			
		||||
		outputFunctionSets = append(outputFunctionSets, GetDatabaseFunctionSet(db, inputFunctionSet))
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctionSets
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseFunctionSets(db *gorm.DB) []FunctionSet {
 | 
			
		||||
	var outputFunctionSets []FunctionSet
 | 
			
		||||
	result := db.Find(&outputFunctionSets)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputFunctionSet := range outputFunctionSets {
 | 
			
		||||
		outputFunctionSets[index] = GetDatabaseFunctionSet(db, int(outputFunctionSet.ID))
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctionSets
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseFunctionSet(db *gorm.DB, functionSet FunctionSet) error {
 | 
			
		||||
	result := db.Save(&functionSet)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								src/lib/database/functionset/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/lib/database/functionset/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
module example.com/database/functionset
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/function v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -2,9 +2,7 @@ module example.com/database/group
 | 
			
		|||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
require gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										31
									
								
								src/lib/database/inventoryslot/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/lib/database/inventoryslot/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,31 @@
 | 
			
		|||
module example.com/database/inventoryslot
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/item => ../item
 | 
			
		||||
 | 
			
		||||
replace example.com/database/itemtag => ../itemtag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
replace example.com/database/customization => ../customization
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/customization v0.0.0 // indirect
 | 
			
		||||
	example.com/database/function v0.0.0 // indirect
 | 
			
		||||
	example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/group v0.0.0 // indirect
 | 
			
		||||
	example.com/database/item v0.0.0
 | 
			
		||||
	example.com/database/itemtag v0.0.0 // indirect
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										61
									
								
								src/lib/database/inventoryslot/inventoryslot.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/lib/database/inventoryslot/inventoryslot.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,61 @@
 | 
			
		|||
package inventoryslot
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	item "example.com/database/item"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type InventorySlot struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Item     item.Item `gorm:"foreignKey:Name" json:"item"`
 | 
			
		||||
	Quantity int64     `json:"quantity"` // Positive
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseInventorySlot(db *gorm.DB, inventorySlot InventorySlot) error {
 | 
			
		||||
	result := db.Create(&inventorySlot)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseInventorySlot(db *gorm.DB, inputInventorySlot int) InventorySlot {
 | 
			
		||||
	var outputInventorySlot InventorySlot
 | 
			
		||||
	result := db.Model(&InventorySlot{}).Where("id = ?", inputInventorySlot).Take(&outputInventorySlot)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return InventorySlot{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputInventorySlot).Association("Item").Find(&outputInventorySlot.Item)
 | 
			
		||||
	return outputInventorySlot
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseInventorySlots(db *gorm.DB, inputInventorySlots []int) []InventorySlot {
 | 
			
		||||
	var outputInventorySlots []InventorySlot
 | 
			
		||||
	for _, inputInventorySlot := range inputInventorySlots {
 | 
			
		||||
		outputInventorySlots = append(outputInventorySlots, GetDatabaseInventorySlot(db, inputInventorySlot))
 | 
			
		||||
	}
 | 
			
		||||
	return outputInventorySlots
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseInventorySlots(db *gorm.DB) []InventorySlot {
 | 
			
		||||
	var outputInventorySlots []InventorySlot
 | 
			
		||||
	result := db.Find(&outputInventorySlots)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputInventorySlot := range outputInventorySlots {
 | 
			
		||||
		outputInventorySlots[index] = GetDatabaseInventorySlot(db, int(outputInventorySlot.ID))
 | 
			
		||||
	}
 | 
			
		||||
	return outputInventorySlots
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseInventorySlot(db *gorm.DB, inventoySlot InventorySlot) error {
 | 
			
		||||
	result := db.Save(&inventoySlot)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								src/lib/database/item/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/lib/database/item/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
module example.com/database/item
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/itemtag => ../itemtag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/customization => ../customization
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/customization v0.0.0
 | 
			
		||||
	example.com/database/function v0.0.0
 | 
			
		||||
	example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/group v0.0.0
 | 
			
		||||
	example.com/database/itemtag v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/item/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/item/go.sum
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 | 
			
		||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 | 
			
		||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
			
		||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
			
		||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
			
		||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
			
		||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
 | 
			
		||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
 | 
			
		||||
							
								
								
									
										73
									
								
								src/lib/database/item/item.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								src/lib/database/item/item.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,73 @@
 | 
			
		|||
package item
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	customization "example.com/database/customization"
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	itemtag "example.com/database/itemtag"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Item struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name                string                        `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
	Functions           []function.Function           `gorm:"many2many:item_function_associations" json:"functions"`
 | 
			
		||||
	FlavorText          string                        `json:"flavor_text"`
 | 
			
		||||
	RulesDescription    string                        `json:"rules_description"`
 | 
			
		||||
	PhysrepRequirements string                        `json:"physrep_requirements"`
 | 
			
		||||
	Tags                []itemtag.ItemTag             `gorm:"many2many:item_tag_associations" json:"tags"` // Unique
 | 
			
		||||
	Customizations      []customization.Customization `gorm:"many2many:item_customization_associations" json:"customizations"`
 | 
			
		||||
	Visibility          []group.Group                 `gorm:"many2many:item_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseItem(db *gorm.DB, item Item) error {
 | 
			
		||||
	result := db.Create(&item)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseItem(db *gorm.DB, inputItem string) Item {
 | 
			
		||||
	var outputItem Item
 | 
			
		||||
	result := db.Model(&Item{}).Where("name = ?", inputItem).Take(&outputItem)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return Item{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputItem).Association("Functions").Find(&outputItem.Functions)
 | 
			
		||||
	db.Model(&outputItem).Association("Tags").Find(&outputItem.Tags)
 | 
			
		||||
	db.Model(&outputItem).Association("Customizations").Find(&outputItem.Customizations)
 | 
			
		||||
	db.Model(&outputItem).Association("Visibility").Find(&outputItem.Visibility)
 | 
			
		||||
	return outputItem
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseItems(db *gorm.DB, inputItems []string) []Item {
 | 
			
		||||
	var outputItems []Item
 | 
			
		||||
	for _, inputItem := range inputItems {
 | 
			
		||||
		outputItems = append(outputItems, GetDatabaseItem(db, inputItem))
 | 
			
		||||
	}
 | 
			
		||||
	return outputItems
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseItems(db *gorm.DB) []Item {
 | 
			
		||||
	var outputItems []Item
 | 
			
		||||
	result := db.Find(&outputItems)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputItem := range outputItems {
 | 
			
		||||
		outputItems[index] = GetDatabaseItem(db, outputItem.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputItems
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseItem(db *gorm.DB, item Item) error {
 | 
			
		||||
	result := db.Save(&item)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/lib/database/itemtag/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/lib/database/itemtag/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
module example.com/database/itemtag
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
require gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/itemtag/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/itemtag/go.sum
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 | 
			
		||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 | 
			
		||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
			
		||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
			
		||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
			
		||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
			
		||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
 | 
			
		||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
 | 
			
		||||
							
								
								
									
										57
									
								
								src/lib/database/itemtag/itemtag.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/lib/database/itemtag/itemtag.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,57 @@
 | 
			
		|||
package itemtag
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type ItemTag struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name string `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseItemTag(db *gorm.DB, itemTag ItemTag) error {
 | 
			
		||||
	result := db.Create(&itemTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseItemTag(db *gorm.DB, inputItemTag string) ItemTag {
 | 
			
		||||
	var outputItemTag ItemTag
 | 
			
		||||
	result := db.Model(&ItemTag{}).Where("name = ?", outputItemTag).Take(&outputItemTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return ItemTag{}
 | 
			
		||||
	}
 | 
			
		||||
	return outputItemTag
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseItemTags(db *gorm.DB, inputItemTags []string) []ItemTag {
 | 
			
		||||
	var outputItemTags []ItemTag
 | 
			
		||||
	for _, inputItemTag := range inputItemTags {
 | 
			
		||||
		outputItemTags = append(outputItemTags, GetDatabaseItemTag(db, inputItemTag))
 | 
			
		||||
	}
 | 
			
		||||
	return outputItemTags
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseItemTags(db *gorm.DB) []ItemTag {
 | 
			
		||||
	var outputItemTags []ItemTag
 | 
			
		||||
	result := db.Find(&outputItemTags)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputItemTag := range outputItemTags {
 | 
			
		||||
		outputItemTags[index] = GetDatabaseItemTag(db, outputItemTag.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputItemTags
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseItemTag(db *gorm.DB, itemTag ItemTag) error {
 | 
			
		||||
	result := db.Save(&itemTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,98 +0,0 @@
 | 
			
		|||
package databasemodels
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type User struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Id               string `json:"id"`
 | 
			
		||||
	DisplayName      string `json:"display_name"`
 | 
			
		||||
	Username         string `json:"user_name"`
 | 
			
		||||
	Avatar           string `json:"avatar"`
 | 
			
		||||
	AvatarDecoration string `json:"avatar_decoration"`
 | 
			
		||||
	LoginToken       string `json:"login_token"`
 | 
			
		||||
	LoggedIn         bool   `json:"logged_in"`
 | 
			
		||||
	ApiKey           []struct {
 | 
			
		||||
		Name string `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
		Key  string `json:"key"`
 | 
			
		||||
	} `gorm:"foreignKey:Name" json:"api_key"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Person struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name   string        `gorm:"primaryKey" json:"name"`
 | 
			
		||||
	Groups []group.Group `gorm:"many2many:person_group_associations" json:"groups"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Character struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name         string          `gorm:"primaryKey; uniqueIndex" json:"name"`
 | 
			
		||||
	Owners       []Person        `gorm:"many2many:character_owner_associations" json:"owners"` // Unique
 | 
			
		||||
	Roles        []Role          `gorm:"many2many:character_role_associations" json:"roles"`   // Unique
 | 
			
		||||
	FunctionSets []FunctionSet   `gorm:"many2many:character_functionset_associations" json:"function_sets"`
 | 
			
		||||
	Inventory    []InventorySlot `gorm:"many2many:character_inventory_associations" json:"inventory"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Role struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name       string        `gorm:"primaryKey" json:"name"`
 | 
			
		||||
	Tiers      []Tier        `gorm:"many2many:role_tier_associations" json:"tiers"`
 | 
			
		||||
	Visibility []group.Group `gorm:"many2many:role_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Tier struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	FunctionSets []FunctionSet `gorm:"many2many:tier_functionset_associations" json:"function_sets"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type FunctionSet struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Functions []function.Function `gorm:"many2many:functionset_function_associations" json:"functions"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type InventorySlot struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Item     Item  `gorm:"foreignKey:Name" json:"item"`
 | 
			
		||||
	Quantity int64 `json:"quantity"` // Positive
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Item struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name                string              `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
	Functions           []function.Function `gorm:"many2many:item_function_associations" json:"functions"`
 | 
			
		||||
	FlavorText          string              `json:"flavor_text"`
 | 
			
		||||
	RulesDescription    string              `json:"rules_description"`
 | 
			
		||||
	PhysrepRequirements string              `json:"physrep_requirements"`
 | 
			
		||||
	Tags                []ItemTag           `gorm:"many2many:item_tag_associations" json:"tags"` // Unique
 | 
			
		||||
	Customizations      []Customization     `gorm:"many2many:item_customization_associations" json:"customizations"`
 | 
			
		||||
	Visibility          []group.Group       `gorm:"many2many:item_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ItemTag struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name string `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Customization struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name                string              `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
	Functions           []function.Function `gorm:"many2many:customization_function_associations" json:"functions"`
 | 
			
		||||
	FlavorText          string              `json:"flavor_text"`
 | 
			
		||||
	RulesDescription    string              `json:"rules_description"`
 | 
			
		||||
	PhysrepRequirements string              `json:"physrep_requirements"`
 | 
			
		||||
	Tags                []ItemTag           `gorm:"many2many:customization_tag_associations" json:"tags"`              // Unique
 | 
			
		||||
	Visibility          []group.Group       `gorm:"many2many:customization_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Schematic struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Material     []InventorySlot     `gorm:"many2many:schematic_material_associations" json:"material"`
 | 
			
		||||
	Tools        []InventorySlot     `gorm:"many2many:schematic_tool_associations" json:"tools"`
 | 
			
		||||
	Requirements []function.Function `gorm:"many2many:schematic_requirement_associations" json:"requirements"`
 | 
			
		||||
	TimeUnits    int64               `json:"time_units"` // Positive
 | 
			
		||||
	Result       InventorySlot       `gorm:"many2many:schematic_result_associations" json:"result"`
 | 
			
		||||
	Visibility   []group.Group       `gorm:"many2many:schematic_group_associations" json:"visibility"` // Unique
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,11 +1,11 @@
 | 
			
		|||
module example.com/database/commands/get
 | 
			
		||||
module example.com/database/person
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/models => ../../models
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/models v0.0.0
 | 
			
		||||
	example.com/database/group v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/person/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/person/go.sum
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 | 
			
		||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 | 
			
		||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
			
		||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
			
		||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
			
		||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
			
		||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
 | 
			
		||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
 | 
			
		||||
							
								
								
									
										61
									
								
								src/lib/database/person/person.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/lib/database/person/person.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,61 @@
 | 
			
		|||
package person
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Person struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name   string        `gorm:"primaryKey" json:"name"`
 | 
			
		||||
	Groups []group.Group `gorm:"many2many:person_group_associations" json:"groups"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabasePerson(db *gorm.DB, person Person) error {
 | 
			
		||||
	result := db.Create(&person)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabasePerson(db *gorm.DB, inputPerson string) Person {
 | 
			
		||||
	var outputPerson Person
 | 
			
		||||
	result := db.Model(&Person{}).Where("name = ?", inputPerson).Take(&outputPerson)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return Person{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputPerson).Association("Groups").Find(&outputPerson.Groups)
 | 
			
		||||
	return outputPerson
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabasePersons(db *gorm.DB, inputPersons []string) []Person {
 | 
			
		||||
	var outputPersons []Person
 | 
			
		||||
	for _, inputPerson := range inputPersons {
 | 
			
		||||
		outputPersons = append(outputPersons, GetDatabasePerson(db, inputPerson))
 | 
			
		||||
	}
 | 
			
		||||
	return outputPersons
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabasePersons(db *gorm.DB) []Person {
 | 
			
		||||
	var outputPersons []Person
 | 
			
		||||
	result := db.Find(&outputPersons)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputPerson := range outputPersons {
 | 
			
		||||
		outputPersons[index] = GetDatabasePerson(db, outputPerson.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputPersons
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabasePerson(db *gorm.DB, person Person) error {
 | 
			
		||||
	result := db.Save(&person)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								src/lib/database/role/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/lib/database/role/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
module example.com/database/role
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/tier => ../tier
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functionset => ../functionset
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/functionset v0.0.0 // indirect
 | 
			
		||||
	example.com/database/group v0.0.0
 | 
			
		||||
	example.com/database/tier v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/role/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/role/go.sum
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 | 
			
		||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 | 
			
		||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
			
		||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
			
		||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
			
		||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
			
		||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
 | 
			
		||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
 | 
			
		||||
							
								
								
									
										65
									
								
								src/lib/database/role/role.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								src/lib/database/role/role.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,65 @@
 | 
			
		|||
package role
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	tier "example.com/database/tier"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Role struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name       string        `gorm:"primaryKey" json:"name"`
 | 
			
		||||
	Tiers      []tier.Tier   `gorm:"many2many:role_tier_associations" json:"tiers"`
 | 
			
		||||
	Visibility []group.Group `gorm:"many2many:role_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseRole(db *gorm.DB, role Role) error {
 | 
			
		||||
	result := db.Create(&role)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseRole(db *gorm.DB, inputRole string) Role {
 | 
			
		||||
	var outputRole Role
 | 
			
		||||
	result := db.Model(&Role{}).Where("name = ?", inputRole).Take(&outputRole)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return Role{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputRole).Association("Tiers").Find(&outputRole.Tiers)
 | 
			
		||||
	db.Model(&outputRole).Association("Visibility").Find(&outputRole.Visibility)
 | 
			
		||||
	return outputRole
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseRoles(db *gorm.DB) []Role {
 | 
			
		||||
	var outputRoles []Role
 | 
			
		||||
	db.Find(&outputRoles)
 | 
			
		||||
	for _, outputRole := range outputRoles {
 | 
			
		||||
		outputRoles = append(outputRoles, GetDatabaseRole(db, outputRole.Name))
 | 
			
		||||
	}
 | 
			
		||||
	return outputRoles
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseRoles(db *gorm.DB) []Role {
 | 
			
		||||
	var outputRoles []Role
 | 
			
		||||
	result := db.Find(&outputRoles)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputRole := range outputRoles {
 | 
			
		||||
		outputRoles[index] = GetDatabaseRole(db, outputRole.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputRoles
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseRole(db *gorm.DB, role Role) error {
 | 
			
		||||
	result := db.Save(&role)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								src/lib/database/schematic/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/lib/database/schematic/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,34 @@
 | 
			
		|||
module example.com/database/schematic
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/inventoryslot => ../inventoryslot
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
replace example.com/database/item => ../item
 | 
			
		||||
 | 
			
		||||
replace example.com/database/itemtag => ../itemtag
 | 
			
		||||
 | 
			
		||||
replace example.com/database/customization => ../customization
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/function v0.0.0
 | 
			
		||||
	example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
	example.com/database/group v0.0.0
 | 
			
		||||
	example.com/database/inventoryslot v0.0.0
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/customization v0.0.0 // indirect
 | 
			
		||||
	example.com/database/item v0.0.0 // indirect
 | 
			
		||||
	example.com/database/itemtag v0.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/schematic/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/schematic/go.sum
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 | 
			
		||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 | 
			
		||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
			
		||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
			
		||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
			
		||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
			
		||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
 | 
			
		||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
 | 
			
		||||
							
								
								
									
										71
									
								
								src/lib/database/schematic/schematic.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								src/lib/database/schematic/schematic.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,71 @@
 | 
			
		|||
package schematic
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	inventoryslot "example.com/database/inventoryslot"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Schematic struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Material     []inventoryslot.InventorySlot `gorm:"many2many:schematic_material_associations" json:"material"`
 | 
			
		||||
	Tools        []inventoryslot.InventorySlot `gorm:"many2many:schematic_tool_associations" json:"tools"`
 | 
			
		||||
	Requirements []function.Function           `gorm:"many2many:schematic_requirement_associations" json:"requirements"`
 | 
			
		||||
	TimeUnits    int64                         `json:"time_units"` // Positive
 | 
			
		||||
	Result       inventoryslot.InventorySlot   `gorm:"many2many:schematic_result_associations" json:"result"`
 | 
			
		||||
	Visibility   []group.Group                 `gorm:"many2many:schematic_group_associations" json:"visibility"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseSchematic(db *gorm.DB, schematic Schematic) error {
 | 
			
		||||
	result := db.Create(&schematic)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseSchematic(db *gorm.DB, inputSchematic int) Schematic {
 | 
			
		||||
	var outputSchematic Schematic
 | 
			
		||||
	result := db.Model(&Schematic{}).Where("id = ?", inputSchematic).Take(&outputSchematic)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return Schematic{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputSchematic).Association("Material").Find(&outputSchematic.Material)
 | 
			
		||||
	db.Model(&outputSchematic).Association("Tools").Find(&outputSchematic.Tools)
 | 
			
		||||
	db.Model(&outputSchematic).Association("Requirements").Find(&outputSchematic.Requirements)
 | 
			
		||||
	db.Model(&outputSchematic).Association("Result").Find(&outputSchematic.Result)
 | 
			
		||||
	db.Model(&outputSchematic).Association("Visibility").Find(&outputSchematic.Visibility)
 | 
			
		||||
	return outputSchematic
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseSchematics(db *gorm.DB, inputSchematics []int) []Schematic {
 | 
			
		||||
	var outputSchematics []Schematic
 | 
			
		||||
	for _, inputSchematic := range inputSchematics {
 | 
			
		||||
		outputSchematics = append(outputSchematics, GetDatabaseSchematic(db, inputSchematic))
 | 
			
		||||
	}
 | 
			
		||||
	return outputSchematics
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseSchematics(db *gorm.DB) []Schematic {
 | 
			
		||||
	var outputSchematics []Schematic
 | 
			
		||||
	result := db.Find(&outputSchematics)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputSchematic := range outputSchematics {
 | 
			
		||||
		outputSchematics[index] = GetDatabaseSchematic(db, int(outputSchematic.ID))
 | 
			
		||||
	}
 | 
			
		||||
	return outputSchematics
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseSchematic(db *gorm.DB, schematic Schematic) error {
 | 
			
		||||
	result := db.Save(&schematic)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								src/lib/database/tier/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/lib/database/tier/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
module example.com/database/tier
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functionset => ../functionset
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/function v0.0.0 // indirect
 | 
			
		||||
	example.com/database/functionset v0.0.0
 | 
			
		||||
	example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/tier/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/tier/go.sum
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 | 
			
		||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 | 
			
		||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
			
		||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
			
		||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
			
		||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
			
		||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
 | 
			
		||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
 | 
			
		||||
							
								
								
									
										60
									
								
								src/lib/database/tier/tier.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src/lib/database/tier/tier.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,60 @@
 | 
			
		|||
package tier
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	functionset "example.com/database/functionset"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Tier struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	FunctionSets []functionset.FunctionSet `gorm:"many2many:tier_functionset_associations" json:"function_sets"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseTier(db *gorm.DB, tier Tier) error {
 | 
			
		||||
	result := db.Create(&tier)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseTier(db *gorm.DB, inputTier int) Tier {
 | 
			
		||||
	var outputTier Tier
 | 
			
		||||
	result := db.Model(&Tier{}).Where("id = ?", inputTier).Take(&outputTier)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return Tier{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputTier).Association("FunctionSets").Find(&outputTier.FunctionSets)
 | 
			
		||||
	return outputTier
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseTiers(db *gorm.DB, inputTiers []int) []Tier {
 | 
			
		||||
	var outputTiers []Tier
 | 
			
		||||
	for _, inputTier := range inputTiers {
 | 
			
		||||
		outputTiers = append(outputTiers, GetDatabaseTier(db, inputTier))
 | 
			
		||||
	}
 | 
			
		||||
	return outputTiers
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseTiers(db *gorm.DB) []Tier {
 | 
			
		||||
	var outputTiers []Tier
 | 
			
		||||
	result := db.Find(&outputTiers)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputTier := range outputTiers {
 | 
			
		||||
		outputTiers[index] = GetDatabaseTier(db, int(outputTier.ID))
 | 
			
		||||
	}
 | 
			
		||||
	return outputTiers
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseTier(db *gorm.DB, tier Tier) error {
 | 
			
		||||
	result := db.Save(&tier)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/lib/database/user/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/lib/database/user/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
module example.com/database/user
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
require gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
	golang.org/x/text v0.14.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/user/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/user/go.sum
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 | 
			
		||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 | 
			
		||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
			
		||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
			
		||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 | 
			
		||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
			
		||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
 | 
			
		||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
 | 
			
		||||
							
								
								
									
										82
									
								
								src/lib/database/user/user.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								src/lib/database/user/user.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,82 @@
 | 
			
		|||
package user
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type User struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Id               string `json:"id"`
 | 
			
		||||
	DisplayName      string `json:"display_name"`
 | 
			
		||||
	Username         string `json:"user_name"`
 | 
			
		||||
	Avatar           string `json:"avatar"`
 | 
			
		||||
	AvatarDecoration string `json:"avatar_decoration"`
 | 
			
		||||
	LoginToken       string `json:"login_token"`
 | 
			
		||||
	LoggedIn         bool   `json:"logged_in"`
 | 
			
		||||
	ApiKey           []struct {
 | 
			
		||||
		Name string `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
		Key  string `json:"key"`
 | 
			
		||||
	} `gorm:"foreignKey:Name" json:"api_key"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (user *User) Get(db *gorm.DB, id string) {
 | 
			
		||||
	db.Where("id = ?", id).Take(&user)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (user User) Update(db *gorm.DB) error {
 | 
			
		||||
	result := db.Save(&user)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (user User) Create(db *gorm.DB) error {
 | 
			
		||||
	result := db.Create(&user)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Exists(db *gorm.DB, id string) bool {
 | 
			
		||||
	var queryUser User
 | 
			
		||||
	result := db.Where("id = ?", id).Take(&queryUser)
 | 
			
		||||
	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
 | 
			
		||||
		return false
 | 
			
		||||
	} else {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTokenFromUserId(db *gorm.DB, id string) string {
 | 
			
		||||
	var dbUser User
 | 
			
		||||
	result := db.Where("id = ?", id).Select("login_token").Take(&dbUser)
 | 
			
		||||
	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
 | 
			
		||||
		return ""
 | 
			
		||||
	} else {
 | 
			
		||||
		return dbUser.LoginToken
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetLoggedInFromOAuthToken(db *gorm.DB, oauthTokenJSON string) bool {
 | 
			
		||||
	var queryUser User
 | 
			
		||||
	result := db.Where("login_token = ?", oauthTokenJSON).Take(&queryUser)
 | 
			
		||||
	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
 | 
			
		||||
		return false
 | 
			
		||||
	} else {
 | 
			
		||||
		return queryUser.LoggedIn
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetLoggedInFromDiscordId(db *gorm.DB, discordId string) bool {
 | 
			
		||||
	var queryUser User
 | 
			
		||||
	result := db.Where("id = ?", discordId).Take(&queryUser)
 | 
			
		||||
	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
 | 
			
		||||
		return false
 | 
			
		||||
	} else {
 | 
			
		||||
		return queryUser.LoggedIn
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in a new issue