Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#147 #60

Merged
merged 1 commit into from Jul 17, 2022
Merged

#147 #60

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 34 additions & 29 deletions index.html
Expand Up @@ -161,33 +161,33 @@ <h5 class="modal-title" id="id-add-modal-label">登録</h5>
}


#validateMemo(id, title, body) {
var errStr = ""
if (title.length < 1 || title.length > Memo.MaxTitleLength) {
errStr = "タイトルの文字数は1文字以上30文字以下にしてください。<br>"
}

if (body.length < 1 || body.length > Memo.MaxBodyLength) {
errStr = errStr + "本文の文字数は1文字以上100文字以下にしてください。<br>"
}

this.#memos.forEach((m) => {
if (m.id == id) {
return
}
if (m.title == title) {
errStr = "すでに登録済みのタイトルです。<br>"
}
})

return errStr
}
//#validateMemo(id, title, body) {
// var errStr = ""
// if (title.length < 1 || title.length > Memo.MaxTitleLength) {
// errStr = "タイトルの文字数は1文字以上30文字以下にしてください。<br>"
// }

// if (body.length < 1 || body.length > Memo.MaxBodyLength) {
// errStr = errStr + "本文の文字数は1文字以上100文字以下にしてください。<br>"
// }

// this.#memos.forEach((m) => {
// if (m.id == id) {
// return
// }
// if (m.title == title) {
// errStr = "すでに登録済みのタイトルです。<br>"
// }
// })

// return errStr
//}

updateMemo(id, title, body) {
const errStr = this.#validateMemo(id, title, body)
if (errStr.length > 0) {
return errStr
}
//const errStr = this.#validateMemo(id, title, body)
//if (errStr.length > 0) {
// return errStr
//}

const memo = this.#getMemoById(id)
memo.update(title, body)
Expand Down Expand Up @@ -215,10 +215,10 @@ <h5 class="modal-title" id="id-add-modal-label">登録</h5>

addMemo(title, body) {
//この時点で登録されるメモに id はないので、-1 を指定する。
const errStr = this.#validateMemo(-1, title, body)
if (errStr.length > 0) {
return errStr
}
//const errStr = this.#validateMemo(-1, title, body)
//if (errStr.length > 0) {
// return errStr
//}

const memo = Memo.createNewMemo(title, body)

Expand All @@ -227,6 +227,11 @@ <h5 class="modal-title" id="id-add-modal-label">登録</h5>
//メモをバックエンドサーバに送信する
const req = new XMLHttpRequest()
req.addEventListener("load", () => {
//バックエンドサーバからのレスポンスが返ってくる
console.log(req)
if (req.status == 400) {
alert("400 error")
}
})
req.open("POST", "http://localhost:8080/add_memo")
req.setRequestHeader("Content-Type", "application/json")
Expand Down
2 changes: 2 additions & 0 deletions main.go
Expand Up @@ -19,6 +19,8 @@ func main() {

//http://localhost:8080/
http.HandleFunc("/", showHTML)
http.HandleFunc("/favicon.ico", func (w http.ResponseWriter, r *http.Request) {
})
http.HandleFunc("/add_memo", addMemo)
http.HandleFunc("/update_memo", updateMemo)
http.HandleFunc("/list_memos", listMemos)
Expand Down