Skip to content

Commit 57e5fde

Browse files
committed
small updates
1 parent fc8dac2 commit 57e5fde

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM --platform=linux/amd64 debian:stretch-slim
1+
FROM --platform=linux/amd64 debian:stable-slim
2+
3+
RUN apt-get update && apt-get install -y ca-certificates
24

35
ADD notely /usr/bin/notely
46

handler_notes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ func (cfg *apiConfig) handlerNotesCreate(w http.ResponseWriter, r *http.Request,
4949
respondWithError(w, http.StatusNotFound, "Couldn't get note")
5050
return
5151
}
52-
respondWithJSON(w, http.StatusOK, databaseNoteToNote(note))
52+
respondWithJSON(w, http.StatusCreated, databaseNoteToNote(note))
5353
}

handler_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (cfg *apiConfig) handlerUsersCreate(w http.ResponseWriter, r *http.Request)
5151
return
5252
}
5353

54-
respondWithJSON(w, http.StatusOK, databaseUserToUser(user))
54+
respondWithJSON(w, http.StatusCreated, databaseUserToUser(user))
5555
}
5656

5757
func generateRandomSHA256Hash() (string, error) {
File renamed without changes.

scripts/migrateup.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
source .env
1+
if [ -f .env ]; then
2+
source .env
3+
fi
24

35
cd sql/schema
46
goose mysql $DATABASE_URL up

static/index.html

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</head>
88

99
<body class="section">
10-
<h1>Notely</h1>
10+
<h1>Welcome to Notely</h1>
1111

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

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

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

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

116+
async function fetchWithAlert(url, options) {
117+
const response = await fetch(url, options);
118+
if (response.status > 299) {
119+
alert(`Error: ${response.status}`);
120+
return;
121+
}
122+
return response;
123+
}
124+
116125
login();
117126
</script>
118127

0 commit comments

Comments
 (0)