Yimaru-BackEnd/internal/services/user/user.go

68 lines
2.1 KiB
Go

package user
import (
"Yimaru-Backend/internal/domain"
"context"
"strconv"
)
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)
}