Skip to content

Commit

Permalink
Merge pull request #1 from Haransis/feat/update-token
Browse files Browse the repository at this point in the history
🐛 fix few bugs
  • Loading branch information
Haransis authored Nov 8, 2023
2 parents debbe22 + 9b46443 commit 3b036eb
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 5 deletions.
15 changes: 15 additions & 0 deletions controller/geojson.go → controller/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ func (c *Controller) refreshGeoJson() {
}
}

func (c *Controller) ClearGeoPoint(ctx *gin.Context) {
ctx.Next()
picture := ctx.GetString("picture")
sound := ctx.GetString("sound")

if err := os.Remove(picture); err != nil {
log.Println("could not rm picture: ", err)
}
if err := os.Remove(sound); err != nil {
log.Println("could not rm sound: ", err)
}

c.refreshGeoJson()
}

func (c *Controller) AppendGeoJson(ctx *gin.Context) {
ctx.Next()
geoId := ctx.GetUint64("geoId")
Expand Down
16 changes: 16 additions & 0 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ func TestDeleteGeoPoint(t *testing.T) {
}

for _, test := range tests {
var toDelete geopoint.DbGeoPoint

if test.StatusCode == http.StatusOK {
if err := c.Db.Get(&toDelete, "SELECT * FROM geopoints WHERE id = $1", test.IdToDelete); err != nil {
t.Fatalf("could not get geopoint: %s", err)
}
}

w := httptest.NewRecorder()

req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/restricted/geopoint/%d", test.IdToDelete), nil)
Expand All @@ -505,6 +513,14 @@ func TestDeleteGeoPoint(t *testing.T) {
var geoPoint geopoint.DbGeoPoint
err := c.Db.Get(&geoPoint, "SELECT * FROM geopoints WHERE id = $1", test.IdToDelete)
assert.Equal(t, err, sql.ErrNoRows)

_, err = os.Open(toDelete.Picture)
_, ok := err.(*os.PathError)
assert.Equal(t, ok, true)

_, err = os.Open(toDelete.Picture)
_, ok = err.(*os.PathError)
assert.Equal(t, ok, true)
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion controller/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (c *Controller) GetClosestGeoPoint(ctx *gin.Context) {
return
}

target := postgis.PointS{X: closestTo.Latitude, Y: closestTo.Longitude, SRID: geopoint.WGS84}
target := postgis.PointS{X: closestTo.Longitude, Y: closestTo.Latitude, SRID: geopoint.WGS84}
if closestTo.SRID != nil {
target.SRID = *closestTo.SRID
}
Expand Down Expand Up @@ -245,6 +245,13 @@ func (c *Controller) DeleteGeoPoint(ctx *gin.Context) {
return
}

var geopoint geopoint.DbGeoPoint
if err := c.Db.Get(&geopoint, database.GetGeoPoint, id); err != nil {
ctx.Error(err).SetType(gin.ErrorTypeAny).SetMeta("-> could not get geopoint")
ctx.Abort()
return
}

result, err := c.Db.Exec(database.DeleteGeoPoint, id)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
Expand All @@ -261,6 +268,9 @@ func (c *Controller) DeleteGeoPoint(ctx *gin.Context) {
return
}

ctx.Set("picture", geopoint.Picture)
ctx.Set("sound", geopoint.Sound)

ctx.JSON(http.StatusOK, gin.H{"message": "geopoint was deleted"})
}

Expand Down
2 changes: 1 addition & 1 deletion controller/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func SetupRouter(c *Controller) *gin.Engine {
toAdmins.PATCH("/geopoint/:id/enable", c.EnableGeoPoint, c.AppendGeoJson)
toAdmins.PATCH("/user/:id", c.MakeAdmin)
toAdmins.GET("/geopoint/:id", c.GetGeoPoint)
toAdmins.DELETE("/geopoint/:id", c.DeleteGeoPoint)
toAdmins.DELETE("/geopoint/:id", c.DeleteGeoPoint, c.ClearGeoPoint)
}
}
v1.GET("/ping", c.Pong)
Expand Down
2 changes: 1 addition & 1 deletion public/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
assets/picture/[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]-[0-9a-z][0-9a-z][0-9a-z][0-9a-z]-[0-9a-z][0-9a-z][0-9a-z][0-9a-z]-[0-9a-z][0-9a-z][0-9a-z][0-9a-z]-[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z].jpg
assets/picture/[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]-[0-9a-z][0-9a-z][0-9a-z][0-9a-z]-[0-9a-z][0-9a-z][0-9a-z][0-9a-z]-[0-9a-z][0-9a-z][0-9a-z][0-9a-z]-[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z].webp
assets/sound/*
assets/!sound/.gitkeep
assets/geojson.json
4 changes: 2 additions & 2 deletions public/web/scripts/mapbox.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mapboxgl.accessToken = 'pk.eyJ1IjoiaGFyYW5zaXMiLCJhIjoiY2thd2FqZWozMXJuczJ4cWZycHo2Njl6MyJ9.JEmqtXLcoWK1euOnKJvxrQ';
mapboxgl.accessToken = 'pk.eyJ1IjoiaGFyYW5zaXMiLCJhIjoiY2xhbXdmcWM1MGJnajN4bjA2OWQxZzV6ciJ9.ZjF8Laz8eHSYNvJOWNm93g';
const baseUrl = window.location.protocol + '//' + window.location.host + '/api/v1/assets/'
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/geoffreydorne/cjy30xoii1tid1crv9bz19hct',
style: 'mapbox://styles/haransis/clesss239000801s0jzzy7nxz',
center: [14.012033, 49.245659],
zoom: 4,
});
Expand Down
1 change: 1 addition & 0 deletions testassets/geojson.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type" : "FeatureCollection", "features" : [{"type": "Feature", "geometry": {"type":"Point","coordinates":[-1.55362,47.21837]}, "properties": {"id": 1, "name": "WithTemplate"}},{"type": "Feature", "geometry": {"type":"Point","coordinates":[2.615863333,44.677165]}, "properties": {"id": 2, "name": "WithPicture"}}]}
Loading

0 comments on commit 3b036eb

Please sign in to comment.