Skip to content

Commit

Permalink
fix: pass additional location fields to MSP
Browse files Browse the repository at this point in the history
  • Loading branch information
neinkeinkaffee committed Sep 5, 2023
1 parent 44acdec commit b268d16
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 81 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ fileignoreconfig:
checksum: fb9c6cf09f7864a32c38e40fb8a8598d3c6bd5c406245c6b31666c2ccb1f9e24
- filename: manager/api/api.gen.go
checksum: 711dafa8a64745b56d1848e74e67a96e97c6abe99a927f8783023b42abf46f69
- filename: manager/api/api.gen.go
checksum: 68dd639262ee2def17f4acbd84c23c7281d8a158ebdc0a1e4b757f1cbe283ae0
- filename: manager/api/server.go
checksum: 98cbd1df522ea428f7e669c01721f3070133062378a4f2e4b167d55eaa8d079b
- filename: manager/api/server_test.go
Expand Down
4 changes: 3 additions & 1 deletion manager/api/api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,12 @@ components:
type: "object"
description: "A charge station location"
required:
- "name"
- "address"
- "city"
- "country"
- "country_code"
- "coordinates"
- "party_id"
properties:
country_code:
type: string
Expand Down Expand Up @@ -473,6 +474,7 @@ components:
type: array
items:
$ref: '#/components/schemas/Evse'
nullable: true
GeoLocation:
required:
- latitude
Expand Down
108 changes: 54 additions & 54 deletions manager/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 89 additions & 5 deletions manager/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,36 @@ func (s *Server) RegisterLocation(w http.ResponseWriter, r *http.Request, locati
return
}

now := s.clock.Now()

var numEvses int
if req.Evses != nil {
numEvses = len(*req.Evses)
}
storeEvses := make([]store.Evse, numEvses)
if numEvses != 0 {
for i, reqEvse := range *req.Evses {
storeConnectors := make([]store.Connector, len(reqEvse.Connectors))
for j, reqConnector := range reqEvse.Connectors {
storeConnectors[j] = store.Connector{
Id: reqConnector.Id,
Format: string(reqConnector.Format),
PowerType: string(reqConnector.PowerType),
Standard: string(reqConnector.Standard),
MaxVoltage: reqConnector.MaxVoltage,
MaxAmperage: reqConnector.MaxAmperage,
LastUpdated: now.Format(time.RFC3339),
}
storeEvses[i] = store.Evse{
Connectors: storeConnectors,
EvseId: reqEvse.EvseId,
Status: string(reqEvse.Status),
Uid: reqEvse.Uid,
LastUpdated: now.Format(time.RFC3339),
}
}
}
}
err := s.store.SetLocation(r.Context(), &store.Location{
Address: req.Address,
City: req.City,
Expand All @@ -286,18 +316,72 @@ func (s *Server) RegisterLocation(w http.ResponseWriter, r *http.Request, locati
Longitude: req.Coordinates.Longitude,
},
Country: req.Country,
Evses: nil,
Evses: &storeEvses,
Id: locationId,
Name: req.Name,
ParkingType: (*string)(req.ParkingType),
PostalCode: req.PostalCode,
Name: *req.Name,
ParkingType: string(*req.ParkingType),
PostalCode: *req.PostalCode,
})
if err != nil {
_ = render.Render(w, r, ErrInternalError(err))
return
}

