Completed db rewrite
This commit is contained in:
parent
54d7d14ef9
commit
cf4b8e0119
19 changed files with 481 additions and 276 deletions
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
. "planner/core"
|
||||
"planner/core"
|
||||
)
|
||||
|
||||
func getUserByName(c *gin.Context) {
|
||||
|
|
@ -14,19 +14,23 @@ func getUserByName(c *gin.Context) {
|
|||
Name string `fdb:"name"`
|
||||
}
|
||||
if c.ShouldBind(&q) == nil {
|
||||
user := User{
|
||||
Username: q.Name,
|
||||
user, err := core.UserGet(db, q.Name)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "Unable to get user: "+err.Error())
|
||||
return
|
||||
}
|
||||
db.Take(&user)
|
||||
fmt.Println(user)
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
}
|
||||
|
||||
func createUser(c *gin.Context) {
|
||||
var u User
|
||||
var u core.User
|
||||
if c.ShouldBind(&u) == nil {
|
||||
db.Create(&u)
|
||||
err := u.Create(db)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "Unable to create user: "+err.Error())
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusCreated)
|
||||
} else {
|
||||
fmt.Print("Could not bind model")
|
||||
|
|
@ -43,12 +47,13 @@ func login(c *gin.Context) {
|
|||
if q.Username == "" {
|
||||
c.String(http.StatusBadRequest, "Login data is null")
|
||||
} else {
|
||||
user := User{
|
||||
Username: q.Username,
|
||||
user, err := core.UserGet(db, q.Username)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "Unable to get user: "+err.Error())
|
||||
return
|
||||
}
|
||||
db.Take(&user)
|
||||
if user.Password == q.Password {
|
||||
c.JSON(http.StatusOK, map[string]string{"username": user.Username})
|
||||
c.JSON(http.StatusOK, gin.H{"username": user.Username})
|
||||
} else {
|
||||
c.Status(http.StatusForbidden)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue