This commit is contained in:
Tiger Wang 2022-07-07 11:41:29 -04:00
parent 3463de85ee
commit a55a5fe361
3 changed files with 11 additions and 3 deletions

View File

@ -37,6 +37,10 @@ func InitRouter() *gin.Engine {
r.POST("/v1/user/register/:key", v1.PostUserRegister)
r.POST("/v1/user/login", v1.PostUserLogin) //
// @tiger - 如果遵循 RESTful 规范name 本身并不是资源,而是属性;资源是 user
// 所以正规的方法是 改成 /v1/users 然后返回所有的 user 对象,具体 name 由前端自行抽取
// 不正规的方式是 改成 /v1/users/names假定 name 也是资源
r.GET("/v1/user/all/name", v1.GetUserAllUserName)
r.GET("/v1/sys/init/check", v1.GetSystemInitCheck)

View File

@ -95,6 +95,8 @@ func PostUserLogin(c *gin.Context) {
c.BindJSON(&json)
username := json["username"]
// @tiger - 字段命名要一直,在注册的时候如果用 password这里也要用 password
pwd := json["pwd"]
//check params is empty
if len(username) == 0 || len(pwd) == 0 {
@ -123,6 +125,8 @@ func PostUserLogin(c *gin.Context) {
data := make(map[string]interface{}, 2)
user.Password = ""
data["token"] = token
// @tiger - 不建议直接透传数据库对象,而是适配到用于 API 输出的 model 对象
data["user"] = user
c.JSON(http.StatusOK,
@ -368,7 +372,7 @@ func GetUserInfoByUserName(c *gin.Context) {
}
/**
* @description: get all user name
* @description: get all usernames
* @method:GET
* @router:/user/all/name
*/

View File

@ -15,11 +15,11 @@ import "time"
//Soon to be removed
type UserDBModel struct {
Id int `gorm:"column:id;primary_key" json:"id"`
UserName string `json:"user_name"`
UserName string `json:"user_name"` // @tiger - user_name 改 username
Password string `json:"password,omitempty"`
Role string `json:"role"`
Email string `json:"email"`
NickName string `json:"nick_name"`
NickName string `json:"nick_name"` // @tiger - nick_name 改 nickname
Avatar string `json:"avatar"`
Description string `json:"description"`
CreatedAt time.Time `gorm:"<-:create;autoCreateTime" json:"created_at,omitempty"`