Exemplo n.º 1
0
func (cdb ComplaintDB) GetAllByEmailAddress(ea string, everything bool) (*types.ComplaintsAndProfile, error) {
	var cap types.ComplaintsAndProfile

	cdb.Debugf("GABEA_001", "cdb.GetAllByEmailAddress starting (everything=%v)", everything)

	if cp, err := cdb.GetProfileByEmailAddress(ea); err == datastore.ErrNoSuchEntity {
		return nil, nil // No such profile exists
	} else if err != nil {
		return nil, err // A real problem occurred
	} else {
		cdb.Debugf("GABEA_002", "profile retrieved")
		cap.Profile = *cp
	}

	if everything {
		if c, err := cdb.GetComplaintsByEmailAddress(ea); err != nil {
			return nil, err
		} else {
			cdb.Debugf("GABEA_003", "EVERYTHING retrieved")
			cap.Complaints = c
		}

	} else {
		// Just today
		s, e := date.WindowForToday()
		if c, err := cdb.GetComplaintsInSpanByEmailAddress(ea, s, e); err != nil {
			return nil, err
		} else {
			cdb.Debugf("GABEA_004", "WindowForToday retrieved; now getting counts")
			cap.Complaints = c
		}
	}

	if counts, err := cdb.getDailyCountsByEmailAdress(ea); err != nil {
		return nil, err
	} else {
		cdb.Debugf("GABEA_005", "counts retrieved")
		cap.Counts = counts
	}

	return &cap, nil
}
Exemplo n.º 2
0
func (cdb ComplaintDB) GetAllByEmailAddress(ea string, everything bool) (*types.ComplaintsAndProfile, error) {
	var cap types.ComplaintsAndProfile

	if cp, err := cdb.GetProfileByEmailAddress(ea); err == datastore.ErrNoSuchEntity {
		return nil, nil // No such profile exists
	} else if err != nil {
		return nil, err // A real problem occurred
	} else {
		cap.Profile = *cp
	}

	if everything {
		if c, err := cdb.GetComplaintsByEmailAddress(ea); err != nil {
			return nil, err
		} else {
			cap.Complaints = c
		}

	} else {
		// Just today
		s, e := date.WindowForToday()
		if c, err := cdb.GetComplaintsInSpanByEmailAddress(ea, s, e); err != nil {
			return nil, err
		} else {
			cap.Complaints = c
		}
	}

	if counts, err := cdb.getDailyCountsByEmailAdress(ea); err != nil {
		return nil, err
	} else {
		cap.Counts = counts
	}

	return &cap, nil
}