Esempio n. 1
0
func scanReport(rows *sql.Rows) (string, schema.ReportHeader, error) {
	hdr := schema.ReportHeader{Grade: -1}
	var comment sql.NullString
	var delivery, reviewed pq.NullTime
	var grade sql.NullInt64
	var student string
	err := rows.Scan(
		&student,
		&hdr.Kind,
		&hdr.Deadline,
		&delivery,
		&reviewed,
		&grade,
		&comment,
		&hdr.Private,
		&hdr.ToGrade)
	if err != nil {
		return "", hdr, mapCstrToError(err)
	}
	if comment.Valid {
		hdr.Comment = comment.String
	}
	hdr.Deadline = hdr.Deadline.Truncate(time.Minute).UTC()
	hdr.Delivery = nullableTime(delivery)
	hdr.Reviewed = nullableTime(reviewed)
	if grade.Valid {
		hdr.Grade = int(grade.Int64)
	}
	return student, hdr, mapCstrToError(err)
}
Esempio n. 2
0
//ReportHeader returns a report
func ReportHeader(k string, deadline time.Time, others ...time.Time) schema.ReportHeader {
	hdr := schema.ReportHeader{
		Kind:     k,
		Deadline: deadline,
	}
	if len(others) >= 1 {
		hdr.Delivery = &others[0]
	}
	if len(others) == 2 {
		hdr.Reviewed = &others[1]
	}
	return hdr
}