sql error handling: no rows + duplicated key
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
@@ -1,40 +0,0 @@
|
||||
.openapi-generator-ignore
|
||||
Dockerfile
|
||||
README.md
|
||||
api/openapi.yaml
|
||||
go.mod
|
||||
go/api.go
|
||||
go/api_bookings_filter.go
|
||||
go/api_bookings_filter_service.go
|
||||
go/api_driver_availability_and_schedule.go
|
||||
go/api_driver_availability_and_schedule_service.go
|
||||
go/api_interact.go
|
||||
go/api_interact_service.go
|
||||
go/api_passenger_trip_request.go
|
||||
go/api_passenger_trip_request_service.go
|
||||
go/api_search.go
|
||||
go/api_search_service.go
|
||||
go/error.go
|
||||
go/helpers.go
|
||||
go/impl.go
|
||||
go/logger.go
|
||||
go/model__passenger_post_400_response.go
|
||||
go/model_booking.go
|
||||
go/model_booking_request.go
|
||||
go/model_booking_status.go
|
||||
go/model_car.go
|
||||
go/model_driver_journey.go
|
||||
go/model_driver_punctual_availabilities_request.go
|
||||
go/model_driver_regular_availabilities_request.go
|
||||
go/model_driver_trip.go
|
||||
go/model_get_bookings_404_response.go
|
||||
go/model_journey_schedule.go
|
||||
go/model_passenger_trip_request.go
|
||||
go/model_post_connections_request.go
|
||||
go/model_preferences.go
|
||||
go/model_price.go
|
||||
go/model_punctual_availability_slot.go
|
||||
go/model_regular_availability_slot.go
|
||||
go/model_user.go
|
||||
go/routers.go
|
||||
main.go
|
||||
@@ -1 +0,0 @@
|
||||
7.0.1
|
||||
File diff suppressed because it is too large
Load Diff
@@ -44,7 +44,7 @@ func (s *BookingsFilterAPIService) FilterBookingsByStatus(ctx context.Context, o
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
if strings.Contains(err.Error(), " no rows in result set") {
|
||||
return Response(http.StatusBadRequest, "ID not found in the database"), nil
|
||||
return Response(http.StatusBadRequest, "no related data recheck your parameters"), nil
|
||||
} else {
|
||||
return Response(http.StatusInternalServerError, nil), nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ import (
|
||||
"solidarity-service/handler"
|
||||
"solidarity-service/internal"
|
||||
"solidarity-service/storage"
|
||||
"solidarity-service/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DriverAvailabilityAndScheduleAPIService is a service that implements the logic for the DriverAvailabilityAndScheduleAPIServicer
|
||||
@@ -77,6 +79,9 @@ func (s *DriverAvailabilityAndScheduleAPIService) DriverPunctualAvailabilitiesPo
|
||||
driver.Car.Model = driverPunctualAvailabilitiesRequest.Car.Model
|
||||
err := s.storage.CreateDriver(driver)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), utils.SQL_DUPLICATE) {
|
||||
return Response(http.StatusBadRequest, "ID already in use"), nil
|
||||
}
|
||||
return Response(http.StatusInternalServerError, nil), errors.New("DriverPunctualAvailabilitiesPost internal server error")
|
||||
} else {
|
||||
return Response(201, "Punctual driver availabilities set successfully"), nil
|
||||
@@ -120,6 +125,9 @@ func (s *DriverAvailabilityAndScheduleAPIService) DriverRegularAvailabilitiesPos
|
||||
driver.Car.Model = driverRegularAvailabilitiesRequest.Car.Model
|
||||
err := s.storage.CreateDriver(driver)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), utils.SQL_DUPLICATE) {
|
||||
return Response(http.StatusBadRequest, "ID already in use"), nil
|
||||
}
|
||||
return Response(http.StatusInternalServerError, nil), errors.New("DriverPunctualAvailabilitiesPost internal server error")
|
||||
} else {
|
||||
return Response(201, "Regular driver availabilities set successfully"), nil
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"solidarity-service/handler"
|
||||
"solidarity-service/internal"
|
||||
"solidarity-service/storage"
|
||||
"solidarity-service/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -44,7 +45,7 @@ func (s *InteractAPIService) GetBookings(ctx context.Context, operator string, b
|
||||
booking, err := s.storage.GetBooking(bookingId)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), " no rows in result set") {
|
||||
return Response(http.StatusBadRequest, "ID not found in the database"), nil
|
||||
return Response(http.StatusBadRequest, "no related data recheck your parameters"), nil
|
||||
} else {
|
||||
return Response(http.StatusInternalServerError, nil), errors.New("DriverPunctualAvailabilitiesPost internal server error")
|
||||
}
|
||||
@@ -114,7 +115,7 @@ func (s *InteractAPIService) PatchBookings(ctx context.Context, operator string,
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), " no rows in result set") {
|
||||
return Response(http.StatusBadRequest, "ID not found in the database"), nil
|
||||
return Response(http.StatusBadRequest, "no related data recheck your params"), nil
|
||||
}
|
||||
return Response(http.StatusInternalServerError, nil), nil
|
||||
}
|
||||
@@ -131,6 +132,9 @@ func (s *InteractAPIService) PostBookings(ctx context.Context, bookingRequest Bo
|
||||
booking.Operator = bookingRequest.Operator
|
||||
err := s.storage.CreateBooking(booking)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), utils.SQL_DUPLICATE) {
|
||||
return Response(http.StatusBadRequest, "ID already in use"), nil
|
||||
}
|
||||
return Response(http.StatusInternalServerError, nil), errors.New("PostBookings internal server error")
|
||||
}
|
||||
passenger, err := s.storage.GetPassenger(booking.Passenger_id)
|
||||
|
||||
@@ -19,6 +19,8 @@ import (
|
||||
"solidarity-service/handler"
|
||||
"solidarity-service/internal"
|
||||
"solidarity-service/storage"
|
||||
"solidarity-service/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PassengerTripRequestAPIService is a service that implements the logic for the PassengerTripRequestAPIServicer
|
||||
@@ -73,6 +75,9 @@ func (s *PassengerTripRequestAPIService) PassengerPost(ctx context.Context, pass
|
||||
passenger.Preferences.Music = passengerTripRequest.Preferences.Music
|
||||
err := s.storage.CreatePassenger(passenger)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), utils.SQL_DUPLICATE) {
|
||||
return Response(http.StatusBadRequest, "ID already in use"), nil
|
||||
}
|
||||
return Response(http.StatusInternalServerError, nil), errors.New("DriverPunctualAvailabilitiesPost internal server error")
|
||||
} else {
|
||||
return Response(201, "Trip request created"), nil
|
||||
|
||||
@@ -36,5 +36,5 @@ func Run(cfg *viper.Viper, handler *handler.SolidarityServiceHandler, storage st
|
||||
|
||||
router := openapi.NewRouter(BookingsFilterAPIController, DriverAvailabilityAndScheduleAPIController, InteractAPIController, PassengerTripRequestAPIController, SearchAPIController)
|
||||
|
||||
log.Fatal(http.ListenAndServe(":9999", router))
|
||||
log.Fatal(http.ListenAndServe(cfg.GetString("services.solidarity-api.address"), router))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user