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
|
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")
|
respondWithError(w, http.StatusNotFound, "Couldn't get note")
|
||||||
return
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
respondWithJSON(w, http.StatusOK, databaseUserToUser(user))
|
respondWithJSON(w, http.StatusCreated, databaseUserToUser(user))
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomSHA256Hash() (string, error) {
|
func generateRandomSHA256Hash() (string, error) {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
source .env
|
if [ -f .env ]; then
|
||||||
|
source .env
|
||||||
|
fi
|
||||||
|
|
||||||
cd sql/schema
|
cd sql/schema
|
||||||
goose mysql $DATABASE_URL up
|
goose mysql $DATABASE_URL up
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="section">
|
<body class="section">
|
||||||
<h1>Notely</h1>
|
<h1>Welcome to Notely</h1>
|
||||||
|
|
||||||
<div id="userCreationContainer" class="section">
|
<div id="userCreationContainer" class="section">
|
||||||
<input id="nameField" type="text" placeholder="Enter your name">
|
<input id="nameField" type="text" placeholder="Enter your name">
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const noteContent = document.getElementById('newNoteContent').value;
|
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}` },
|
method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `ApiKey ${currentUserAPIKey}` },
|
||||||
body: JSON.stringify({ note: noteContent })
|
body: JSON.stringify({ note: noteContent })
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getUser() {
|
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();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
return;
|
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 notes = await response.json();
|
||||||
const notesContainer = document.getElementById('notes');
|
const notesContainer = document.getElementById('notes');
|
||||||
notesContainer.innerHTML = '';
|
notesContainer.innerHTML = '';
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
async function createUser() {
|
async function createUser() {
|
||||||
const nameField = document.getElementById('nameField');
|
const nameField = document.getElementById('nameField');
|
||||||
const response = await fetch(`${API_BASE}/users`, {
|
const response = await fetchWithAlert(`${API_BASE}/users`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ name: nameField.value }) // using the value from nameField
|
body: JSON.stringify({ name: nameField.value }) // using the value from nameField
|
||||||
@@ -113,6 +113,15 @@
|
|||||||
document.getElementById('greetingMessage').textContent = `Hello ${user.name}!`;
|
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();
|
login();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user