refactoring fmt + moving utils

This commit is contained in:
sbouaram 2023-10-20 13:47:51 +02:00
parent 6696cd3152
commit b7bba4cdaa
25 changed files with 71 additions and 91 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/solidarity-service.iml" filepath="$PROJECT_DIR$/.idea/solidarity-service.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -3,7 +3,7 @@ package handler
import ( import (
"github.com/paulmach/orb" "github.com/paulmach/orb"
"github.com/paulmach/orb/geojson" "github.com/paulmach/orb/geojson"
"solidarity-service/servers/utils" "solidarity-service/utils"
) )
func (handler *SolidarityServiceHandler) CalculateDistanceBetweenFeatures(feature1, feature2 *geojson.Feature) int64 { func (handler *SolidarityServiceHandler) CalculateDistanceBetweenFeatures(feature1, feature2 *geojson.Feature) int64 {

View File

@ -15,7 +15,7 @@ import (
// Response return a ImplResponse struct filled // Response return a ImplResponse struct filled
func Response(code int, body interface{}) ImplResponse { func Response(code int, body interface{}) ImplResponse {
return ImplResponse { return ImplResponse{
Code: code, Code: code,
Body: body, Body: body,
} }

View File

@ -9,11 +9,7 @@
package openapi package openapi
type PassengerPost400Response struct { type PassengerPost400Response struct {
Error string `json:"error,omitempty"` Error string `json:"error,omitempty"`
} }

View File

@ -9,9 +9,6 @@
package openapi package openapi
type BookingRequest struct { type BookingRequest struct {
// Booking id is common between both operators, and must be created as a [UUID](https://datatracker.ietf.org/doc/html/rfc4122) by whoever initiates the booking. Usage of a [4 UUID](https://datatracker.ietf.org/doc/html/rfc4122#section-4.4) generation algorithm is advised. // Booking id is common between both operators, and must be created as a [UUID](https://datatracker.ietf.org/doc/html/rfc4122) by whoever initiates the booking. Usage of a [4 UUID](https://datatracker.ietf.org/doc/html/rfc4122#section-4.4) generation algorithm is advised.
@ -29,11 +26,11 @@ type BookingRequest struct {
// AssertBookingRequestRequired checks if the required fields are not zero-ed // AssertBookingRequestRequired checks if the required fields are not zero-ed
func AssertBookingRequestRequired(obj BookingRequest) error { func AssertBookingRequestRequired(obj BookingRequest) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"id": obj.Id, "id": obj.Id,
"passengerId": obj.PassengerId, "passengerId": obj.PassengerId,
"driverId": obj.DriverId, "driverId": obj.DriverId,
"status": obj.Status, "status": obj.Status,
"operator": obj.Operator, "operator": obj.Operator,
} }
for name, el := range elements { for name, el := range elements {
if isZero := IsZeroValue(el); isZero { if isZero := IsZeroValue(el); isZero {

View File

@ -9,19 +9,17 @@
package openapi package openapi
// BookingStatus : Status of the booking. // BookingStatus : Status of the booking.
type BookingStatus string type BookingStatus string
// List of BookingStatus // List of BookingStatus
const ( const (
WAITING_DRIVER_CONFIRMATION BookingStatus = "WAITING_DRIVER_CONFIRMATION" WAITING_DRIVER_CONFIRMATION BookingStatus = "WAITING_DRIVER_CONFIRMATION"
WAITING_PASSENGER_CONFIRMATION BookingStatus = "WAITING_PASSENGER_CONFIRMATION" WAITING_PASSENGER_CONFIRMATION BookingStatus = "WAITING_PASSENGER_CONFIRMATION"
CONFIRMED BookingStatus = "CONFIRMED" CONFIRMED BookingStatus = "CONFIRMED"
CANCELLED BookingStatus = "CANCELLED" CANCELLED BookingStatus = "CANCELLED"
COMPLETED_PENDING_VALIDATION BookingStatus = "COMPLETED_PENDING_VALIDATION" COMPLETED_PENDING_VALIDATION BookingStatus = "COMPLETED_PENDING_VALIDATION"
VALIDATED BookingStatus = "VALIDATED" VALIDATED BookingStatus = "VALIDATED"
) )
// AssertBookingStatusRequired checks if the required fields are not zero-ed // AssertBookingStatusRequired checks if the required fields are not zero-ed

View File

@ -9,9 +9,6 @@
package openapi package openapi
type Car struct { type Car struct {
// Model of the car. // Model of the car.

View File

@ -9,9 +9,6 @@
package openapi package openapi
type DriverPunctualAvailabilitiesRequest struct { type DriverPunctualAvailabilitiesRequest struct {
// The address or location description. // The address or location description.
@ -38,12 +35,12 @@ type DriverPunctualAvailabilitiesRequest struct {
// AssertDriverPunctualAvailabilitiesRequestRequired checks if the required fields are not zero-ed // AssertDriverPunctualAvailabilitiesRequestRequired checks if the required fields are not zero-ed
func AssertDriverPunctualAvailabilitiesRequestRequired(obj DriverPunctualAvailabilitiesRequest) error { func AssertDriverPunctualAvailabilitiesRequestRequired(obj DriverPunctualAvailabilitiesRequest) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"address": obj.Address, "address": obj.Address,
"latitude": obj.Latitude, "latitude": obj.Latitude,
"longitude": obj.Longitude, "longitude": obj.Longitude,
"radius": obj.Radius, "radius": obj.Radius,
"availabilities": obj.Availabilities, "availabilities": obj.Availabilities,
"user": obj.User, "user": obj.User,
} }
for name, el := range elements { for name, el := range elements {
if isZero := IsZeroValue(el); isZero { if isZero := IsZeroValue(el); isZero {

View File

@ -9,9 +9,6 @@
package openapi package openapi
type DriverRegularAvailabilitiesRequest struct { type DriverRegularAvailabilitiesRequest struct {
// The address or location description. // The address or location description.
@ -38,12 +35,12 @@ type DriverRegularAvailabilitiesRequest struct {
// AssertDriverRegularAvailabilitiesRequestRequired checks if the required fields are not zero-ed // AssertDriverRegularAvailabilitiesRequestRequired checks if the required fields are not zero-ed
func AssertDriverRegularAvailabilitiesRequestRequired(obj DriverRegularAvailabilitiesRequest) error { func AssertDriverRegularAvailabilitiesRequestRequired(obj DriverRegularAvailabilitiesRequest) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"address": obj.Address, "address": obj.Address,
"latitude": obj.Latitude, "latitude": obj.Latitude,
"longitude": obj.Longitude, "longitude": obj.Longitude,
"radius": obj.Radius, "radius": obj.Radius,
"availabilities": obj.Availabilities, "availabilities": obj.Availabilities,
"user": obj.User, "user": obj.User,
} }
for name, el := range elements { for name, el := range elements {
if isZero := IsZeroValue(el); isZero { if isZero := IsZeroValue(el); isZero {

View File

@ -9,11 +9,7 @@
package openapi package openapi
type DriverTrip struct { type DriverTrip struct {
User User `json:"user"` User User `json:"user"`
Car Car `json:"car,omitempty"` Car Car `json:"car,omitempty"`

View File

@ -9,9 +9,6 @@
package openapi package openapi
type GetBookings404Response struct { type GetBookings404Response struct {
// Explain why the request couldn't be processed. // Explain why the request couldn't be processed.

View File

@ -9,9 +9,6 @@
package openapi package openapi
type JourneySchedule struct { type JourneySchedule struct {
// Passenger pickup datetime as a UNIX UTC timestamp in seconds. // Passenger pickup datetime as a UNIX UTC timestamp in seconds.
@ -28,7 +25,7 @@ type JourneySchedule struct {
func AssertJourneyScheduleRequired(obj JourneySchedule) error { func AssertJourneyScheduleRequired(obj JourneySchedule) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"passengerPickupDate": obj.PassengerPickupDate, "passengerPickupDate": obj.PassengerPickupDate,
"type": obj.Type, "type": obj.Type,
} }
for name, el := range elements { for name, el := range elements {
if isZero := IsZeroValue(el); isZero { if isZero := IsZeroValue(el); isZero {

View File

@ -9,11 +9,7 @@
package openapi package openapi
type PassengerTripRequest struct { type PassengerTripRequest struct {
User User `json:"user"` User User `json:"user"`
DestinationAddress string `json:"destination_address"` DestinationAddress string `json:"destination_address"`
@ -37,14 +33,14 @@ type PassengerTripRequest struct {
// AssertPassengerTripRequestRequired checks if the required fields are not zero-ed // AssertPassengerTripRequestRequired checks if the required fields are not zero-ed
func AssertPassengerTripRequestRequired(obj PassengerTripRequest) error { func AssertPassengerTripRequestRequired(obj PassengerTripRequest) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"user": obj.User, "user": obj.User,
"destination_address": obj.DestinationAddress, "destination_address": obj.DestinationAddress,
"destination_latitude": obj.DestinationLatitude, "destination_latitude": obj.DestinationLatitude,
"destination_longitude": obj.DestinationLongitude, "destination_longitude": obj.DestinationLongitude,
"departure_address": obj.DepartureAddress, "departure_address": obj.DepartureAddress,
"departure_latitude": obj.DepartureLatitude, "departure_latitude": obj.DepartureLatitude,
"departure_longitude": obj.DepartureLongitude, "departure_longitude": obj.DepartureLongitude,
"departure_date": obj.DepartureDate, "departure_date": obj.DepartureDate,
} }
for name, el := range elements { for name, el := range elements {
if isZero := IsZeroValue(el); isZero { if isZero := IsZeroValue(el); isZero {

View File

@ -9,11 +9,7 @@
package openapi package openapi
type PostConnectionsRequest struct { type PostConnectionsRequest struct {
From User `json:"from"` From User `json:"from"`
To User `json:"to"` To User `json:"to"`
@ -37,9 +33,9 @@ type PostConnectionsRequest struct {
// AssertPostConnectionsRequestRequired checks if the required fields are not zero-ed // AssertPostConnectionsRequestRequired checks if the required fields are not zero-ed
func AssertPostConnectionsRequestRequired(obj PostConnectionsRequest) error { func AssertPostConnectionsRequestRequired(obj PostConnectionsRequest) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"from": obj.From, "from": obj.From,
"to": obj.To, "to": obj.To,
"message": obj.Message, "message": obj.Message,
"recipientCarpoolerType": obj.RecipientCarpoolerType, "recipientCarpoolerType": obj.RecipientCarpoolerType,
} }
for name, el := range elements { for name, el := range elements {

View File

@ -9,13 +9,10 @@
package openapi package openapi
import ( import (
"errors" "errors"
) )
type Preferences struct { type Preferences struct {
// If driver journey, specifies if the driver allows smoking in the car. // If driver journey, specifies if the driver allows smoking in the car.

View File

@ -9,9 +9,6 @@
package openapi package openapi
type Price struct { type Price struct {
// Either « FREE », « PAYING » or « UNKNOWN ». « UNKNOWN » is given when it should be « PAYING » but we cannot set the price yet. // Either « FREE », « PAYING » or « UNKNOWN ». « UNKNOWN » is given when it should be « PAYING » but we cannot set the price yet.

View File

@ -9,9 +9,6 @@
package openapi package openapi
type PunctualAvailabilitySlot struct { type PunctualAvailabilitySlot struct {
// UNIX UTC timestamp in seconds. // UNIX UTC timestamp in seconds.
@ -27,9 +24,9 @@ type PunctualAvailabilitySlot struct {
// AssertPunctualAvailabilitySlotRequired checks if the required fields are not zero-ed // AssertPunctualAvailabilitySlotRequired checks if the required fields are not zero-ed
func AssertPunctualAvailabilitySlotRequired(obj PunctualAvailabilitySlot) error { func AssertPunctualAvailabilitySlotRequired(obj PunctualAvailabilitySlot) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"date": obj.Date, "date": obj.Date,
"startTime": obj.StartTime, "startTime": obj.StartTime,
"endTime": obj.EndTime, "endTime": obj.EndTime,
} }
for name, el := range elements { for name, el := range elements {
if isZero := IsZeroValue(el); isZero { if isZero := IsZeroValue(el); isZero {

View File

@ -9,9 +9,6 @@
package openapi package openapi
type RegularAvailabilitySlot struct { type RegularAvailabilitySlot struct {
// Day of the week for regular scheduling. // Day of the week for regular scheduling.
@ -29,7 +26,7 @@ func AssertRegularAvailabilitySlotRequired(obj RegularAvailabilitySlot) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"dayOfWeek": obj.DayOfWeek, "dayOfWeek": obj.DayOfWeek,
"startTime": obj.StartTime, "startTime": obj.StartTime,
"endTime": obj.EndTime, "endTime": obj.EndTime,
} }
for name, el := range elements { for name, el := range elements {
if isZero := IsZeroValue(el); isZero { if isZero := IsZeroValue(el); isZero {

View File

@ -9,13 +9,10 @@
package openapi package openapi
import ( import (
"errors" "errors"
) )
type User struct { type User struct {
// User's identifier. It MUST be unique for a given `operator`. // User's identifier. It MUST be unique for a given `operator`.
@ -49,9 +46,9 @@ type User struct {
// AssertUserRequired checks if the required fields are not zero-ed // AssertUserRequired checks if the required fields are not zero-ed
func AssertUserRequired(obj User) error { func AssertUserRequired(obj User) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"id": obj.Id, "id": obj.Id,
"operator": obj.Operator, "operator": obj.Operator,
"alias": obj.Alias, "alias": obj.Alias,
} }
for name, el := range elements { for name, el := range elements {
if isZero := IsZeroValue(el); isZero { if isZero := IsZeroValue(el); isZero {

View File

@ -23,8 +23,8 @@ import (
// A Route defines the parameters for an api endpoint // A Route defines the parameters for an api endpoint
type Route struct { type Route struct {
Method string Method string
Pattern string Pattern string
HandlerFunc http.HandlerFunc HandlerFunc http.HandlerFunc
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/spf13/viper" "github.com/spf13/viper"
"solidarity-service/internal" "solidarity-service/internal"
"solidarity-service/servers/utils" "solidarity-service/utils"
"strconv" "strconv"
"strings" "strings"
"time" "time"