Slowly migrating struct methods to their own models for association.
This commit is contained in:
		
							parent
							
								
									9505c479e8
								
							
						
					
					
						commit
						06cb11ed8c
					
				
					 31 changed files with 1209 additions and 839 deletions
				
			
		
							
								
								
									
										22
									
								
								src/go.mod
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/go.mod
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -4,6 +4,20 @@ go 1.24.2
 | 
			
		|||
 | 
			
		||||
replace example.com/database/commands => ./lib/database/commands
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
| 
						 | 
				
			
			@ -15,12 +29,18 @@ replace example.com/api => ./lib/api
 | 
			
		|||
require (
 | 
			
		||||
	example.com/api v0.0.0
 | 
			
		||||
	example.com/auth/discord v0.0.0
 | 
			
		||||
	example.com/config/server v0.0.0
 | 
			
		||||
	example.com/database/commands v0.0.0
 | 
			
		||||
	github.com/gin-gonic/gin v1.10.0
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
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/function 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
 | 
			
		||||
	github.com/bytedance/sonic v1.11.6 // indirect
 | 
			
		||||
	github.com/bytedance/sonic/loader v0.1.1 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,13 +2,19 @@ package api
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"io"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	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"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
| 
						 | 
				
			
			@ -23,29 +29,6 @@ var GlobalOAuth *oauth2.Config
 | 
			
		|||
 | 
			
		||||
// Private Functions
 | 
			
		||||
 | 
			
		||||
func getDiscordUser(context *gin.Context, oauthToken *oauth2.Token) authdiscord.DiscordUser {
 | 
			
		||||
	response, err := GlobalOAuth.Client(context, oauthToken).Get("https://discord.com/api/users/@me")
 | 
			
		||||
	if err != nil || response.StatusCode != 200 {
 | 
			
		||||
		responseMessage := ""
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			responseMessage = err.Error()
 | 
			
		||||
		} else {
 | 
			
		||||
			responseMessage = response.Status
 | 
			
		||||
		}
 | 
			
		||||
		log.Println(responseMessage)
 | 
			
		||||
		log.Println("Assuming the Discord OAuth Key has expired.")
 | 
			
		||||
		context.Redirect(http.StatusUnauthorized, "https://localhost:15995/logout")
 | 
			
		||||
	}
 | 
			
		||||
	defer response.Body.Close()
 | 
			
		||||
	body, err := io.ReadAll(response.Body)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Println(err)
 | 
			
		||||
	}
 | 
			
		||||
	var user authdiscord.DiscordUser
 | 
			
		||||
	json.Unmarshal(body, &user)
 | 
			
		||||
	return user
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Authentication Workflow
 | 
			
		||||
 | 
			
		||||
