113 lines
3.2 KiB
Go
113 lines
3.2 KiB
Go
package user
|
|
|
|
import (
|
|
"Yimaru-Backend/internal/domain"
|
|
"context"
|
|
"strconv"
|
|
)
|
|
|
|
func (s *Service) GetUserByEmailPhone(
|
|
ctx context.Context,
|
|
email string,
|
|
phone string,
|
|
) (domain.User, error) {
|
|
return s.userStore.GetUserByEmailPhone(ctx, email, phone)
|
|
}
|
|
|
|
func (s *Service) IsUserPending(ctx context.Context, userName string) (bool, error) {
|
|
return s.userStore.IsUserPending(ctx, userName)
|
|
}
|
|
|
|
func (s *Service) IsUserNameUnique(ctx context.Context, userName string) (bool, error) {
|
|
return s.userStore.IsUserNameUnique(ctx, userName)
|
|
}
|
|
|
|
func (s *Service) GetUserByUserName(
|
|
ctx context.Context,
|
|
userName string,
|
|
) (domain.User, error) {
|
|
return s.userStore.GetUserByUserName(ctx, userName)
|
|
}
|
|
|
|
func (s *Service) SearchUserByNameOrPhone(ctx context.Context, searchString string, role *int64) ([]domain.User, error) {
|
|
// Search user
|
|
var roleStr *string
|
|
if role != nil {
|
|
tmp := strconv.FormatInt(*role, 10)
|
|
roleStr = &tmp
|
|
}
|
|
return s.userStore.SearchUserByNameOrPhone(ctx, searchString, roleStr)
|
|
|
|
}
|
|
|
|
func (s *Service) UpdateUser(ctx context.Context, req domain.UpdateUserReq) error {
|
|
newUser := domain.User{
|
|
ID: req.UserID,
|
|
FirstName: req.FirstName.Value,
|
|
LastName: req.LastName.Value,
|
|
KnowledgeLevel: req.KnowledgeLevel.Value,
|
|
UserName: req.UserName.Value,
|
|
Age: req.Age.Value,
|
|
EducationLevel: req.EducationLevel.Value,
|
|
Country: req.Country.Value,
|
|
Region: req.Region.Value,
|
|
Status: domain.UserStatus(req.Status.Value),
|
|
NickName: req.NickName.Value,
|
|
Occupation: req.Occupation.Value,
|
|
LearningGoal: req.LearningGoal.Value,
|
|
LanguageGoal: req.LanguageGoal.Value,
|
|
LanguageChallange: req.LanguageChallange.Value,
|
|
FavoutiteTopic: req.FavoutiteTopic.Value,
|
|
PreferredLanguage: req.PreferredLanguage.Value,
|
|
ProfilePictureURL: req.ProfilePictureURL.Value,
|
|
}
|
|
|
|
// Update user in the store
|
|
return s.userStore.UpdateUser(ctx, newUser)
|
|
}
|
|
|
|
// func (s *Service) UpdateUserSuspend(ctx context.Context, id int64, status bool) error {
|
|
// // update user
|
|
// return s.userStore.UpdateUserSuspend(ctx, id, status)
|
|
// }
|
|
func (s *Service) GetUserByID(ctx context.Context, id int64) (domain.User, error) {
|
|
return s.userStore.GetUserByID(ctx, id)
|
|
}
|
|
|
|
// GetAllUsers retrieves users based on the provided filter
|
|
// func (s *Service) GetAllUsers(ctx context.Context, filter domain.UserFilter) ([]domain.User, int64, error) {
|
|
// var role *string
|
|
// if filter.Role != "" {
|
|
// role = &filter.Role
|
|
// }
|
|
|
|
// var query *string
|
|
// if filter.Query.Valid {
|
|
// q := filter.Query.Value
|
|
// query = &q
|
|
// }
|
|
|
|
// var createdBefore *time.Time
|
|
// if filter.CreatedBefore.Valid {
|
|
// b := filter.CreatedBefore.Value
|
|
// createdBefore = &b
|
|
// }
|
|
|
|
// var createdAfter *time.Time
|
|
// if filter.CreatedAfter.Valid {
|
|
// a := filter.CreatedAfter.Value
|
|
// createdAfter = &a
|
|
// }
|
|
|
|
// var limit int32 = 10
|
|
// var offset int32 = 0
|
|
// if filter.PageSize.Valid {
|
|
// limit = int32(filter.PageSize.Value)
|
|
// }
|
|
// if filter.Page.Valid && filter.PageSize.Valid {
|
|
// offset = int32(filter.Page.Value * filter.PageSize.Value)
|
|
// }
|
|
|
|
// return s.userStore.GetAllUsers(ctx, role, query, createdBefore, createdAfter, limit, offset)
|
|
// }
|