err = s.ocpi.PushLocation(r.Context(), ocpi.Location{Id: "loc001"})
ocpiEvses := make([]ocpi.Evse, numEvses)
if numEvses != 0 {
for i, reqEvse := range *req.Evses {
ocpiConnectors := make([]ocpi.Connector, len(reqEvse.Connectors))
for j, reqConnector := range reqEvse.Connectors {
ocpiConnectors[j] = ocpi.Connector{
Id: reqConnector.Id,
Format: ocpi.ConnectorFormat(reqConnector.Format),
PowerType: ocpi.ConnectorPowerType(reqConnector.PowerType),
Standard: ocpi.ConnectorStandard(reqConnector.Standard),
MaxVoltage: reqConnector.MaxVoltage,
MaxAmperage: reqConnector.MaxAmperage,
LastUpdated: now.Format(time.RFC3339),
}
ocpiEvses[i] = ocpi.Evse{
Connectors: ocpiConnectors,
EvseId: reqEvse.EvseId,
Status: ocpi.EvseStatus(reqEvse.Status),
Uid: reqEvse.Uid,
LastUpdated: now.Format(time.RFC3339),
}
}
}
}
err = s.ocpi.PushLocation(r.Context(), ocpi.Location{
Address: req.Address,
ChargingWhenClosed: nil, // TODO: add to request body schema but make optional
City: req.City,
Coordinates: ocpi.GeoLocation{
Latitude: req.Coordinates.Latitude,
Longitude: req.Coordinates.Longitude,
},
Country: req.Country,
CountryCode: req.CountryCode,
Directions: nil, // TODO: add to request body schema but make optional
EnergyMix: nil, // TODO: add to request body schema but make optional
Evses: &ocpiEvses,
Facilities: nil, // TODO: add to request body schema but make optional
Id: locationId,
Images: nil, // TODO: add to request body schema but make optional
LastUpdated: now.Format(time.RFC3339),
Name: req.Name,
OpeningTimes: nil, // TODO: add to request body schema but make optional
Operator: nil, // TODO: add to request body schema but make optional
Owner: nil, // TODO: add to request body schema but make optional
ParkingType: (*ocpi.LocationParkingType)(req.ParkingType),
PartyId: req.PartyId,
PostalCode: req.PostalCode,
Publish: true,
PublishAllowedTo: nil, // TODO: add to request body schema but make optional
RelatedLocations: nil, // TODO: add to request body schema but make optional
State: nil, // TODO: add to request body schema but make optional
Suboperator: nil, // TODO: add to request body schema but make optional
TimeZone: nil, // TODO: add to request body schema but make optional
})
if err != nil {
_ = render.Render(w, r, ErrInternalError(err))
return
Expand Down
13 changes: 6 additions & 7 deletions manager/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,10 @@ func TestRegisterLocation(t *testing.T) {
"name": "Gent Zuid",
"address": "F.Rooseveltlaan 3A",
"city": "Gent",
"party_id": "TWK",
"postal_code": "9000",
"country": "BEL",
"country_code": "BEL",
"coordinates": {
"latitude": "51.047599",
"longitude": "3.729944"
Expand All @@ -338,10 +340,11 @@ func TestRegisterLocation(t *testing.T) {
Longitude: "3.729944",
},
Country: "BEL",
Evses: &[]store.Evse{},
Id: "loc001",
Name: strPointer("Gent Zuid"),
ParkingType: strPointer("ON_STREET"),
PostalCode: strPointer("9000"),
Name: "Gent Zuid",
ParkingType: "ON_STREET",
PostalCode: "9000",
}
got, err := engine.LookupLocation(context.Background(), "loc001")
require.NoError(t, err)
Expand Down Expand Up @@ -403,7 +406,3 @@ func getCertificateHash(cert *x509.Certificate) string {
b64Hash := base64.RawURLEncoding.EncodeToString(hash[:])
return b64Hash
}

func strPointer(s string) *string {
return &s
}
14 changes: 7 additions & 7 deletions manager/store/firestore/location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func TestSetAndLookupLocation(t *testing.T) {
},
Country: "BEL",
Id: "loc001",
Name: strPointer("Gent Zuid"),
ParkingType: strPointer("ON_STREET"),
PostalCode: strPointer("9000"),
Name: "Gent Zuid",
ParkingType: "ON_STREET",
PostalCode: "9000",
}
err = locationStore.SetLocation(ctx, want)
require.NoError(t, err)
Expand All @@ -53,17 +53,17 @@ func TestListLocations(t *testing.T) {
locations := make([]*store.Location, 20)
for i := 0; i < 20; i++ {
locations[i] = &store.Location{
Address: "Randomlaan 3A",
Address: "Randomstreet 3A",
City: "Randomtown",
Coordinates: store.GeoLocation{
Latitude: fmt.Sprintf("%f", rand.Float32()*90),
Longitude: fmt.Sprintf("%f", rand.Float32()*180),
},
Country: "RAND",
Id: fmt.Sprintf("loc%03d", i),
Name: strPointer("Random Location"),
ParkingType: strPointer("ON_STREET"),
PostalCode: strPointer("12345"),
Name: "Random Location",
ParkingType: "ON_STREET",
PostalCode: "12345",
}
}

Expand Down
16 changes: 9 additions & 7 deletions manager/store/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ type Connector struct {
MaxVoltage int32
PowerType string
Standard string
LastUpdated string
}

type Evse struct {
Connectors []Connector
EvseId *string
Status string
Uid string
Connectors []Connector
EvseId *string
Status string
Uid string
LastUpdated string
}

type Location struct {
Expand All @@ -31,9 +33,9 @@ type Location struct {
Evses *[]Evse
Id string
LastUpdated string
Name *string
ParkingType *string
PostalCode *string
Name string
ParkingType string
PostalCode string
}

type LocationStore interface {
Expand Down

0 comments on commit b268d16

Please sign in to comment.