func AuthCallback(context *gin.Context) {
 | 
			
		||||
| 
						 | 
				
			
			@ -54,16 +37,17 @@ func AuthCallback(context *gin.Context) {
 | 
			
		|||
	var err error
 | 
			
		||||
	oauthToken, err := GlobalOAuth.Exchange(context.Request.Context(), context.Query("code"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		context.Redirect(http.StatusInternalServerError, "http://localhost:15995/")
 | 
			
		||||
		context.Redirect(http.StatusInternalServerError, GlobalConfig.GetFrontendRootDomain())
 | 
			
		||||
	}
 | 
			
		||||
	oauthTokenJSON, _ := json.Marshal(oauthToken)
 | 
			
		||||
	context.SetCookie("discord-oauthtoken", string(oauthTokenJSON), 0, "", GlobalConfig.API.Domain, false, false)
 | 
			
		||||
	context.Set("discord-oauthtoken", string(oauthTokenJSON))
 | 
			
		||||
	CreateOrUpdateUser(context)
 | 
			
		||||
	context.Redirect(http.StatusTemporaryRedirect, "http://localhost:15995/dashboard")
 | 
			
		||||
	context.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%sdashboard", GlobalConfig.GetFrontendRootDomain()))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func AuthLoginRedirect(context *gin.Context) {
 | 
			
		||||
	log.Println(GlobalOAuth.AuthCodeURL(context.GetString("state")))
 | 
			
		||||
	context.Redirect(302, GlobalOAuth.AuthCodeURL(context.GetString("state")))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +59,7 @@ func AuthLogoutRedirect(context *gin.Context) {
 | 
			
		|||
	} else {
 | 
			
		||||
		log.Println(err)
 | 
			
		||||
	}
 | 
			
		||||
	context.Redirect(http.StatusTemporaryRedirect, "http://localhost:15995/")
 | 
			
		||||
	context.Redirect(http.StatusTemporaryRedirect, GlobalConfig.GetFrontendRootDomain())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Create & Update Endpoints (post/, put/, patch)
 | 
			
		||||
| 
						 | 
				
			
			@ -96,7 +80,8 @@ func CreateOrUpdateUser(context *gin.Context) {
 | 
			
		|||
		log.Println(err)
 | 
			
		||||
		context.AbortWithStatus(http.StatusBadRequest)
 | 
			
		||||
	}
 | 
			
		||||
	currentDiscordUser := getDiscordUser(context, oauthToken)
 | 
			
		||||
	var currentDiscordUser authdiscord.DiscordUser
 | 
			
		||||
	currentDiscordUser.GetDiscordUser(context, oauthToken, GlobalConfig, GlobalOAuth)
 | 
			
		||||
	updatedDatabaseUser := databasemodels.User{
 | 
			
		||||
		DisplayName:      currentDiscordUser.Global_Name,
 | 
			
		||||
		Username:         currentDiscordUser.Username,
 | 
			
		||||
| 
						 | 
				
			
			@ -107,21 +92,21 @@ func CreateOrUpdateUser(context *gin.Context) {
 | 
			
		|||
		LoggedIn:         true,
 | 
			
		||||
		ApiKey:           nil,
 | 
			
		||||
	}
 | 
			
		||||
	if databasecommands.GetDatabaseUserExists(GlobalDatabase, currentDiscordUser.Id) {
 | 
			
		||||
		dbOAuthToken := databasecommands.GetDatabaseUserToken(GlobalDatabase, currentDiscordUser.Id)
 | 
			
		||||
		if databasecommands.GetDatabaseUserLoggedInFromDiscordId(GlobalDatabase, currentDiscordUser.Id) {
 | 
			
		||||
	if get.GetDatabaseUserExists(GlobalDatabase, currentDiscordUser.Id) {
 | 
			
		||||
		dbOAuthToken := get.GetDatabaseUserToken(GlobalDatabase, currentDiscordUser.Id)
 | 
			
		||||
		if get.GetDatabaseUserLoggedInFromDiscordId(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 := databasecommands.UpdateDatabaseUser(GlobalDatabase, updatedDatabaseUser)
 | 
			
		||||
		err := update.UpdateDatabaseUser(GlobalDatabase, updatedDatabaseUser)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Println(err)
 | 
			
		||||
			context.AbortWithStatus(http.StatusInternalServerError)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		err := databasecommands.CreateDatabaseUser(GlobalDatabase, updatedDatabaseUser)
 | 
			
		||||
		err := create.CreateDatabaseUser(GlobalDatabase, updatedDatabaseUser)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Println(err)
 | 
			
		||||
			context.Copy().AbortWithStatus(http.StatusInternalServerError)
 | 
			
		||||
| 
						 | 
				
			
			@ -135,9 +120,7 @@ func CreateDatabaseGroup(context *gin.Context) {
 | 
			
		|||
	if isAuthorized {
 | 
			
		||||
		name := context.Query("name")
 | 
			
		||||
		if name != "" {
 | 
			
		||||
			databasecommands.CreateDatabaseGroup(GlobalDatabase, databasemodels.Group{
 | 
			
		||||
				Name: name,
 | 
			
		||||
			})
 | 
			
		||||
			group.Group{Name: name}.Create(GlobalDatabase)
 | 
			
		||||
			context.Status(http.StatusOK)
 | 
			
		||||
		} else {
 | 
			
		||||
			context.AbortWithStatus(http.StatusBadRequest)
 | 
			
		||||
| 
						 | 
				
			
			@ -150,28 +133,25 @@ func CreateDatabaseGroup(context *gin.Context) {
 | 
			
		|||
func CreateDatabaseFunction(context *gin.Context) {
 | 
			
		||||
	GetIsUserAuthorized(context)
 | 
			
		||||
	isAuthorized := context.GetBool("is-authorized")
 | 
			
		||||
	log.Println(isAuthorized)
 | 
			
		||||
	if isAuthorized {
 | 
			
		||||
		name := context.Query("name")
 | 
			
		||||
		tags := context.QueryArray("tags")
 | 
			
		||||
		requirements := context.QueryArray("requirements")
 | 
			
		||||
		if name != "" {
 | 
			
		||||
			newTags := []databasemodels.FunctionTag{}
 | 
			
		||||
			log.Println(tags)
 | 
			
		||||
			for _, tag := range tags {
 | 
			
		||||
				newTags = append(newTags, databasecommands.GetDatabaseFunctionTag(GlobalDatabase, tag))
 | 
			
		||||
		name, nameOk := context.GetQuery("name")
 | 
			
		||||
		tags, tagsOk := context.GetQueryArray("tags")
 | 
			
		||||
		requirements, requirementsOk := context.GetQueryArray("requirements")
 | 
			
		||||
		if nameOk {
 | 
			
		||||
			var newTags *[]functiontag.FunctionTag
 | 
			
		||||
			var newRequirements *[]function.Function
 | 
			
		||||
			if tagsOk {
 | 
			
		||||
				newTags = functiontag.Get(GlobalDatabase, tags)
 | 
			
		||||
			}
 | 
			
		||||
			log.Println(newTags)
 | 
			
		||||
			newRequirements := []databasemodels.Function{}
 | 
			
		||||
			for _, requirement := range requirements {
 | 
			
		||||
				newRequirement := databasecommands.GetDatabaseFunction(GlobalDatabase, requirement)
 | 
			
		||||
				newRequirements = append(newRequirements, newRequirement)
 | 
			
		||||
			if requirementsOk {
 | 
			
		||||
				newRequirements = function.Get(GlobalDatabase, requirements)
 | 
			
		||||
			}
 | 
			
		||||
			databasecommands.CreateDatabaseFunction(GlobalDatabase, databasemodels.Function{
 | 
			
		||||
			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 {
 | 
			
		||||
			context.AbortWithStatus(http.StatusBadRequest)
 | 
			
		||||
| 
						 | 
				
			
			@ -188,9 +168,9 @@ func CreateDatabaseFunctionTag(context *gin.Context) {
 | 
			
		|||
	if isAuthorized {
 | 
			
		||||
		name := context.Query("name")
 | 
			
		||||
		if name != "" {
 | 
			
		||||
			databasecommands.CreateDatabaseFunctionTag(GlobalDatabase, databasemodels.FunctionTag{
 | 
			
		||||
			functiontag.FunctionTag{
 | 
			
		||||
				Name: name,
 | 
			
		||||
			})
 | 
			
		||||
			}.Create(GlobalDatabase)
 | 
			
		||||
			context.Status(http.StatusOK)
 | 
			
		||||
		} else {
 | 
			
		||||
			context.AbortWithStatus(http.StatusBadRequest)
 | 
			
		||||
| 
						 | 
				
			
			@ -209,11 +189,12 @@ func GetUserInfo(context *gin.Context) {
 | 
			
		|||
		err := json.Unmarshal([]byte(oauthTokenJSON), &oauthToken)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			if oauthToken.Valid() {
 | 
			
		||||
				user := getDiscordUser(context, oauthToken)
 | 
			
		||||
				if databasecommands.GetDatabaseUserLoggedInFromDiscordId(GlobalDatabase, user.Id) {
 | 
			
		||||
				var user authdiscord.DiscordUser
 | 
			
		||||
				user.GetDiscordUser(context, oauthToken, GlobalConfig, GlobalOAuth)
 | 
			
		||||
				if get.GetDatabaseUserLoggedInFromDiscordId(GlobalDatabase, user.Id) {
 | 
			
		||||
					context.JSON(http.StatusOK, user)
 | 
			
		||||
				} else {
 | 
			
		||||
					context.Redirect(http.StatusTemporaryRedirect, "http://localhost:31337/auth/logout")
 | 
			
		||||
					context.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%slogout", GlobalConfig.GetAPIRootDomain()))
 | 
			
		||||
				}
 | 
			
		||||
				return
 | 
			
		||||
			} else {
 | 
			
		||||
| 
						 | 
				
			
			@ -228,7 +209,7 @@ func GetUserInfo(context *gin.Context) {
 | 
			
		|||
		log.Println(err)
 | 
			
		||||
		context.AbortWithStatus(http.StatusBadRequest)
 | 
			
		||||
	}
 | 
			
		||||
	context.Redirect(http.StatusTemporaryRedirect, "http://localhost:15995/")
 | 
			
		||||
	context.Redirect(http.StatusTemporaryRedirect, GlobalConfig.GetFrontendRootDomain())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetIsUserAuthorized(context *gin.Context) {
 | 
			
		||||
| 
						 | 
				
			
			@ -238,7 +219,7 @@ func GetIsUserAuthorized(context *gin.Context) {
 | 
			
		|||
		err := json.Unmarshal([]byte(oauthTokenJSON), &oauthToken)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			if oauthToken.Valid() {
 | 
			
		||||
				if databasecommands.GetDatabaseUserLoggedIn(GlobalDatabase, oauthTokenJSON) {
 | 
			
		||||
				if get.GetDatabaseUserLoggedIn(GlobalDatabase, oauthTokenJSON) {
 | 
			
		||||
					context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
						"message": true,
 | 
			
		||||
					})
 | 
			
		||||
| 
						 | 
				
			
			@ -254,82 +235,64 @@ func GetIsUserAuthorized(context *gin.Context) {
 | 
			
		|||
	context.Set("is-authorized", false)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseGroup(context *gin.Context) {
 | 
			
		||||
	groupName := context.Query("group")
 | 
			
		||||
	if groupName != "" {
 | 
			
		||||
		group := databasecommands.GetDatabaseGroup(GlobalDatabase, groupName)
 | 
			
		||||
		context.JSON(http.StatusOK, group)
 | 
			
		||||
func GetDatabaseGroups(context *gin.Context) {
 | 
			
		||||
	groupNames, ok := context.GetQueryArray("groups")
 | 
			
		||||
	if ok {
 | 
			
		||||
		groups := group.Get(GlobalDatabase, groupNames)
 | 
			
		||||
		context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
			"groups": groups,
 | 
			
		||||
		})
 | 
			
		||||
	} else {
 | 
			
		||||
		context.JSON(http.StatusBadRequest, gin.H{
 | 
			
		||||
			"name": "",
 | 
			
		||||
		context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
			"groups": []group.Group{},
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseGroups(context *gin.Context) {
 | 
			
		||||
	groupNames := context.QueryArray("groups")
 | 
			
		||||
	groups := databasecommands.GetDatabaseGroups(GlobalDatabase, groupNames)
 | 
			
		||||
	context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
		"groups": groups,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseGroups(context *gin.Context) {
 | 
			
		||||
	groups := databasecommands.GetAllDatabaseGroups(GlobalDatabase)
 | 
			
		||||
	groups := group.GetAll(GlobalDatabase)
 | 
			
		||||
	context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
		"groups": groups,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunction(context *gin.Context) {
 | 
			
		||||
	functionName := context.Query("function")
 | 
			
		||||
	if functionName != "" {
 | 
			
		||||
		group := databasecommands.GetDatabaseFunction(GlobalDatabase, functionName)
 | 
			
		||||
		context.JSON(http.StatusOK, group)
 | 
			
		||||
func GetDatabaseFunctions(context *gin.Context) {
 | 
			
		||||
	functionNames, ok := context.GetQueryArray("functions")
 | 
			
		||||
	if ok {
 | 
			
		||||
		functions := function.Get(GlobalDatabase, functionNames)
 | 
			
		||||
		context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
			"functions": functions,
 | 
			
		||||
		})
 | 
			
		||||
	} else {
 | 
			
		||||
		context.JSON(http.StatusBadRequest, gin.H{
 | 
			
		||||
			"name": "",
 | 
			
		||||
		context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
			"functions": function.Function{},
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctions(context *gin.Context) {
 | 
			
		||||
	functionNames := context.QueryArray("functions")
 | 
			
		||||
	functions := databasecommands.GetDatabaseFunctions(GlobalDatabase, functionNames)
 | 
			
		||||
	context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
		"functions": functions,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseFunctions(context *gin.Context) {
 | 
			
		||||
	functions := databasecommands.GetAllDatabaseFunctions(GlobalDatabase)
 | 
			
		||||
	functions := function.GetAll(GlobalDatabase)
 | 
			
		||||
	context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
		"functions": functions,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctionTag(context *gin.Context) {
 | 
			
		||||
	functionTagName := context.Query("name")
 | 
			
		||||
	if functionTagName != "" {
 | 
			
		||||
		functionTag := databasecommands.GetDatabaseFunctionTag(GlobalDatabase, functionTagName)
 | 
			
		||||
		context.JSON(http.StatusOK, functionTag)
 | 
			
		||||
func GetDatabaseFunctionTags(context *gin.Context) {
 | 
			
		||||
	functionTagNames, ok := context.GetQueryArray("functiontags")
 | 
			
		||||
	if ok {
 | 
			
		||||
		functionTags := functiontag.Get(GlobalDatabase, functionTagNames)
 | 
			
		||||
		context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
			"function_tags": functionTags,
 | 
			
		||||
		})
 | 
			
		||||
	} else {
 | 
			
		||||
		context.JSON(http.StatusBadRequest, gin.H{
 | 
			
		||||
			"name": "",
 | 
			
		||||
		context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
			"function_tags": []functiontag.FunctionTag{},
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctionTags(context *gin.Context) {
 | 
			
		||||
	functionTagNames := context.QueryArray("functiontags")
 | 
			
		||||
	functionTags := databasecommands.GetDatabaseFunctionTags(GlobalDatabase, functionTagNames)
 | 
			
		||||
	context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
		"function_tags": functionTags,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseFunctionTags(context *gin.Context) {
 | 
			
		||||
	functionTags := databasecommands.GetAllDatabaseFunctionTags(GlobalDatabase)
 | 
			
		||||
	functionTags := functiontag.GetAll(GlobalDatabase)
 | 
			
		||||
	context.JSON(http.StatusOK, gin.H{
 | 
			
		||||
		"function_tags": functionTags,
 | 
			
		||||
	})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,18 @@ module example.com/api
 | 
			
		|||
 | 
			
		||||
replace example.com/database/commands => ../database/commands
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
| 
						 | 
				
			
			@ -14,6 +26,12 @@ 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
 | 
			
		||||
	github.com/gin-gonic/gin v1.10.0
 | 
			
		||||
	github.com/xyproto/randomstring v1.2.0
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,15 @@
 | 
			
		|||
package authdiscord
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	configserver "example.com/config/server"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"github.com/ravener/discord-oauth2"
 | 
			
		||||
	"golang.org/x/oauth2"
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -33,6 +38,27 @@ type DiscordUser struct {
 | 
			
		|||
	Premium_Type  float64 `json:"premium_type"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (discordUser *DiscordUser) GetDiscordUser(context *gin.Context, oauthToken *oauth2.Token, appConfig configserver.AppConfig, oauthConfig *oauth2.Config) {
 | 
			
		||||
	response, err := oauthConfig.Client(context, oauthToken).Get("https://discord.com/api/users/@me")
 | 
			
		||||
	if err != nil || response.StatusCode != 200 {
 | 
			
		||||
		responseMessage := ""
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			responseMessage = err.Error()
 | 
			
		||||
		} else {
 | 
			
		||||
			responseMessage = response.Status
 | 
			
		||||
		}
 | 
			
		||||
		log.Println(responseMessage)
 | 
			
		||||
		log.Println("Assuming the Discord OAuth Key has expired.")
 | 
			
		||||
		context.Redirect(http.StatusUnauthorized, fmt.Sprintf("%slogout", appConfig.GetFrontendRootDomain()))
 | 
			
		||||
	}
 | 
			
		||||
	defer response.Body.Close()
 | 
			
		||||
	body, err := io.ReadAll(response.Body)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Println(err)
 | 
			
		||||
	}
 | 
			
		||||
	json.Unmarshal(body, &discordUser)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDiscordOAuthConfig(config configserver.AppConfig) *oauth2.Config {
 | 
			
		||||
	protocolString := ""
 | 
			
		||||
	if config.API.Https {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,12 +2,42 @@ module example.com/auth/discord
 | 
			
		|||
 | 
			
		||||
replace example.com/config/server => ../../config/server
 | 
			
		||||
 | 
			
		||||
replace example.com/api => ../../api
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/config/server v0.0.0
 | 
			
		||||
	github.com/gin-gonic/gin v1.10.0
 | 
			
		||||
	github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3
 | 
			
		||||
	golang.org/x/oauth2 v0.29.0
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require github.com/pelletier/go-toml/v2 v2.2.4 // indirect
 | 
			
		||||
require (
 | 
			
		||||
	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
 | 
			
		||||
	github.com/cloudwego/iasm v0.2.0 // indirect
 | 
			
		||||
	github.com/gabriel-vasile/mimetype v1.4.3 // indirect
 | 
			
		||||
	github.com/gin-contrib/sse v0.1.0 // indirect
 | 
			
		||||
	github.com/go-playground/locales v0.14.1 // indirect
 | 
			
		||||
	github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
			
		||||
	github.com/go-playground/validator/v10 v10.20.0 // indirect
 | 
			
		||||
	github.com/goccy/go-json v0.10.2 // indirect
 | 
			
		||||
	github.com/json-iterator/go v1.1.12 // indirect
 | 
			
		||||
	github.com/klauspost/cpuid/v2 v2.2.7 // indirect
 | 
			
		||||
	github.com/leodido/go-urn v1.4.0 // indirect
 | 
			
		||||
	github.com/mattn/go-isatty v0.0.20 // indirect
 | 
			
		||||
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 | 
			
		||||
	github.com/modern-go/reflect2 v1.0.2 // indirect
 | 
			
		||||
	github.com/pelletier/go-toml/v2 v2.2.4 // indirect
 | 
			
		||||
	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 | 
			
		||||
	github.com/ugorji/go/codec v1.2.12 // indirect
 | 
			
		||||
	golang.org/x/arch v0.8.0 // indirect
 | 
			
		||||
	golang.org/x/crypto v0.23.0 // indirect
 | 
			
		||||
	golang.org/x/net v0.25.0 // indirect
 | 
			
		||||
	golang.org/x/sys v0.20.0 // indirect
 | 
			
		||||
	golang.org/x/text v0.15.0 // indirect
 | 
			
		||||
	google.golang.org/protobuf v1.34.1 // indirect
 | 
			
		||||
	gopkg.in/yaml.v3 v3.0.1 // indirect
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,89 @@
 | 
			
		|||
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
 | 
			
		||||
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
 | 
			
		||||
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
 | 
			
		||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
 | 
			
		||||
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
 | 
			
		||||
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
 | 
			
		||||
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
 | 
			
		||||
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
 | 
			
		||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
			
		||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
			
		||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
			
		||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
 | 
			
		||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
 | 
			
		||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 | 
			
		||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
			
		||||
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
 | 
			
		||||
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
 | 
			
		||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
 | 
			
		||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
			
		||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
 | 
			
		||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
 | 
			
		||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
 | 
			
		||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 | 
			
		||||
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
 | 
			
		||||
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
 | 
			
		||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
 | 
			
		||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 | 
			
		||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
 | 
			
		||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 | 
			
		||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 | 
			
		||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 | 
			
		||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
 | 
			
		||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
 | 
			
		||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
 | 
			
		||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
 | 
			
		||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
 | 
			
		||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
 | 
			
		||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
 | 
			
		||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 | 
			
		||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 | 
			
		||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
			
		||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
 | 
			
		||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
			
		||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
 | 
			
		||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 | 
			
		||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
 | 
			
		||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
 | 
			
		||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 | 
			
		||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
			
		||||
github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3 h1:x3LgcvujjG+mx8PUMfPmwn3tcu2aA95uCB6ilGGObWk=
 | 
			
		||||
github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3/go.mod h1:P/mZMYLZ87lqRSECEWsOqywGrO1hlZkk9RTwEw35IP4=
 | 
			
		||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
			
		||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 | 
			
		||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
 | 
			
		||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 | 
			
		||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
			
		||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
			
		||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 | 
			
		||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 | 
			
		||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
 | 
			
		||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 | 
			
		||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
 | 
			
		||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
 | 
			
		||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
 | 
			
		||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
 | 
			
		||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
 | 
			
		||||
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
 | 
			
		||||
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
 | 
			
		||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
 | 
			
		||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
 | 
			
		||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
 | 
			
		||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
 | 
			
		||||
golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98=
 | 
			
		||||
golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
 | 
			
		||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
 | 
			
		||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
			
		||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
 | 
			
		||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 | 
			
		||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
 | 
			
		||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
 | 
			
		||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
 | 
			
		||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
			
		||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
 | 
			
		||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
package configserver
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
| 
						 | 
				
			
			@ -14,13 +15,36 @@ type AppConfig struct {
 | 
			
		|||
		Port   string
 | 
			
		||||
		Https  bool
 | 
			
		||||
	}
 | 
			
		||||
	Frontend struct {
 | 
			
		||||
		Domain string
 | 
			
		||||
		Port   string
 | 
			
		||||
		Https  bool
 | 
			
		||||
	}
 | 
			
		||||
	OAuth struct {
 | 
			
		||||
		ClientID     string
 | 
			
		||||
		ClientSecret string
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ParseConfig(configPath string) AppConfig {
 | 
			
		||||
func (config AppConfig) GetAPIRootDomain() string {
 | 
			
		||||
	protocol := "http://"
 | 
			
		||||
	if config.API.Https {
 | 
			
		||||
		protocol = "https://"
 | 
			
		||||
	}
 | 
			
		||||
	log.Println(config.API)
 | 
			
		||||
	return fmt.Sprintf("%s%s:%s/", protocol, config.API.Domain, config.API.Port)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (config AppConfig) GetFrontendRootDomain() string {
 | 
			
		||||
	protocol := "http://"
 | 
			
		||||
	if config.Frontend.Https {
 | 
			
		||||
		protocol = "https://"
 | 
			
		||||
	}
 | 
			
		||||
	log.Println(config.Frontend)
 | 
			
		||||
	return fmt.Sprintf("%s%s:%s/", protocol, config.Frontend.Domain, config.Frontend.Port)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (config *AppConfig) ParseConfig(configPath string) {
 | 
			
		||||
	configFile, err := os.Open(configPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
| 
						 | 
				
			
			@ -29,10 +53,8 @@ func ParseConfig(configPath string) AppConfig {
 | 
			
		|||
	if err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	var configObject AppConfig
 | 
			
		||||
	err = toml.Unmarshal(configFileContent, &configObject)
 | 
			
		||||
	err = toml.Unmarshal(configFileContent, &config)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	return configObject
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
package databasecommands
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
	functiontag "example.com/database/functiontag"
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	databasemodels "example.com/database/models"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/driver/sqlite"
 | 
			
		||||
| 
						 | 
				
			
			@ -17,10 +19,10 @@ func InitializeDatabase() *gorm.DB {
 | 
			
		|||
	}
 | 
			
		||||
	db.AutoMigrate(
 | 
			
		||||
		&databasemodels.User{},
 | 
			
		||||
		&databasemodels.Group{},
 | 
			
		||||
		&databasemodels.FunctionTag{},
 | 
			
		||||
		&group.Group{},
 | 
			
		||||
		&functiontag.FunctionTag{},
 | 
			
		||||
		&databasemodels.ItemTag{},
 | 
			
		||||
		&databasemodels.Function{},
 | 
			
		||||
		&function.Function{},
 | 
			
		||||
		&databasemodels.FunctionSet{},
 | 
			
		||||
		&databasemodels.Tier{},
 | 
			
		||||
		&databasemodels.Role{},
 | 
			
		||||
| 
						 | 
				
			
			@ -34,681 +36,6 @@ func InitializeDatabase() *gorm.DB {
 | 
			
		|||
	return db
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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 CreateDatabaseGroup(db *gorm.DB, group databasemodels.Group) error {
 | 
			
		||||
	result := db.Create(&group)
 | 
			
		||||
	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 CreateDatabaseFunction(db *gorm.DB, function databasemodels.Function) error {
 | 
			
		||||
	result := db.Create(&function)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateDatabaseFunctionTag(db *gorm.DB, functionTag databasemodels.FunctionTag) error {
 | 
			
		||||
	result := db.Create(&functionTag)
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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 GetDatabaseGroup(db *gorm.DB, inputGroup string) databasemodels.Group {
 | 
			
		||||
	var outputGroup databasemodels.Group
 | 
			
		||||
	result := db.Model(&databasemodels.Group{}).Where("name = ?", inputGroup).Take(&outputGroup)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Group{}
 | 
			
		||||
	}
 | 
			
		||||
	return outputGroup
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseGroups(db *gorm.DB, inputGroups []string) []databasemodels.Group {
 | 
			
		||||
	var outputGroups []databasemodels.Group
 | 
			
		||||
	for _, inputGroup := range inputGroups {
 | 
			
		||||
		outputGroups = append(outputGroups, GetDatabaseGroup(db, inputGroup))
 | 
			
		||||
	}
 | 
			
		||||
	return outputGroups
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseGroups(db *gorm.DB) []databasemodels.Group {
 | 
			
		||||
	var outputGroups []databasemodels.Group
 | 
			
		||||
	result := db.Find(&outputGroups)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputGroup := range outputGroups {
 | 
			
		||||
		outputGroups[index] = GetDatabaseGroup(db, outputGroup.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputGroups
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 GetDatabaseFunction(db *gorm.DB, inputFunction string) databasemodels.Function {
 | 
			
		||||
	var outputFunction databasemodels.Function
 | 
			
		||||
	result := db.Model(&databasemodels.Function{}).Where("name = ?", inputFunction).Take(&outputFunction)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.Function{}
 | 
			
		||||
	}
 | 
			
		||||
	db.Model(&outputFunction).Association("Tags").Find(&outputFunction.Tags)
 | 
			
		||||
	db.Model(&outputFunction).Association("Requirements").Find(&outputFunction.Requirements)
 | 
			
		||||
	return outputFunction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctions(db *gorm.DB, inputFunctions []string) []databasemodels.Function {
 | 
			
		||||
	var outputFunctions []databasemodels.Function
 | 
			
		||||
	for _, inputFunction := range inputFunctions {
 | 
			
		||||
		outputFunctions = append(outputFunctions, GetDatabaseFunction(db, inputFunction))
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctions
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseFunctions(db *gorm.DB) []databasemodels.Function {
 | 
			
		||||
	var outputFunctions []databasemodels.Function
 | 
			
		||||
	result := db.Find(&outputFunctions)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputFunction := range outputFunctions {
 | 
			
		||||
		outputFunctions[index] = GetDatabaseFunction(db, outputFunction.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctions
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctionTag(db *gorm.DB, inputFunctionTag string) databasemodels.FunctionTag {
 | 
			
		||||
	var outputFunctionTag databasemodels.FunctionTag
 | 
			
		||||
	result := db.Model(&databasemodels.FunctionTag{}).Where("name = ?", inputFunctionTag).Take(&outputFunctionTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return databasemodels.FunctionTag{}
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctionTag
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDatabaseFunctionTags(db *gorm.DB, inputFunctionTags []string) []databasemodels.FunctionTag {
 | 
			
		||||
	var outputFunctionTags []databasemodels.FunctionTag
 | 
			
		||||
	for _, inputFunctionTag := range inputFunctionTags {
 | 
			
		||||
		outputFunctionTags = append(outputFunctionTags, GetDatabaseFunctionTag(db, inputFunctionTag))
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctionTags
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllDatabaseFunctionTags(db *gorm.DB) []databasemodels.FunctionTag {
 | 
			
		||||
	var outputFunctionTags []databasemodels.FunctionTag
 | 
			
		||||
	result := db.Find(&outputFunctionTags)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	for index, outputFunctionTag := range outputFunctionTags {
 | 
			
		||||
		outputFunctionTags[index] = GetDatabaseFunctionTag(db, outputFunctionTag.Name)
 | 
			
		||||
	}
 | 
			
		||||
	return outputFunctionTags
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Update Functions
 | 
			
		||||
 | 
			
		||||
func LogoutDatabaseUser(db *gorm.DB, oauthToken string) {
 | 
			
		||||
	db.Model(&databasemodels.User{}).Where("login_token = ?", oauthToken).Update("logged_in", false)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 UpdateDatabaseGroup(db *gorm.DB, group databasemodels.Group) error {
 | 
			
		||||
	result := db.Save(&group)
 | 
			
		||||
	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 UpdateDatabaseFunction(db *gorm.DB, function databasemodels.Function) error {
 | 
			
		||||
	result := db.Save(&function)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func UpdateDatabaseFunctionTag(db *gorm.DB, functionTag databasemodels.FunctionTag) error {
 | 
			
		||||
	result := db.Save(&functionTag)
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Delete Functions
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										97
									
								
								src/lib/database/commands/create/create.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/lib/database/commands/create/create.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,97 @@
 | 
			
		|||
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
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/lib/database/commands/create/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/lib/database/commands/create/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
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
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/commands/create/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/commands/create/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=
 | 
			
		||||
							
								
								
									
										3
									
								
								src/lib/database/commands/delete/delete.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/lib/database/commands/delete/delete.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
package delete
 | 
			
		||||
 | 
			
		||||
// Delete Functions
 | 
			
		||||
							
								
								
									
										3
									
								
								src/lib/database/commands/delete/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/lib/database/commands/delete/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
module gin-cpularp
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
							
								
								
									
										366
									
								
								src/lib/database/commands/get/get.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										366
									
								
								src/lib/database/commands/get/get.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,366 @@
 | 
			
		|||
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
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/lib/database/commands/get/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/lib/database/commands/get/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
module example.com/database/commands/get
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/commands/get/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/commands/get/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=
 | 
			
		||||
| 
						 | 
				
			
			@ -4,12 +4,24 @@ go 1.24.2
 | 
			
		|||
 | 
			
		||||
replace example.com/database/models => ../models
 | 
			
		||||
 | 
			
		||||
replace example.com/database/group => ../group
 | 
			
		||||
 | 
			
		||||
replace example.com/database/function => ../function
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/models v0.0.0
 | 
			
		||||
	gorm.io/driver/sqlite v1.5.7 // direct
 | 
			
		||||
	gorm.io/gorm v1.25.12 // direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require example.com/database/group v0.0.0
 | 
			
		||||
 | 
			
		||||
require example.com/database/function v0.0.0
 | 
			
		||||
 | 
			
		||||
require example.com/database/functiontag v0.0.0
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								src/lib/database/commands/update/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/lib/database/commands/update/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
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
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										8
									
								
								src/lib/database/commands/update/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/commands/update/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=
 | 
			
		||||
							
								
								
									
										97
									
								
								src/lib/database/commands/update/update.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/lib/database/commands/update/update.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,97 @@
 | 
			
		|||
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
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										64
									
								
								src/lib/database/function/function.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/lib/database/function/function.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,64 @@
 | 
			
		|||
package function
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	functiontag "example.com/database/functiontag"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Function struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name         string                    `gorm:"primaryKey uniqueIndex index" json:"name"`
 | 
			
		||||
	Tags         []functiontag.FunctionTag `gorm:"many2many:function_tag_associations" json:"tags"`
 | 
			
		||||
	Requirements []Function                `gorm:"many2many:function_requirement_associations" json:"requirements"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (function *Function) getAssociations(db *gorm.DB) {
 | 
			
		||||
	db.Model(&function).Association("Tags").Find(&function.Tags)
 | 
			
		||||
	db.Model(&function).Association("Requirements").Find(&function.Requirements)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
	result := db.Save(&function)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (function Function) Create(db *gorm.DB) error {
 | 
			
		||||
	result := db.Create(&function)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Get(db *gorm.DB, inputFunctions []string) *[]Function {
 | 
			
		||||
	var outputFunctions []Function
 | 
			
		||||
	for _, inputFunction := range inputFunctions {
 | 
			
		||||
		var outputFunction Function
 | 
			
		||||
		outputFunction.Get(db, inputFunction)
 | 
			
		||||
		outputFunctions = append(outputFunctions, outputFunction)
 | 
			
		||||
	}
 | 
			
		||||
	return &outputFunctions
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAll(db *gorm.DB) *[]Function {
 | 
			
		||||
	var outputFunctions []Function
 | 
			
		||||
	var outputFunctionNames []string
 | 
			
		||||
	result := db.Model(&Function{}).Select("name").Find(&outputFunctionNames)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	outputFunctions = *Get(db, outputFunctionNames)
 | 
			
		||||
	return &outputFunctions
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/lib/database/function/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/lib/database/function/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
module example.com/database/function
 | 
			
		||||
 | 
			
		||||
go 1.24.2
 | 
			
		||||
 | 
			
		||||
replace example.com/database/functiontag => ../functiontag
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	example.com/database/functiontag 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/function/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/function/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=
 | 
			
		||||
							
								
								
									
										53
									
								
								src/lib/database/functiontag/functiontag.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/lib/database/functiontag/functiontag.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,53 @@
 | 
			
		|||
package functiontag
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type FunctionTag struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name string `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (functionTag *FunctionTag) Get(db *gorm.DB, inputFunctionTag string) {
 | 
			
		||||
	db.Where("name = ?", inputFunctionTag).Take(&functionTag)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (functionTag FunctionTag) Update(db *gorm.DB) error {
 | 
			
		||||
	result := db.Save(&functionTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (functionTag FunctionTag) Create(db *gorm.DB) error {
 | 
			
		||||
	result := db.Create(&functionTag)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Get(db *gorm.DB, inputFunctionTags []string) *[]FunctionTag {
 | 
			
		||||
	var outputFunctionTags []FunctionTag
 | 
			
		||||
	for _, inputFunctionTag := range inputFunctionTags {
 | 
			
		||||
		var outputFunctionTag FunctionTag
 | 
			
		||||
		outputFunctionTag.Get(db, inputFunctionTag)
 | 
			
		||||
		outputFunctionTags = append(outputFunctionTags, outputFunctionTag)
 | 
			
		||||
	}
 | 
			
		||||
	return &outputFunctionTags
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAll(db *gorm.DB) *[]FunctionTag {
 | 
			
		||||
	var outputFunctionTags []FunctionTag
 | 
			
		||||
	var outputFunctionTagNames []string
 | 
			
		||||
	result := db.Model(&FunctionTag{}).Select("name").Find(&outputFunctionTagNames)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	outputFunctionTags = *Get(db, outputFunctionTagNames)
 | 
			
		||||
	return &outputFunctionTags
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/lib/database/functiontag/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/lib/database/functiontag/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
module example.com/database/functiontag
 | 
			
		||||
 | 
			
		||||
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/functiontag/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/functiontag/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=
 | 
			
		||||
							
								
								
									
										13
									
								
								src/lib/database/group/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/lib/database/group/go.mod
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
module example.com/database/group
 | 
			
		||||
 | 
			
		||||
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/group/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/database/group/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=
 | 
			
		||||
							
								
								
									
										53
									
								
								src/lib/database/group/group.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/lib/database/group/group.go
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,53 @@
 | 
			
		|||
package group
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Group struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name string `gorm:"primaryKey" json:"name"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (group *Group) Get(db *gorm.DB, inputGroup string) {
 | 
			
		||||
	db.Model(&Group{}).Where("name = ?", inputGroup).Take(&group)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (group Group) Update(db *gorm.DB) error {
 | 
			
		||||
	result := db.Save(&group)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (group Group) Create(db *gorm.DB) error {
 | 
			
		||||
	result := db.Create(&group)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		return result.Error
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Get(db *gorm.DB, inputGroups []string) *[]Group {
 | 
			
		||||
	var outputGroups []Group
 | 
			
		||||
	for _, inputGroup := range inputGroups {
 | 
			
		||||
		var outputGroup Group
 | 
			
		||||
		outputGroup.Get(db, inputGroup)
 | 
			
		||||
		outputGroups = append(outputGroups, outputGroup)
 | 
			
		||||
	}
 | 
			
		||||
	return &outputGroups
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAll(db *gorm.DB) *[]Group {
 | 
			
		||||
	var outputGroups []Group
 | 
			
		||||
	var outputGroupNames []string
 | 
			
		||||
	result := db.Model(&Group{}).Select("name").Find(&outputGroupNames)
 | 
			
		||||
	if result.Error != nil {
 | 
			
		||||
		log.Println(result.Error)
 | 
			
		||||
	}
 | 
			
		||||
	outputGroups = *Get(db, outputGroupNames)
 | 
			
		||||
	return &outputGroups
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,8 +2,20 @@ module example.com/database/models
 | 
			
		|||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
require example.com/database/group v0.0.0
 | 
			
		||||
 | 
			
		||||
require example.com/database/function v0.0.0
 | 
			
		||||
 | 
			
		||||
require example.com/database/functiontag v0.0.0 // indirect
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/jinzhu/inflection v1.0.0 // indirect
 | 
			
		||||
	github.com/jinzhu/now v1.1.5 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,10 @@
 | 
			
		|||
package databasemodels
 | 
			
		||||
 | 
			
		||||
import "gorm.io/gorm"
 | 
			
		||||
import (
 | 
			
		||||
	function "example.com/database/function"
 | 
			
		||||
	group "example.com/database/group"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type User struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
| 
						 | 
				
			
			@ -19,13 +23,8 @@ type User struct {
 | 
			
		|||
 | 
			
		||||
type Person struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name   string  `gorm:"primaryKey" json:"name"`
 | 
			
		||||
	Groups []Group `gorm:"many2many:person_group_associations" json:"groups"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Group struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name string `gorm:"primaryKey" json:"name"`
 | 
			
		||||
	Name   string        `gorm:"primaryKey" json:"name"`
 | 
			
		||||
	Groups []group.Group `gorm:"many2many:person_group_associations" json:"groups"` // Unique
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Character struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -39,9 +38,9 @@ type Character struct {
 | 
			
		|||
 | 
			
		||||
type Role struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name       string  `gorm:"primaryKey" json:"name"`
 | 
			
		||||
	Tiers      []Tier  `gorm:"many2many:role_tier_associations" json:"tiers"`
 | 
			
		||||
	Visibility []Group `gorm:"many2many:role_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
	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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -51,19 +50,7 @@ type Tier struct {
 | 
			
		|||
 | 
			
		||||
type FunctionSet struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Functions []Function `gorm:"many2many:functionset_function_associations" json:"functions"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Function struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name         string        `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
	Tags         []FunctionTag `gorm:"many2many:function_tag_associations" json:"tags"`
 | 
			
		||||
	Requirements []Function    `gorm:"many2many:function_requirement_associations" json:"requirements"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type FunctionTag struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name string `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
	Functions []function.Function `gorm:"many2many:functionset_function_associations" json:"functions"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type InventorySlot struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -74,14 +61,14 @@ type InventorySlot struct {
 | 
			
		|||
 | 
			
		||||
type Item struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name                string          `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
	Functions           []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         `gorm:"many2many:item_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
	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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -91,21 +78,21 @@ type ItemTag struct {
 | 
			
		|||
 | 
			
		||||
type Customization struct {
 | 
			
		||||
	gorm.Model
 | 
			
		||||
	Name                string     `gorm:"primaryKey uniqueIndex" json:"name"`
 | 
			
		||||
	Functions           []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    `gorm:"many2many:customization_visibility_associations" json:"visibility"` // Unique
 | 
			
		||||
	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      `gorm:"many2many:schematic_requirement_associations" json:"requirements"`
 | 
			
		||||
	TimeUnits    int64           `json:"time_units"` // Positive
 | 
			
		||||
	Result       InventorySlot   `gorm:"many2many:schematic_result_associations" json:"result"`
 | 
			
		||||
	Visibility   []Group         `gorm:"many2many:schematic_group_associations" json:"visibility"` // Unique
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue