Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wagslane committed Jun 12, 2023
1 parent fc8dac2 commit 57e5fde
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM --platform=linux/amd64 debian:stretch-slim
FROM --platform=linux/amd64 debian:stable-slim

RUN apt-get update && apt-get install -y ca-certificates

ADD notely /usr/bin/notely

Expand Down
2 changes: 1 addition & 1 deletion handler_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ func (cfg *apiConfig) handlerNotesCreate(w http.ResponseWriter, r *http.Request,
respondWithError(w, http.StatusNotFound, "Couldn't get note")
return
}
respondWithJSON(w, http.StatusOK, databaseNoteToNote(note))
respondWithJSON(w, http.StatusCreated, databaseNoteToNote(note))
}
2 changes: 1 addition & 1 deletion handler_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (cfg *apiConfig) handlerUsersCreate(w http.ResponseWriter, r *http.Request)
return
}

respondWithJSON(w, http.StatusOK, databaseUserToUser(user))
respondWithJSON(w, http.StatusCreated, databaseUserToUser(user))
}

func generateRandomSHA256Hash() (string, error) {
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion scripts/migrateup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
source .env
if [ -f .env ]; then
source .env
fi

cd sql/schema
goose mysql $DATABASE_URL up
19 changes: 14 additions & 5 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body class="section">
<h1>Notely</h1>
<h1>Welcome to Notely</h1>

<div id="userCreationContainer" class="section">
<input id="nameField" type="text" placeholder="Enter your name">
Expand Down Expand Up @@ -37,7 +37,7 @@ <h2>Your Notes</h2>
return;
}
const noteContent = document.getElementById('newNoteContent').value;
const response = await fetch(`${API_BASE}/notes`,
const response = await fetchWithAlert(`${API_BASE}/notes`,
{
method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `ApiKey ${currentUserAPIKey}` },
body: JSON.stringify({ note: noteContent })
Expand All @@ -47,15 +47,15 @@ <h2>Your Notes</h2>
}

async function getUser() {
const response = await fetch(`${API_BASE}/users`, { headers: { 'Authorization': `ApiKey ${currentUserAPIKey}` } });
const response = await fetchWithAlert(`${API_BASE}/users`, { headers: { 'Authorization': `ApiKey ${currentUserAPIKey}` } });
return await response.json();
}

async function loadNotes() {
if (!currentUser) {
return;
}
const response = await fetch(`${API_BASE}/notes`, { headers: { 'Authorization': `ApiKey ${currentUserAPIKey}` } });
const response = await fetchWithAlert(`${API_BASE}/notes`, { headers: { 'Authorization': `ApiKey ${currentUserAPIKey}` } });
const notes = await response.json();
const notesContainer = document.getElementById('notes');
notesContainer.innerHTML = '';
Expand All @@ -71,7 +71,7 @@ <h2>Your Notes</h2>

async function createUser() {
const nameField = document.getElementById('nameField');
const response = await fetch(`${API_BASE}/users`, {
const response = await fetchWithAlert(`${API_BASE}/users`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: nameField.value }) // using the value from nameField
Expand Down Expand Up @@ -113,6 +113,15 @@ <h2>Your Notes</h2>
document.getElementById('greetingMessage').textContent = `Hello ${user.name}!`;
}

async function fetchWithAlert(url, options) {
const response = await fetch(url, options);
if (response.status > 299) {
alert(`Error: ${response.status}`);
return;
}
return response;
}

login();
</script>

Expand Down

0 comments on commit 57e5fde

Please sign in to comment.