Add proper updating of profiles
This commit is contained in:
parent
a9b09ce4da
commit
b68dba10cb
2 changed files with 22 additions and 5 deletions
|
@ -2,6 +2,7 @@ package users
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-chi/chi"
|
"github.com/go-chi/chi"
|
||||||
"github.com/go-chi/jwtauth"
|
"github.com/go-chi/jwtauth"
|
||||||
|
@ -15,10 +16,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username",db:"username"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email",db:"email"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country",db:"country"`
|
||||||
Bio string `json:"bio"`
|
Bio string `json:"bio",db:"bio"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
|
@ -64,6 +65,22 @@ func updateUser(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
user := &User{}
|
||||||
|
err := json.NewDecoder(r.Body).Decode(user)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user.Username = username
|
||||||
|
updateProfileStatement := `
|
||||||
|
UPDATE user_profiles
|
||||||
|
SET username = $1,
|
||||||
|
email = $2,
|
||||||
|
country = $3,
|
||||||
|
bio = $4
|
||||||
|
WHERE username = $5`
|
||||||
|
_, err = DB.Exec(updateProfileStatement, user.Username, user.Email, user.Country, user.Bio, username)
|
||||||
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue