/
geojson.go
82 lines (74 loc) · 2.46 KB
/
geojson.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package backendgis4
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
)
func GCHandlerFunc(Mongostring, dbname, colname string) string {
koneksyen := GetConnectionMongo(Mongostring, dbname)
datageo := GetAllData(koneksyen, colname)
jsoncihuy, _ := json.Marshal(datageo)
return string(jsoncihuy)
}
func GCFPostCoordinate(Mongostring, dbname, colname string, r *http.Request) string {
req := new(Credents)
conn := GetConnectionMongo(Mongostring, dbname)
resp := new(LonLatProperties)
err := json.NewDecoder(r.Body).Decode(&resp)
if err != nil {
req.Status = strconv.Itoa(http.StatusNotFound)
req.Message = "error parsing application/json: " + err.Error()
} else {
req.Status = strconv.Itoa(http.StatusOK)
Ins := InsertDatajson(conn, colname,
resp.Coordinates,
resp.Name,
resp.Volume,
resp.Type)
req.Message = fmt.Sprintf("%v:%v", "Berhasil Input data", Ins)
}
return ReturnStringStruct(req)
}
func ReturnStringStruct(Data any) string {
jsonee, _ := json.Marshal(Data)
return string(jsonee)
}
func GCFUpdateNameGeojson(Mongostring, dbname, colname string, r *http.Request) string {
req := new(Credents)
resp := new(LonLatProperties)
conn := GetConnectionMongo(Mongostring, dbname)
err := json.NewDecoder(r.Body).Decode(&resp)
if err != nil {
req.Status = strconv.Itoa(http.StatusNotFound)
req.Message = "error parsing application/json: " + err.Error()
} else {
req.Status = strconv.Itoa(http.StatusOK)
Ins := UpdateDatajson(conn, colname,
resp.Name,
resp.Volume,
resp.Type)
req.Message = fmt.Sprintf("%v:%v", "Berhasil Update data", Ins)
}
return ReturnStringStruct(req)
}
func GCFDeleteDataGeojson(Mongostring, dbname, colname string, r *http.Request) string {
req := new(Credents)
resp := new(LonLatProperties)
conn := GetConnectionMongo(Mongostring, dbname)
err := json.NewDecoder(r.Body).Decode(&resp)
if err != nil {
req.Status = strconv.Itoa(http.StatusNotFound)
req.Message = "error parsing application/json: " + err.Error()
} else {
req.Status = strconv.Itoa(http.StatusOK)
delResult, delErr := DeleteDatajson(conn, colname, resp.Name)
if delErr != nil {
req.Status = strconv.Itoa(http.StatusInternalServerError)
req.Message = "error deleting data: " + delErr.Error()
} else {
req.Message = fmt.Sprintf("Berhasil menghapus data. Jumlah data terhapus: %v", delResult.DeletedCount)
}
}
return ReturnStringStruct(req)
}