Allow get realm by numeric auto increment id

This commit is contained in:
LittleSheep 2024-11-16 21:36:34 +08:00
parent 40b64a3559
commit f91be512f3
3 changed files with 24 additions and 26 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="dataSourceStorageLocal" created-in="GO-242.23339.24">
<component name="dataSourceStorageLocal" created-in="GO-243.21565.208">
<data-source name="hy_passport@localhost" uuid="74bcf3ef-a2b9-435b-b9e5-f32902a33b25">
<database-info product="PostgreSQL" version="16.4 (Homebrew)" jdbc-version="4.2" driver-name="PostgreSQL JDBC Driver" driver-version="42.6.0" dbms="POSTGRES" exact-version="16.4" exact-driver-version="42.6">
<identifier-quote-string>&quot;</identifier-quote-string>

36
.idea/workspace.xml generated
View File

@ -4,13 +4,9 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Authkit can get user">
<change beforePath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" afterDir="false" />
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix auth cache">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/cache/store.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/cache/store.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/auth.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/realms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/realms.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -52,9 +48,10 @@
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"DefaultGoTemplateProperty": "Go File",
"Go Build.Backend.executor": "Run",
"Go Build.Backend.executor": "Debug",
"Go 构建.Backend.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"RunOnceActivity.go.formatter.settings.were.checked": "true",
"RunOnceActivity.go.migrated.go.modules.settings": "true",
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
@ -120,8 +117,8 @@
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-gosdk-5df93f7ad4aa-df9ad98b711f-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-242.23339.24" />
<option value="bundled-js-predefined-d6986cc7102b-5c90d61e3bab-JavaScript-GO-242.23339.24" />
<option value="bundled-gosdk-d297c17c1fbd-b87a2f8923ed-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-243.21565.208" />
<option value="bundled-js-predefined-d6986cc7102b-e768b9ed790e-JavaScript-GO-243.21565.208" />
</set>
</attachedChunks>
</component>
@ -162,7 +159,6 @@
</component>
<component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<MESSAGE value=":bug: Bug fixes in non-cached notification preferences" />
<MESSAGE value=":alien: Support better metadata encoder / decoder" />
<MESSAGE value=":bug: Bug fixes on compile time" />
<MESSAGE value=":bug: Fix notification order" />
@ -187,7 +183,8 @@
<MESSAGE value=":recycle: Replace nil context with context.Background in authkit" />
<MESSAGE value=":sparkles: Authkit support check user related permission" />
<MESSAGE value=":sparkles: Authkit can get user" />
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Authkit can get user" />
<MESSAGE value=":bug: Fix auth cache" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix auth cache" />
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
</component>
<component name="VgoProject">
@ -197,19 +194,14 @@
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/pkg/internal/services/auth.go</url>
<line>105</line>
<option name="timeStamp" value="5" />
<url>file://$PROJECT_DIR$/pkg/internal/services/factors.go</url>
<line>85</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/pkg/internal/services/auth.go</url>
<line>90</line>
<option name="timeStamp" value="6" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/pkg/internal/services/auth.go</url>
<line>45</line>
<option name="timeStamp" value="7" />
<url>file://$PROJECT_DIR$/pkg/internal/http/api/factors_api.go</url>
<line>35</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>

View File

@ -5,6 +5,7 @@ import (
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
"github.com/samber/lo"
"strconv"
)
func ListCommunityRealm() ([]models.Realm, error) {
@ -48,10 +49,15 @@ func ListAvailableRealm(user models.Account) ([]models.Realm, error) {
}
func GetRealmWithAlias(alias string) (models.Realm, error) {
tx := database.C.Where("alias = ?", alias)
numericId, err := strconv.Atoi(alias)
if err == nil {
tx.Or("id = ?", numericId)
}
var realm models.Realm
if err := database.C.Where(&models.Realm{
Alias: alias,
}).First(&realm).Error; err != nil {
if err := tx.First(&realm).Error; err != nil {
return realm, err
}
return realm, nil