Skip to content

Commit

Permalink
Merge pull request #1 from satimoto/release/v0.2.0
Browse files Browse the repository at this point in the history
OCPI release v0.2.0
  • Loading branch information
dangeross authored Sep 13, 2022
2 parents b52f01f + 31fbd08 commit 5ebdca7
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/joho/godotenv v1.4.0
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
github.com/prometheus/client_golang v1.12.1
github.com/satimoto/go-datastore v0.1.2-0.20220805214902-ea4b06bdc5fc
github.com/satimoto/go-datastore v0.2.1-0.20220831073447-93cd95eaae40
google.golang.org/grpc v1.46.0
)

Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ github.com/satimoto/go-datastore v0.1.2-0.20220805214327-a9c71370cb15 h1:agKEIHH
github.com/satimoto/go-datastore v0.1.2-0.20220805214327-a9c71370cb15/go.mod h1:SvM8losYPwH6hJgUKLkjNtQwVv06lZgCMWl8cGdllCM=
github.com/satimoto/go-datastore v0.1.2-0.20220805214902-ea4b06bdc5fc h1:IBagDAoSUJpBdfqv6Z510p263Hc7pLIr2Xpklx6mBa4=
github.com/satimoto/go-datastore v0.1.2-0.20220805214902-ea4b06bdc5fc/go.mod h1:SvM8losYPwH6hJgUKLkjNtQwVv06lZgCMWl8cGdllCM=
github.com/satimoto/go-datastore v0.2.1-0.20220819180024-a135c70c2f7b h1:Ct9eyvj3FXr876kXglEp3ms1mxofwpQEw+RlKuBnFvU=
github.com/satimoto/go-datastore v0.2.1-0.20220819180024-a135c70c2f7b/go.mod h1:SvM8losYPwH6hJgUKLkjNtQwVv06lZgCMWl8cGdllCM=
github.com/satimoto/go-datastore v0.2.1-0.20220819180210-ed0f1ecb0e87 h1:PCZwlDPOKiPOmLYMcmXsa4c12cyG2+sExPnQiCp29cQ=
github.com/satimoto/go-datastore v0.2.1-0.20220819180210-ed0f1ecb0e87/go.mod h1:SvM8losYPwH6hJgUKLkjNtQwVv06lZgCMWl8cGdllCM=
github.com/satimoto/go-datastore v0.2.1-0.20220829195216-266c7018778e h1:T9aZoZZZdmhW/3Bz78QQ7bwQtjAR0dMA/GIvXCbqpqg=
github.com/satimoto/go-datastore v0.2.1-0.20220829195216-266c7018778e/go.mod h1:SvM8losYPwH6hJgUKLkjNtQwVv06lZgCMWl8cGdllCM=
github.com/satimoto/go-datastore v0.2.1-0.20220831073447-93cd95eaae40 h1:WeAClxmTZu1M/JR7XLC4C2O35u/CQ44aAsH2WA3InL8=
github.com/satimoto/go-datastore v0.2.1-0.20220831073447-93cd95eaae40/go.mod h1:SvM8losYPwH6hJgUKLkjNtQwVv06lZgCMWl8cGdllCM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
Expand Down
13 changes: 7 additions & 6 deletions internal/element/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"context"
"log"

"github.com/satimoto/go-datastore/pkg/db"
"github.com/satimoto/go-datastore/pkg/util"
)

