small updates
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
if [ -f .env ]; then
|
||||
source .env
|
||||
fi
|
||||
|
||||
cd sql/schema
|
||||
goose mysql $DATABASE_URL 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">
|
||||
@@ -37,7 +37,7 @@
|
||||
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 })
|
||||
@@ -47,7 +47,7 @@
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
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 = '';
|
||||
@@ -71,7 +71,7 @@
|
||||
|
||||
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
|
||||
@@ -113,6 +113,15 @@
|
||||
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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user