예제 #1
0
func GetDailyReports(date string) (reports []*models.DailyReport, e error) {
	if _, e = time.Parse("2006-01-02", date); e != nil {
		return
	}

	var rows *sql.Rows
	rows, e = _db.Query(`select date, user_id, work, plan, remark, modified_at from daily_reports  where date=? order by date`, date)
	if e != nil {
		log.Println(e)
		return
	}

	defer rows.Close()
	var modifiedAt float64
	for rows.Next() {
		r := new(models.DailyReport)
		e = rows.Scan(&r.Date, &r.UserId, &r.Work, &r.Plan, &r.Remark, &modifiedAt)
		if e != nil {
			log.Println(e)
			return
		}

		r.ModifiedAt = int64(modifiedAt)
		reports = append(reports, r)
	}

	return
}
예제 #2
0
func AddDailyReport(d *models.DailyReport) error {
	if _, e := time.Parse("2006-01-02", d.Date); e != nil {
		log.Println("AddDailyReport", e)
		return e
	}

	d.ModifiedAt = time.Now().Unix()
	_, e := _db.Exec(`insert or replace into daily_reports(date, user_id, work, plan, remark, modified_at) values(?,?,?,?,?,?)`,
		d.Date, d.UserId, d.Work, d.Plan, d.Remark, d.ModifiedAt)
	if e != nil {
		log.Println(e)
		return e
	}

	return nil
}