update imports

This commit is contained in:
tengge 2020-05-15 20:54:35 +08:00
parent 2cba38e226
commit ba78bd2acb
11 changed files with 26 additions and 25 deletions

View File

@ -336,6 +336,7 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tengge1/shadoweditor/server v0.0.0-20200504012303-9192fe9f226c h1:aGG7kofghI2qpKsHd7KOv0rwi1oJgnjHfZBcA71UekU=
github.com/tengge1/shadoweditor/server v0.0.0-20200504015715-5596e62b74dd h1:ZpiaZOrKlNkjzq83r8k5cT8VKKbiwQe+BCCaZrFDmZs=
github.com/tengge1/shadoweditor/server v0.0.0-20200515121047-ca1a176ced6d h1:vwCkoiaDr1Vmm+MxutDk9QypE7axDgISzDzGUOBnkDM=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.0.1 h1:WE4RBSZ1x6McVVC8S/Md+Qse8YUv6HRObAx6ke00NY8=

View File

@ -5,7 +5,7 @@
// For more information, please visit: https://github.com/tengge1/ShadowEditor
// You can also visit: https://gitee.com/tengge1/ShadowEditor
package model
package system
// Config is mongodb config collection model.
type Config struct {

View File

@ -15,7 +15,7 @@ import (
"github.com/tengge1/shadoweditor/helper"
"github.com/tengge1/shadoweditor/server"
"github.com/tengge1/shadoweditor/server/system/model"
"github.com/tengge1/shadoweditor/server/system"
)
func init() {
@ -30,7 +30,7 @@ func Get(w http.ResponseWriter, r *http.Request) {
return
}
config := model.Config{}
config := system.Config{}
find, err := db.FindOne(server.ConfigCollectionName, bson.M{}, &config)
if err != nil {
helper.WriteJSON(w, server.Result{

View File

@ -5,7 +5,7 @@
// For more information, please visit: https://github.com/tengge1/ShadowEditor
// You can also visit: https://gitee.com/tengge1/ShadowEditor
package model
package system
// Department is user department model.
type Department struct {

View File

@ -14,7 +14,7 @@ import (
"github.com/tengge1/shadoweditor/helper"
"github.com/tengge1/shadoweditor/server"
"github.com/tengge1/shadoweditor/server/system/model"
"github.com/tengge1/shadoweditor/server/system"
)
func init() {
@ -30,7 +30,7 @@ func List(w http.ResponseWriter, r *http.Request) {
}
// get all the users
users := []model.User{}
users := []system.User{}
err = db.FindMany(server.UserCollectionName, bson.M{}, &users)
if err != nil {
@ -43,7 +43,7 @@ func List(w http.ResponseWriter, r *http.Request) {
"Status": 0,
}
list := []model.Department{}
list := []system.Department{}
err = db.FindMany(server.DepartmentCollectionName, filter, &list)
if err != nil {
@ -53,7 +53,7 @@ func List(w http.ResponseWriter, r *http.Request) {
for key := range list {
adminID := list[key].AdminID
var admin model.User
var admin system.User
for _, user := range users {
if user.ID == adminID {

View File

@ -5,7 +5,7 @@
// For more information, please visit: https://github.com/tengge1/ShadowEditor
// You can also visit: https://gitee.com/tengge1/ShadowEditor
package model
package system
import "time"

View File

@ -18,7 +18,7 @@ import (
"github.com/tengge1/shadoweditor/helper"
"github.com/tengge1/shadoweditor/server"
"github.com/tengge1/shadoweditor/server/system/model"
"github.com/tengge1/shadoweditor/server/system"
)
func init() {
@ -90,11 +90,11 @@ func List(w http.ResponseWriter, r *http.Request) {
return
}
rows := []model.Role{}
rows := []system.Role{}
for _, doc := range docs {
data := doc.(primitive.D).Map()
rows = append(rows, model.Role{
rows = append(rows, system.Role{
ID: data["ID"].(primitive.ObjectID).Hex(),
Name: data["Name"].(string),
CreateTime: data["CreateTime"].(primitive.DateTime).Time(),

View File

@ -5,7 +5,7 @@
// For more information, please visit: https://github.com/tengge1/ShadowEditor
// You can also visit: https://gitee.com/tengge1/ShadowEditor
package model
package system
// RoleAuthority presents a role's one authority.
type RoleAuthority struct {

View File

@ -5,7 +5,7 @@
// For more information, please visit: https://github.com/tengge1/ShadowEditor
// You can also visit: https://gitee.com/tengge1/ShadowEditor
package model
package system
import "time"

View File

@ -18,7 +18,7 @@ import (
"github.com/tengge1/shadoweditor/helper"
"github.com/tengge1/shadoweditor/server"
"github.com/tengge1/shadoweditor/server/system/model"
"github.com/tengge1/shadoweditor/server/system"
)
func init() {
@ -48,11 +48,11 @@ func List(w http.ResponseWriter, r *http.Request) {
}
// get all roles
roles := []model.Role{}
roles := []system.Role{}
db.FindAll(server.RoleCollectionName, &roles)
// get all departments
depts := []model.Department{}
depts := []system.Department{}
db.FindAll(server.DepartmentCollectionName, &depts)
// get users
@ -104,7 +104,7 @@ func List(w http.ResponseWriter, r *http.Request) {
docs := bson.A{}
db.FindMany(server.UserCollectionName, filter, &docs, &opts)
rows := []model.User{}
rows := []system.User{}
for _, doc := range docs {
data := doc.(primitive.D).Map()
@ -133,7 +133,7 @@ func List(w http.ResponseWriter, r *http.Request) {
}
}
rows = append(rows, model.User{
rows = append(rows, system.User{
ID: data["ID"].(primitive.ObjectID).Hex(),
Username: data["Username"].(string),
Password: "",

View File

@ -15,12 +15,12 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"github.com/tengge1/shadoweditor/server/system/model"
"github.com/tengge1/shadoweditor/server/system"
)
// GetCurrentUser get the current login user.
// It gets userID from the cookie.
func GetCurrentUser(r *http.Request) (*model.User, error) {
func GetCurrentUser(r *http.Request) (*system.User, error) {
cookies := r.Cookies()
if len(cookies) == 0 {
@ -49,7 +49,7 @@ func GetCurrentUser(r *http.Request) (*model.User, error) {
}
// GetUser get a user from userID.
func GetUser(userID string) (*model.User, error) {
func GetUser(userID string) (*system.User, error) {
objectID, err := primitive.ObjectIDFromHex(userID)
if err != nil {
return nil, err
@ -64,7 +64,7 @@ func GetUser(userID string) (*model.User, error) {
"ID": objectID,
}
user := model.User{}
user := system.User{}
find, err := mongo.FindOne(UserCollectionName, filter, &user)
if err != nil {
@ -85,7 +85,7 @@ func GetUser(userID string) (*model.User, error) {
"ID": objectID,
}
role := model.Role{}
role := system.Role{}
find, err = mongo.FindOne(RoleCollectionName, filter, &role)
if err != nil {
return nil, err
@ -111,7 +111,7 @@ func GetUser(userID string) (*model.User, error) {
}
for cursor.Next(context.TODO()) {
authority := model.RoleAuthority{}
authority := system.RoleAuthority{}
cursor.Decode(&authority)
user.OperatingAuthorities = append(user.OperatingAuthorities, authority.AuthorityID)