Beispiel #1
0
func (i *SessionInter) scopeModel(session *domain.Session) error {
	session.CreatedAt = time.Time{}
	session.UpdatedAt = time.Time{}
	session.Account = domain.Account{}

	return nil
}
Beispiel #2
0
func (r *SessionRepo) UpdateByID(id int, session *domain.Session,
	context usecases.QueryContext) (*domain.Session, error) {

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	dbName := utils.ToDBName("sessions")
	oldSession := &domain.Session{}

	err = query.Where(dbName+".id = ?", id).First(oldSession).Error
	if err != nil {
		if strings.Contains(err.Error(), "record not found") {
			return nil, internalerrors.NotFound
		}

		return nil, internalerrors.DatabaseError
	}

	session.ID = oldSession.ID
	session.CreatedAt = oldSession.CreatedAt

	err = r.store.GetDB().Save(&session).Error
	if err != nil {
		if strings.Contains(err.Error(), "constraint") {
			return nil, internalerrors.NewViolatedConstraint(err.Error())
		}

		return nil, internalerrors.DatabaseError
	}

	return session, nil
}
func (i *AccountGuestInter) Current(currentSession *domain.Session) (*domain.Account, error) {
	filter := &usecases.Filter{
		Include: []interface{}{"users"},
	}

	account, err := i.repo.FindByID(currentSession.AccountID, usecases.QueryContext{Filter: filter})
	if err != nil {
		return nil, err
	}

	currentSession.Account = domain.Account{}
	account.Sessions = []domain.Session{*currentSession}

	return account, nil
}