-
Notifications
You must be signed in to change notification settings - Fork 0
Develop #1
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
base: main
Are you sure you want to change the base?
Conversation
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.
Владимир, привет!
Отличная выпускная работа, код запускается, тесты проходят, но есть критическое замечание с кодами ответа, которое попрошу исправить, подробнее в комментариях.
| http.HandleFunc("/api/tasks", handlers.GetTasksHandler(database)) | ||
| http.HandleFunc("/api/task/done", handlers.DoneTaskHandler(database)) | ||
|
|
||
| if err := http.ListenAndServe(":"+port, nil); err != nil { |
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.
Лучше перед стартом выводить лог, чтобы видеть, что приложение запустилось и на каком порту
internal/app/todo_app.go
Outdated
| if task.Repeat != "" { | ||
| nextDate, err := NextDate(now, task.Date, task.Repeat) | ||
| if err != nil { | ||
| return "", fmt.Errorf("invalid repeat rule: %v", 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.
Для вывода в логи %v, а для оборачивания %w (wrap)
| return "", fmt.Errorf("invalid repeat rule: %v", err) | |
| return "", fmt.Errorf("invalid repeat rule: %w", err) |
| } | ||
| t.ID = strconv.FormatInt(id64, 10) | ||
| tasks = append(tasks, t) | ||
| } |
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.
После цикла нужно проверить курсор на наличие ошибок
| } | ||
| idInt, err := strconv.Atoi(id) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("invalid task id '%s'", id) |
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.
Очень хорошо, что везде оборачиваешь, но лучше текст ошибок оставлять
| return nil, fmt.Errorf("invalid task id '%s'", id) | |
| return nil, fmt.Errorf("invalid task id '%s': %w", id, err) |
|
|
||
| var task app.Task | ||
| if err := json.NewDecoder(r.Body).Decode(&task); err != nil { | ||
| log.Printf("JSON Decode Error: %v", 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.
Верно сделано, что ошибку в лог, а пользователю простое сообщение
| var task app.Task | ||
| if err := json.NewDecoder(r.Body).Decode(&task); err != nil { | ||
| log.Printf("JSON Decode Error: %v", err) | ||
| json.NewEncoder(w).Encode(map[string]string{ |
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.
Только перед записью ответа нужно выставить код ответа
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.
крит, нужно везде исправить
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.
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.
Если не указать код, то по умолчанию будет 200
Привет! Спасибо за ревью. Исправил по замечаниям |
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.
Владимир, привет!
Основные замечания все исправлены!
Работа принята, поздравляю с окончанием курса!
| id := r.URL.Query().Get("id") | ||
| if err := app.DeleteTask(db, id); err != nil { | ||
| log.Printf("DeleteTask error: %v", err) | ||
| w.WriteHeader(http.StatusBadRequest) |
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.
А если это внутренняя ошибка коннекта к БД?
|
|
||
| if r.Method != http.MethodPost { | ||
| http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) | ||
| w.WriteHeader(http.StatusMethodNotAllowed) |
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.

Итоговый PR