Skip to content

Commit

Permalink
#22 generated logic example (#3)
Browse files Browse the repository at this point in the history
* #22 generated logic example
  • Loading branch information
ebirukov authored Jan 11, 2024
1 parent 200513f commit 55b6f40
Show file tree
Hide file tree
Showing 30 changed files with 1,017 additions and 318 deletions.
3 changes: 2 additions & 1 deletion example/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ func Test_main(t *testing.T) {
}

updateFxt, _ := fixture.GetUpdateRewardFixtureByCode(ctx, "64G_android", nil)
updateMutatorFxt := fixture.GetUpdateMutatorPartnerFixtureByCode(ctx, "64G_android")

mockFxt := []octopus.FixtureType{
rewardByCodeMocker.ByFixtureCode(ctx, "64G_android"),
updateFxt,
}

mockFxt = append(mockFxt)
mockFxt = append(mockFxt, updateMutatorFxt)

octopusMockServer.SetFixtures(mockFxt)

Expand Down
46 changes: 46 additions & 0 deletions example/model/conv/reward.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package conv

import (
"encoding/json"
"fmt"
"hash/crc32"
"strconv"

"github.com/mailru/activerecord-cookbook/example/model/ds"
"github.com/mailru/activerecord/pkg/serializer"
"github.com/mailru/activerecord/pkg/serializer/errs"
)

func RewardExtraPartUpdate(extra *ds.Extra, partialExtra map[string]any) ([]string, error) {
v, err := json.Marshal(extra)
if err != nil {
return nil, fmt.Errorf("%w: %v", errs.ErrMarshalJSON, err)
}

crc := strconv.Itoa(int(crc32.ChecksumIEEE(v)))

delete(partialExtra, "other")

extraValues, err := serializer.MapstructureMarshal(partialExtra)
if err != nil {
return nil, fmt.Errorf("%w: %v", errs.ErrMarshalJSON, err)
}

return []string{crc, extraValues}, nil
}

func RewardUnlockedPartUpdate(unlocked ds.ServiceUnlocked, partialUnlocked map[string]any) ([]string, error) {
v, err := json.Marshal(unlocked)
if err != nil {
return nil, fmt.Errorf("%w: %v", errs.ErrMarshalJSON, err)
}

crc := strconv.Itoa(int(crc32.ChecksumIEEE(v)))

extraValues, err := serializer.MapstructureMarshal(partialUnlocked)
if err != nil {
return nil, fmt.Errorf("%w: %v", errs.ErrMarshalJSON, err)
}

return []string{crc, extraValues}, nil
}
12 changes: 9 additions & 3 deletions example/model/repository/declaration/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
type FieldsReward struct {
Code string `ar:"primary_key;size:"`
Services string `ar:"serializer:Services;size:"`
Partner string `ar:"selector:SelectByPartner;size:"`
Extra string `ar:"serializer:Extra;size:"`
Partner string `ar:"selector:SelectByPartner;mutators:Partner;size:"`
Extra string `ar:"serializer:Extra;mutators:ExtraPart;size:"`
Flags string `ar:"serializer:Flags;size:"`
Unlocked string `ar:"serializer:Unlocked;size:"`
Unlocked string `ar:"serializer:Unlocked;mutators:UnlockedPart;size:"`
Description string `ar:"serializer:Description;size:"`
}

Expand All @@ -24,3 +24,9 @@ type SerializersReward struct {
Unlocked ds.ServiceUnlocked `ar:"unmarshaler:JSONUnmarshal;marshaler:JSONMarshal"`
Description *string `ar:"unmarshaler:JSONUnmarshal;marshaler:JSONMarshal"`
}

type MutatorsReward struct {
ExtraPart *ds.Extra `ar:"update:lua.updateExtra;pkg:github.com/mailru/activerecord-cookbook/example/model/conv;"`
UnlockedPart ds.ServiceUnlocked `ar:"update:lua.updateUnlocked;pkg:github.com/mailru/activerecord-cookbook/example/model/conv;"`
Partner string `ar:"update:lua.updateRewardPartner,param1,param2;replace:lua.replaceRewardPartner;"`
}
31 changes: 25 additions & 6 deletions example/model/repository/generated/arobj/fixture.go

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

2 changes: 1 addition & 1 deletion example/model/repository/generated/arobj/mock.go

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

22 changes: 12 additions & 10 deletions example/model/repository/generated/arobj/octopus.go

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

25 changes: 22 additions & 3 deletions example/model/repository/generated/boolindexed/fixture.go

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

2 changes: 1 addition & 1 deletion example/model/repository/generated/boolindexed/mock.go

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

20 changes: 10 additions & 10 deletions example/model/repository/generated/boolindexed/octopus.go

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

21 changes: 20 additions & 1 deletion example/model/repository/generated/category/fixture.go

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

2 changes: 1 addition & 1 deletion example/model/repository/generated/category/mock.go

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

2 changes: 1 addition & 1 deletion example/model/repository/generated/category/octopus.go

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

Loading

0 comments on commit 55b6f40

Please sign in to comment.