/
function.go
48 lines (42 loc) · 1.27 KB
/
function.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
43
44
45
46
47
48
package gcpbackends6
import (
"context"
pasproj "github.com/HRMonitorr/PasetoprojectBackend"
"github.com/whatsauth/watoken"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
func InsertUserdata(MongoConn *mongo.Database, username, password string) (InsertedID interface{}) {
req := new(RegisterStruct)
req.Username = username
req.Password = password
return pasproj.InsertOneDoc(MongoConn, "user", req)
}
func UpdateNameGeo(Mongoenv, dbname string, ctx context.Context, val LonLatProperties) (UpdateID interface{}) {
conn := GetConnectionMongo(Mongoenv, dbname)
filter := bson.D{{"volume", val.Volume}}
update := bson.D{{"$set", bson.D{
{"name", val.Name},
}}}
res, err := conn.Collection("lonlatpost").UpdateOne(ctx, filter, update)
if err != nil {
return "Gagal Update"
}
return res
}
func DeleteDataGeo(Mongoenv, dbname string, ctx context.Context, val LonLatProperties) (DeletedId interface{}) {
conn := GetConnectionMongo(Mongoenv, dbname)
filter := bson.D{{"volume", val.Volume}}
res, err := conn.Collection("lonlatpost").DeleteOne(ctx, filter)
if err != nil {
return "Gagal Delete"
}
return res
}
func IsExist(Tokenstr, PublicKey string) bool {
id := watoken.DecodeGetId(PublicKey, Tokenstr)
if id == "" {
return false
}
return true
}