user.go 915 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package mappers
  2. import (
  3. "database/sql"
  4. "strings"
  5. "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
  6. "git.dmitriygnatenko.ru/dima/homethings/internal/models"
  7. )
  8. func ConvertToUpdateUserRequestModel(id int, req dto.UpdateUserRequest) models.UpdateUserRequest {
  9. res := models.UpdateUserRequest{
  10. ID: id,
  11. }
  12. var username, password string
  13. if req.Username != nil {
  14. username = strings.TrimSpace(*req.Username)
  15. }
  16. if req.Password != nil {
  17. password = strings.TrimSpace(*req.Password)
  18. }
  19. if username != "" {
  20. res.Username = sql.NullString{String: username, Valid: true}
  21. }
  22. if password != "" {
  23. res.Password = sql.NullString{String: password, Valid: true}
  24. }
  25. return res
  26. }
  27. func ConvertToUserResponseDTO(req models.User) dto.UserResponse {
  28. return dto.UserResponse{Username: req.Username}
  29. }
  30. func ConvertToLoginResponseDTO(token string) dto.LoginResponse {
  31. return dto.LoginResponse{Token: token}
  32. }