Skip to content

Commit

Permalink
Merge pull request #1 from MatRouillard/fix-delete
Browse files Browse the repository at this point in the history
Add delete function
  • Loading branch information
GirardinClaire authored Mar 13, 2024
2 parents 59f54f1 + 978bad3 commit 9fc1a48
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/setup.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Vehicle Server CI
on:
- push
- pull_request
jobs:
ci:
runs-on: ubuntu-22.04
Expand All @@ -16,4 +17,8 @@ jobs:
- name: Build application
run: make all
- name: List dist output
run: ls dist/
run: ls dist/
- name: Unit test
run: make unit_test
- name: Integration test
run: make integration_test
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ build:
dist:
mkdir dist

.PHONY: unit_test
unit_test:
go test -v -cover ./...

.PHONY: integration_test
integration_test:
go test -v -count=1 --tags=integration ./app

.PHONY: stop_dev_db
stop_dev_db:
docker container stop $(DB_CONTAINER_NAME)
4 changes: 4 additions & 0 deletions vehicle/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func (f *CreateRequest) validate() []string {
validationIssues = append(validationIssues, "missing short code")
}

if len(f.ShortCode) > 4 {
validationIssues = append(validationIssues, "short code too long")
}

if f.Latitude < -90 || f.Latitude > 90 {
validationIssues = append(validationIssues, "latitude must be >= -90 and <= 90")
}
Expand Down
22 changes: 21 additions & 1 deletion vehicle/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vehicle

import (
"net/http"
"strconv"

"github.com/GirardinClaire/vehicle-server/storage"
"go.uber.org/zap"
Expand All @@ -20,5 +21,24 @@ func NewDeleteHandler(store storage.Store, logger *zap.Logger) *DeleteHandler {
}

func (d *DeleteHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
http.Error(rw, "Not Implemented", http.StatusInternalServerError)
strId := r.PathValue("id")

id, err := strconv.ParseInt(strId, 10, 64)

if err != nil {
http.Error(rw, "Failed to parse ID", http.StatusInternalServerError)
return
}

test, err := d.store.Vehicle().Delete(r.Context(), id)
if err != nil {
http.Error(rw, "Failed to delete vehicle for the id", http.StatusInternalServerError)
return
}

if test {
rw.WriteHeader(http.StatusNoContent)
} else {
rw.WriteHeader(http.StatusNotFound)
}
}

0 comments on commit 9fc1a48

Please sign in to comment.