github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume4/section2/gopherface/endpoints/saveuserprofile.go (about) 1 package endpoints 2 3 import ( 4 "encoding/json" 5 "io/ioutil" 6 "log" 7 "net/http" 8 9 "github.com/EngineerKamesh/gofullstack/volume4/section2/gopherface/common/authenticate" 10 11 "github.com/EngineerKamesh/gofullstack/volume4/section2/gopherface/common" 12 "github.com/EngineerKamesh/gofullstack/volume4/section2/gopherface/models" 13 ) 14 15 func SaveUserProfileEndpoint(env *common.Env) http.HandlerFunc { 16 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 17 18 gfSession, err := authenticate.SessionStore.Get(r, "gopherface-session") 19 if err != nil { 20 log.Print(err) 21 return 22 } 23 uuid := gfSession.Values["uuid"] 24 25 reqBody, err := ioutil.ReadAll(r.Body) 26 if err != nil { 27 log.Print("Encountered error when attempting to read the request body: ", err) 28 } 29 30 var u models.UserProfile 31 json.Unmarshal(reqBody, &u) 32 33 env.DB.UpdateUserProfile(uuid.(string), u.About, u.Location, u.Interests) 34 35 }) 36 }