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

Added profile handler #28

Merged
merged 8 commits into from
Mar 8, 2025
Merged

Added profile handler #28

merged 8 commits into from
Mar 8, 2025

Conversation

marrriamme
Copy link
Collaborator

  1. Добавила ручку профиля
  2. Обновила модели
  3. Добавила тесты и моки для ручки профиля


utils.SendSuccessResponse(w, http.StatusOK, user)
}

var (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Переменные обычно объявляются вверху файла, до функций

Comment on lines 207 to 213
user := models.User{
ID: userRepo.ID,
Email: userRepo.Email,
Name: userRepo.Name,
Surname: userRepo.Surname,
PhoneNumber: userRepo.PhoneNumber,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Давай для этого сделаем отдельную функцию(или метод) в файле models/user.go
Подобный уже есть в файле models/product.go, можешь посмотреть как там

return
}

userRepo, err := h.repo.GetUserByID(uid)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Я бы просто в user переименовал, так понятнее

}

// Проверяем, совпадает ли версия пользователя
if userRepo.Version != version {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Тут тоже можно сделать метод для модельки UserRepo, который принимает version и делает это сравнение, возвращает соответственно bool

Copy link
Collaborator

@Benzogang-Tape Benzogang-Tape left a comment

Choose a reason for hiding this comment

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

Комменты оставил, плюс как договорились с фронтом - при авторизации будем ставить HttpOnly cookie, вместо того, чтобы отправлять токен в теле ответа. Выглядеть это будет примерно так:

cookie := &http.Cookie{
	Name:     "token",
	Value:    "<токен, который отправлялся в теле ответа>",
	HttpOnly: true,
	Path:     "/", // чтобы кука отправлялась на все запросы к нашему домену
	MaxAge:   <время жизни куки в секундах, равно времени жизни токена, можно вынести в константу>,
	SameSite: http.SameSiteStrictMode, // чтобы могла отправляться только с нашего сайта
}

Соответственно в middleware авторизации надо будет получать эту куку и проверять токен, который в ней хранится(не сильно код должен поменяться)

@@ -168,14 +169,49 @@ func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request) {
return
}

utils.Cookie(w, "", string(utils.Token))
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Expires:  time.Now().UTC().AddDate(0, 0, -1)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Спасибо, поправила

Comment on lines 1 to 9
package utils

type CookieKeys string

const (
Token CookieKeys = "token"
UserIDKey = "userID"
UserVersionKey = "userVersion"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Перенеси это в файл utils/cookie.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Перенесла

Copy link
Collaborator

@Benzogang-Tape Benzogang-Tape left a comment

Choose a reason for hiding this comment

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

Два мини коммента, поправь и вливай

@marrriamme marrriamme merged commit 2c5815b into develop Mar 8, 2025
@marrriamme marrriamme deleted the feature/getme-handler branch March 8, 2025 07:31
@marrriamme marrriamme restored the feature/getme-handler branch March 8, 2025 07:31
@marrriamme marrriamme deleted the feature/getme-handler branch March 8, 2025 07:31
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.

2 participants