Skip to content

Commit

Permalink
Merge pull request #13 from azuki774/add-del-button
Browse files Browse the repository at this point in the history
Add del button
  • Loading branch information
azuki774 authored Aug 19, 2024
2 parents a32235a + 5618d64 commit 32da3e2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
21 changes: 21 additions & 0 deletions components/History.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ if (data != undefined) { // 取得済の場合のみ
recordList.value = data
async function showDeleteDialog(id: number): Promise<void> {
const userResponse: boolean = confirm("このデータを削除しますか");
if (userResponse == true) {
console.log('delete: id=' + id);
const asyncDataBtn = await useAsyncData(
`record`,
(): Promise<any> => {
const param = { 'id': id };
const paramStr = "?id=" + param['id'];
const localurl = "/api/deleteRecord" + paramStr
const response = $fetch(localurl);
return response;
}
);
location.reload()
}
};
</script>

<template>
Expand All @@ -34,6 +53,7 @@ recordList.value = data
<th>金額</th>
<th>日付</th>
<th>メモ</th>
<th>削除</th>
</tr>
</thead>
<tbody>
Expand All @@ -43,6 +63,7 @@ recordList.value = data
<td>{{ record.price }}</td>
<td>{{ record.datetime }}</td>
<td>{{ record.memo }}</td>
<td><button class="btn btn-secondary" @click="showDeleteDialog(record.id)">削除</button></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineNuxtConfig({
css: ["bootstrap/dist/css/bootstrap.min.css"],
devtools: { enabled: true },
routeRules: {
"/": { ssr: false },
"/": { ssr: true },
},
runtimeConfig: {
public: { // 外部から取得するにはpublic が必要
Expand Down
11 changes: 11 additions & 0 deletions server/api/deleteRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default defineEventHandler ( async (event) => {
const config = useRuntimeConfig()
const query = getQuery(event)
const url = config.public.mawinterApi + "/v2/record/" + query.id
const result = await $fetch(url,
{
method: "DELETE",
}
)
return result
})
5 changes: 5 additions & 0 deletions test/mock_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def do_POST(self):
self.send_header('Content-type', 'application/json')
self.end_headers()

def do_DELETE(self):
self.send_response(204)
self.send_header('Content-type', 'text/plain')
self.end_headers()

def import_args():
parser = argparse.ArgumentParser("mock server start")

Expand Down

0 comments on commit 32da3e2

Please sign in to comment.