This commit is contained in:
wagslane
2024-03-07 09:48:38 -07:00
parent 2b337f9f0f
commit 86874e2f9e
171 changed files with 63081 additions and 7300 deletions

View File

@@ -33,8 +33,8 @@ func (cfg *apiConfig) handlerUsersCreate(w http.ResponseWriter, r *http.Request)
err = cfg.DB.CreateUser(r.Context(), database.CreateUserParams{
ID: uuid.New().String(),
CreatedAt: time.Now().UTC(),
UpdatedAt: time.Now().UTC(),
CreatedAt: time.Now().UTC().Format(time.RFC3339),
UpdatedAt: time.Now().UTC().Format(time.RFC3339),
Name: params.Name,
ApiKey: apiKey,
})
@@ -51,7 +51,13 @@ func (cfg *apiConfig) handlerUsersCreate(w http.ResponseWriter, r *http.Request)
return
}
respondWithJSON(w, http.StatusCreated, databaseUserToUser(user))
userResp, err := databaseUserToUser(user)
if err != nil {
log.Println(err)
respondWithError(w, http.StatusInternalServerError, "Couldn't convert user")
return
}
respondWithJSON(w, http.StatusCreated, userResp)
}
func generateRandomSHA256Hash() (string, error) {
@@ -66,5 +72,13 @@ func generateRandomSHA256Hash() (string, error) {
}
func (cfg *apiConfig) handlerUsersGet(w http.ResponseWriter, r *http.Request, user database.User) {
respondWithJSON(w, http.StatusOK, databaseUserToUser(user))
userResp, err := databaseUserToUser(user)
if err != nil {
log.Println(err)
respondWithError(w, http.StatusInternalServerError, "Couldn't convert user")
return
}
respondWithJSON(w, http.StatusOK, userResp)
}