Skip to content

Commit

Permalink
🚧 wip (api): Created skeleton of the controller that will update the …
Browse files Browse the repository at this point in the history
…user profile details
  • Loading branch information
kevinmarquesp committed Jul 3, 2024
1 parent 377a5f1 commit 7653d84
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions internal/api/users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package api

import (
"encoding/json"
"io"
"net/http"
"strings"

"github.com/charmbracelet/log"
"github.com/kevinmarquesp/go-postr/internal/data"
"github.com/kevinmarquesp/go-postr/internal/models"
"github.com/kevinmarquesp/go-postr/internal/utils"
)

type UsersController struct {
Database models.GenericDatabaseProvider
}

func (us UsersController) UpdateUserProfileDetails(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()

rawBody, err := io.ReadAll(r.Body)
if err != nil {
utils.WriteGenericJsonError(w, http.StatusInternalServerError, err)
return
}

var body data.UpdateUserProfileDetailsBody

if err = json.Unmarshal(rawBody, &body); err != nil {
utils.WriteGenericJsonError(w, http.StatusInternalServerError, err)
return
}

userPublicId := r.PathValue("userPublicId")
sessionToken := strings.Trim(body.SessionToken, " ")

log.Infof("Public Id:\t\t%s", userPublicId)
log.Infof("Session Token:\t%s", sessionToken)

// TODO: Create a function that recieves the body fields to update the user.
// TODO: Get the updated user profile fields from that function.
// TODO: Format a JSON response, then send it to the final user.
}

0 comments on commit 7653d84

Please sign in to comment.