func (r *ElementResolver) ReplaceElements(ctx context.Context, tariffID int64, dto []*ElementDto) {
func (r *ElementResolver) ReplaceElements(ctx context.Context, tariff db.Tariff, dto []*ElementDto) {
if dto != nil {
r.PriceComponentResolver.Repository.DeletePriceComponents(ctx, tariffID)
r.Repository.DeleteElements(ctx, tariffID)
r.ElementRestrictionResolver.Repository.DeleteElementRestrictions(ctx, tariffID)
r.PriceComponentResolver.Repository.DeletePriceComponents(ctx, tariff.ID)
r.Repository.DeleteElements(ctx, tariff.ID)
r.ElementRestrictionResolver.Repository.DeleteElementRestrictions(ctx, tariff.ID)

for _, elementDto := range dto {
elementParams := NewCreateElementParams(elementDto)
elementParams.TariffID = tariffID
elementParams.TariffID = tariff.ID

if elementDto.Restrictions != nil {
restrictionID := util.SqlNullInt64(nil)
Expand All @@ -31,7 +32,7 @@ func (r *ElementResolver) ReplaceElements(ctx context.Context, tariffID int64, d
continue
}

r.PriceComponentResolver.CreatePriceComponents(ctx, element.ID, elementDto.PriceComponents)
r.PriceComponentResolver.CreatePriceComponents(ctx, element.ID, tariff, elementDto.PriceComponents)
}
}
}
4 changes: 3 additions & 1 deletion internal/pricecomponent/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"database/sql"
"log"

"github.com/satimoto/go-datastore/pkg/db"
"github.com/satimoto/go-datastore/pkg/util"
)

func (r *PriceComponentResolver) CreatePriceComponents(ctx context.Context, elementID int64, dto []*PriceComponentDto) {
func (r *PriceComponentResolver) CreatePriceComponents(ctx context.Context, elementID int64, tariff db.Tariff, dto []*PriceComponentDto) {
for _, priceComponentDto := range dto {
priceRoundingID := util.SqlNullInt64(nil)
stepRoundingID := util.SqlNullInt64(nil)
Expand All @@ -22,6 +23,7 @@ func (r *PriceComponentResolver) CreatePriceComponents(ctx context.Context, elem
}

priceComponentParams := NewCreatePriceComponentParams(priceComponentDto)
priceComponentParams.Currency = tariff.Currency
priceComponentParams.ElementID = elementID
priceComponentParams.PriceRoundingID = priceRoundingID
priceComponentParams.StepRoundingID = stepRoundingID
Expand Down
4 changes: 2 additions & 2 deletions internal/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (rs *RestService) listenAndServe() {
err := rs.Server.ListenAndServe()

if err != nil && err != http.ErrServerClosed {
log.Printf("Error in Rest service: %v", err)
util.LogOnError("OCPI276", "Error in Rest service", err)
}
}

Expand All @@ -74,7 +74,7 @@ func (rs *RestService) shutdown() {
err := rs.Server.Shutdown(ctx)

if err != nil {
log.Printf("Error shutting down Rest service: %v", err)
util.LogOnError("OCPI277", "Error shutting down Rest service", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/rpc/command/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (r *RpcCommandResolver) UnlockConnector(ctx context.Context, input *ocpirpc

if err != nil {
util.LogOnError("OCPI157", "Error retrieving session", err)
log.Printf("OCPI57: LocationUid=%v", input.LocationUid)
log.Printf("OCPI157: LocationUid=%v", input.LocationUid)
return nil, errors.New("location not found")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (rs *RpcService) listenAndServe() {
err = rs.Server.Serve(listener)

if err != nil {
log.Printf("Error in Rpc service: %v", err)
util.LogOnError("OCPI278", "Error in Rpc service", err)
}
}

Expand Down
18 changes: 8 additions & 10 deletions internal/rpc/token/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func (r *RpcTokenResolver) CreateToken(ctx context.Context, request *ocpirpc.Cre
authID, err := r.TokenResolver.GenerateAuthID(ctx)

if err != nil {
log.Printf("Error CreateToken GenerateAuthID: %v", err)
log.Printf("Request=%#v", request)
util.LogOnError("OCPI279", "Error generating AuthID", err)
log.Printf("OCPI279: Request=%#v", request)
return nil, errors.New("error creating token")
}

Expand All @@ -41,8 +41,8 @@ func (r *RpcTokenResolver) CreateToken(ctx context.Context, request *ocpirpc.Cre
t := r.TokenResolver.ReplaceToken(ctx, request.UserId, tokenAllowed, *dto.Uid, dto)

if t == nil {
log.Printf("Error CreateToken ReplaceToken: %v", err)
log.Printf("Dto=%#v", dto)
util.LogOnError("OCPI280", "Error replacing token", err)
log.Printf("OCPI280: Dto=%#v", dto)
return nil, errors.New("error creating token")
}

Expand All @@ -57,17 +57,15 @@ func (r *RpcTokenResolver) UpdateTokens(ctx context.Context, request *ocpirpc.Up
tokens, err := r.TokenResolver.Repository.ListTokensByUserID(ctx, request.UserId)

if err != nil {
log.Printf("Error UpdateTokens ListTokensByUserID: %v", err)
log.Printf("Request=%#v", request)
util.LogOnError("OCPI281", "Error listing tokens", err)
log.Printf("OCPI281: Request=%#v", request)
return nil, errors.New("error updating tokens")
}

for _, t := range tokens {
if len(request.Uid) == 0 || request.Uid == t.Uid {
dto := &token.TokenDto{
Uid: &request.Uid,
LastUpdated: util.NilTime(time.Now()),
}
dto := token.NewTokenDto(t)
dto.LastUpdated = util.NilTime(time.Now())

tokenAllowed := t.Allowed

Expand Down
6 changes: 3 additions & 3 deletions internal/tariff/v2.1.1/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r *TariffResolver) ReplaceTariffByIdentifier(ctx context.Context, credenti
}

if dto.Elements != nil {
r.replaceElements(ctx, tariff.ID, dto)
r.replaceElements(ctx, tariff, dto)
}

return &tariff
Expand Down Expand Up @@ -115,6 +115,6 @@ func (r *TariffResolver) replaceTariffAltText(ctx context.Context, tariffID int6
}
}

func (r *TariffResolver) replaceElements(ctx context.Context, tariffID int64, dto *TariffDto) {
r.ElementResolver.ReplaceElements(ctx, tariffID, dto.Elements)
func (r *TariffResolver) replaceElements(ctx context.Context, tariff db.Tariff, dto *TariffDto) {
r.ElementResolver.ReplaceElements(ctx, tariff, dto.Elements)
}

0 comments on commit 5ebdca7

Please sign in to comment.