// CreateOne saves provided model instance to database
CreateOne saves provided model instance to database
// CreateOne saves provided model instance to database
func (this *UserService) CreateOne(request *mrequest.UserCreate) (*models.User, *mresponse.ErrorResponse) {
	e := errors.ValidateRequest(request)
	if e != nil {
		return nil, e
	}
	res, err := this.userRepository.CreateOne(request)
	if err != nil {
		errR := errors.HandleErrorResponse(errors.SERVICE_UNAVAILABLE, nil, err.Error())
		return nil, errR
	}
	id := res.InsertedID.(objectid.ObjectID)
	u := models.User{
		ID: id.Hex(),
		Username: request.Username,
		Email: request.Email,
	}
	u.Roles = make([]*models.Role, len(request.Roles))
	copy(u.Roles, request.Roles)
	return &u, nil
}
func ( this * UserService ) CreateOne ( request * mrequest . UserCreate ) ( * models . User , * mresponse . ErrorResponse ) { e := errors . ValidateRequest ( request ) if e != nil { return nil , e } res , err := this . userRepository . CreateOne ( request ) if err != nil { errR := errors . HandleErrorResponse ( errors . SERVICE_UNAVAILABLE , nil , err . Error ( ) ) return nil , errR } id := res . InsertedID . ( objectid . ObjectID ) u := models . User { ID : id . Hex ( ) , Username : request . Username , Email : request . Email , } u . Roles = make ( [ ] * models . Role , len ( request . Roles ) ) copy ( u . Roles , request . Roles ) return & u , nil }
CreateOne saves provided model instance to database
CreateOne saves provided model instance to database
// validate request