-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 wip (api): Created skeleton of the controller that will update the …
…user profile details
- Loading branch information
1 parent
377a5f1
commit 7653d84
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} |