-
Notifications
You must be signed in to change notification settings - Fork 6
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
自分の投稿の通知に含めるかの設定するapiの実装 #67
base: main
Are you sure you want to change the base?
Conversation
err := db.Select(&wordMe, "SELECT me_notification, word FROM words WHERE word = ? AND trap_id = ?", word, userId) | ||
if errors.Is(err, sql.ErrNoRows) { | ||
slog.Info("No Data Found") | ||
return err | ||
} else if err != nil { | ||
slog.Info("Error: %s", err) | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの存在確認、model.ExistWordを事前にhandler側の関数で呼び出してやるのがいいんじゃない?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そもそもdb.Select
を使うとsql.ErrNoRows
は返ってこないです
if len(wordMe) != 1 { | ||
slog.Info("Already exist too many data same trap_id and word: %d", len(wordMe)) | ||
return fmt.Errorf("Already exist too many data same trap_id and word: %d", len(wordMe)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model.ExistWord
を使えばこの考慮はいらないはず
err := db.Select(&wordMes, "SELECT me_notification, word FROM words WHERE trap_id = ?", userId) | ||
if errors.Is(err, sql.ErrNoRows) { | ||
slog.Info("No Data Found") | ||
return err | ||
} else if err != nil { | ||
slog.Info("Error: %s", err) | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一括全件更新のときはこのチェックなしでupdateかけていい
PUT /words/me/
POST /words/me/all
postmanで確認済み