Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllor/adminAdd.go → adminControllor/adminAdd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion controllor/adminEdit.go → adminControllor/adminEdit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion controllor/adminGet.go → adminControllor/adminGet.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion controllor/adminLogin.go → adminControllor/adminLogin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
81 changes: 81 additions & 0 deletions adminControllor/adminRange.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package adminControllor

import (
"net/http"
"strings"

"github.com/TrafficLight6/GoAccountHub/sqlTable"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)

type AdminRangeRequestBody struct {
//It the Length is -1, It Means Get All Admin from BeginTableId to The End
BeginTableId int `json:"begin_table_id"`
Length int `json:"length"`
SearchCondition AdminSearchCondition `json:"search_condition"`
}

type AdminSearchCondition struct {
//If The Field is Empty, It Means Ignore This Condition
Username string `json:"username"`
PasswordHash string `json:"password_hash"`
UUHash string `json:"uu_hash"`
}

func AdminRange(c *gin.Context) {
var body AdminRangeRequestBody
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "error": "Invalid Request Body"})
c.Abort()
return
}
if body.BeginTableId < 0 {
c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "error": "BeginTableId Begin From 1"})
c.Abort()
return
}
//Check Length is Valid
if body.Length < -1 {
c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "error": "Length Must Be Greater Than -1"})
c.Abort()
return
}
var isReturnAll bool
if body.Length == -1 {
isReturnAll = true
} else {
isReturnAll = false
}
//Get Db
db := c.Value("db").(*gorm.DB)
//Build Search Query (only non-empty fields, combined with AND)
condition := body.SearchCondition
var conditions []string
var args []interface{}
if condition.Username != "" {
conditions = append(conditions, "username LIKE ?")
args = append(args, "%"+condition.Username+"%")
}
if condition.PasswordHash != "" {
conditions = append(conditions, "password_hash LIKE ?")
args = append(args, "%"+condition.PasswordHash+"%")
}
if condition.UUHash != "" {
conditions = append(conditions, "uu_hash LIKE ?")
args = append(args, "%"+condition.UUHash+"%")
}
query := db.Model(&sqlTable.Admin{})
if len(conditions) > 0 {
query = query.Where(strings.Join(conditions, " AND "), args...)
}
//Search
var admins []sqlTable.Admin
if isReturnAll {
query.Find(&admins)
} else {
query.Limit(body.Length).Offset((body.BeginTableId - 1) * body.Length).Find(&admins)
}
//Return Result
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "message": "Success(not include root admin)", "data": admins})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
81 changes: 81 additions & 0 deletions adminControllor/characterRange.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package adminControllor

import (
"net/http"
"strings"

"github.com/TrafficLight6/GoAccountHub/sqlTable"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)

type CharacterRangeRequestBody struct {
//It the Length is -1, It Means Get All User from BeginTableId to The End
BeginTableId int `json:"begin_table_id"`
Length int `json:"length"`
SearchCondition CharacterSearchCondition `json:"search_condition"`
}

type CharacterSearchCondition struct {
//If The Field is Empty, It Means Ignore This Condition
CharacterName string `json:"character_name"`
PasswordHash string `json:"password_hash"`
UserUUHash string `json:"user_uu_hash"`
UUHash string `json:"uu_hash"`
}

func CharacterRange(c *gin.Context) {
var body CharacterRangeRequestBody
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "error": err.Error()})
return
}
//Check Length is Valid
if body.Length < -1 {
c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "error": "Length Must Be Greater Than -1"})
c.Abort()
return
}
var isReturnAll bool
if body.Length == -1 {
isReturnAll = true
} else {
isReturnAll = false
}
//Get Db
db := c.Value("db").(*gorm.DB)
//Build Search Query (only non-empty fields, combined with AND)
condition := body.SearchCondition
var conditions []string
var args []interface{}
if condition.CharacterName != "" {
conditions = append(conditions, "character_name LIKE ?")
args = append(args, "%"+condition.CharacterName+"%")
}
if condition.PasswordHash != "" {
conditions = append(conditions, "password_hash LIKE ?")
args = append(args, "%"+condition.PasswordHash+"%")
}
if condition.UserUUHash != "" {
conditions = append(conditions, "user_uu_hash LIKE ?")
args = append(args, "%"+condition.UserUUHash+"%")
}
if condition.UUHash != "" {
conditions = append(conditions, "uu_hash LIKE ?")
args = append(args, "%"+condition.UUHash+"%")
}
query := db.Model(&sqlTable.Character{})
if len(conditions) > 0 {
query = query.Where(strings.Join(conditions, " AND "), args...)
}
//Search
var characters []sqlTable.Character
if isReturnAll {
query.Find(&characters)
} else {
query.Limit(body.Length).Offset((body.BeginTableId - 1) * body.Length).Find(&characters)
}
//Return Result
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "message": "Success", "data": characters})
return
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion controllor/userAdd.go → adminControllor/userAdd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion controllor/userDelete.go → adminControllor/userDelete.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion controllor/userEdit.go → adminControllor/userEdit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion controllor/userGet.go → adminControllor/userGet.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllor
package adminControllor

import (
"net/http"
Expand Down
82 changes: 82 additions & 0 deletions adminControllor/userRanger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package adminControllor

import (
"net/http"
"strings"

"github.com/TrafficLight6/GoAccountHub/sqlTable"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)

type UserRangeRequestBody struct {
//It the Length is -1, It Means Get All User from BeginTableId to The End
BeginTableId int `json:"begin_table_id"`
Length int `json:"length"`
SearchCondition UserSearchCondition `json:"search_condition"`
}

type UserSearchCondition struct {
//If The Field is Empty, It Means Ignore This Condition
Username string `json:"username"`
PasswordHash string `json:"password_hash"`
UUHash string `json:"uu_hash"`
}

func UserRange(c *gin.Context) {
var body UserRangeRequestBody
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "error": "Invalid Request Body"})
c.Abort()
return
}
if body.BeginTableId < 0 {
c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "error": "BeginTableId Begin From 1"})
c.Abort()
return
}
//Check Length is Valid
if body.Length < -1 {
c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "error": "Length Must Be Greater Than -1"})
c.Abort()
return
}
var isReturnAll bool
if body.Length == -1 {
isReturnAll = true
} else {
isReturnAll = false
}
//Get Db
db := c.Value("db").(*gorm.DB)
//Build Search Query (only non-empty fields, combined with AND)
condition := body.SearchCondition
var conditions []string
var args []interface{}
if condition.Username != "" {
conditions = append(conditions, "username LIKE ?")
args = append(args, "%"+condition.Username+"%")
}
if condition.PasswordHash != "" {
conditions = append(conditions, "password_hash LIKE ?")
args = append(args, "%"+condition.PasswordHash+"%")
}
if condition.UUHash != "" {
conditions = append(conditions, "uu_hash LIKE ?")
args = append(args, "%"+condition.UUHash+"%")
}
query := db.Model(&sqlTable.User{})
if len(conditions) > 0 {
query = query.Where(strings.Join(conditions, " AND "), args...)
}
//Search
var users []sqlTable.User
if isReturnAll {
query.Find(&users)
} else {
query.Limit(body.Length).Offset((body.BeginTableId - 1) * body.Length).Find(&users)
}
//Return Result
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "message": "Success", "data": users})
return
}
Loading
Loading