yats.git

ref: 3d473f4ebb4edaf7f7185d17ea54bdb0244bba7c

server/db/position.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Yats - yats
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Paolo Lulli <kevwe.com>
 * @copyright Paolo Lulli 2024
 */

package db

import (
	"fmt"
	"time"
)

func SavePosition(idClient string, lat float64, lon float64, positionName string) {
	q := fmt.Sprintf("insert into position ( id_client, ptime, lat, lon, name) values ('%s',toTimestamp(now()),%f,%f,'%s');", idClient, lat, lon, positionName)
	fmt.Printf("q=%s", q)
	Session.Query(q).Exec()
}

func SavePositionAt(idClient string, lat float64, lon float64, tstamp time.Time, positionName string) {
	timeAsBytes, _ := tstamp.UTC().MarshalText()
	q := fmt.Sprintf("insert into position ( id_client, ptime, lat, lon, name) values ('%s','%s',%f,%f,'%s');", idClient, string(timeAsBytes), lat, lon, positionName)
	fmt.Printf("q=%s", q)
	Session.Query(q).Exec()
}

func CanReadSourcePosition(idClient string, sourceApp string) bool {
	m := map[string]interface{}{}

	q := fmt.Sprintf(" SELECT name,app,type from sources where id_client='%s' and app='%s' and type='position';", idClient, sourceApp)
	fmt.Println(q)
	iter := Session.Query(q).Iter()

	for iter.MapScan(m) {
		return true
	}
	return false
}