Skip to content

Conversation

@dev-pv
Copy link
Owner

@dev-pv dev-pv commented Jan 19, 2025

Итоговый PR

Copy link

@ivannizh ivannizh left a 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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше перед стартом выводить лог, чтобы видеть, что приложение запустилось и на каком порту

if task.Repeat != "" {
nextDate, err := NextDate(now, task.Date, task.Repeat)
if err != nil {
return "", fmt.Errorf("invalid repeat rule: %v", err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для вывода в логи %v, а для оборачивания %w (wrap)

Suggested change
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)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

После цикла нужно проверить курсор на наличие ошибок

http://go-database-sql.org/retrieving.html

}
idInt, err := strconv.Atoi(id)
if err != nil {
return nil, fmt.Errorf("invalid task id '%s'", id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень хорошо, что везде оборачиваешь, но лучше текст ошибок оставлять

Suggested change
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)

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{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Только перед записью ответа нужно выставить код ответа

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

крит, нужно везде исправить

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если не указать код, то по умолчанию будет 200

@dev-pv
Copy link
Owner Author

dev-pv commented Jan 20, 2025

Владимир, привет!

Отличная выпускная работа, код запускается, тесты проходят, но есть критическое замечание с кодами ответа, которое попрошу исправить, подробнее в комментариях.

Привет! Спасибо за ревью. Исправил по замечаниям

Copy link

@ivannizh ivannizh left a 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)

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут все было верно, так тоже можно записывать ответ
Uploading image.png…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants