/
koneksi.go
39 lines (32 loc) · 1.09 KB
/
koneksi.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
package gcfbackend1214018
import (
"os"
"github.com/aiteung/atdb"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
func SetConnection(MONGOCONNSTRINGENV, dbname string) *mongo.Database {
var DBmongoinfo = atdb.DBInfo{
DBString: os.Getenv(MONGOCONNSTRINGENV),
DBName: dbname,
}
return atdb.MongoConnect(DBmongoinfo)
}
func GetAllBangunanLineString(mongoconn *mongo.Database, collection string) []GeoJson {
lokasi := atdb.GetAllDoc[[]GeoJson](mongoconn, collection)
return lokasi
}
func IsPasswordValid(mongoconn *mongo.Database, collection string, userdata User) bool {
filter := bson.M{"username": userdata.Username}
res := atdb.GetOneDoc[User](mongoconn, collection, filter)
return CheckPasswordHash(userdata.Password, res.Password)
}
func InsertDataLonlat(mongoconn *mongo.Database, collection string, coordinate []float64, name, volume, tipe string) (InsertedID interface{}) {
req := new(CoorLonLatProperties)
req.Type = tipe
req.Coordinates = coordinate
req.Name = name
req.Volume = volume
ins := atdb.InsertOneDoc(mongoconn, collection, req)
return ins
}