diff --git a/model/events.go b/model/events.go deleted file mode 100644 index 1f66000..0000000 --- a/model/events.go +++ /dev/null @@ -1,20 +0,0 @@ -package model - -type UsernameChanged struct { - AccountId int `json:"accountId"` - OldUsername string `json:"oldUsername"` - NewUsername string `json:"newUsername"` -} - -type SkinChanged struct { - AccountId int `json:"userId"` - Uuid string `json:"uuid"` - SkinId int `json:"skinId"` - OldSkinId int `json:"oldSkinId"` - Hash string `json:"hash"` - Is1_8 bool `json:"is1_8"` - IsSlim bool `json:"isSlim"` - Url string `json:"url"` - MojangTextures string `json:"mojangTextures"` - MojangSignature string `json:"mojangSignature"` -} diff --git a/worker/worder_test.go b/worker/worder_test.go index a9f0a5e..cc2f7b8 100644 --- a/worker/worder_test.go +++ b/worker/worder_test.go @@ -30,7 +30,7 @@ func TestServices_HandleChangeUsername(t *testing.T) { skinRepo.EXPECT().Save(resultModel) wd.EXPECT().IncCounter("worker.change_username", int64(1)) - assert.True(services.HandleChangeUsername(&model.UsernameChanged{ + assert.True(services.HandleChangeUsername(&UsernameChanged{ AccountId: 1, OldUsername: "mock_user", NewUsername: "new_username", @@ -42,7 +42,7 @@ func TestServices_HandleChangeUsername(t *testing.T) { wd.EXPECT().IncCounter("worker.change_username", int64(1)) wd.EXPECT().IncCounter("worker.change_username_empty_old_username", int64(1)) - assert.True(services.HandleChangeUsername(&model.UsernameChanged{ + assert.True(services.HandleChangeUsername(&UsernameChanged{ AccountId: 1, OldUsername: "", NewUsername: "new_mock", @@ -55,7 +55,7 @@ func TestServices_HandleChangeUsername(t *testing.T) { wd.EXPECT().IncCounter("worker.change_username_id_not_found", int64(1)) wd.EXPECT().Info("Cannot find user id :accountId. Trying to search.", gomock.Any()) - assert.True(services.HandleChangeUsername(&model.UsernameChanged{ + assert.True(services.HandleChangeUsername(&UsernameChanged{ AccountId: 1, OldUsername: "mock_user", NewUsername: "new_mock2", @@ -69,7 +69,7 @@ func TestServices_HandleChangeUsername(t *testing.T) { wd.EXPECT().Info("Cannot find user id :accountId. Trying to search.", gomock.Any()) wd.EXPECT().Error("Unknown error when requesting a skin from the repository: :err", gomock.Any()) - assert.True(services.HandleChangeUsername(&model.UsernameChanged{ + assert.True(services.HandleChangeUsername(&UsernameChanged{ AccountId: 1, OldUsername: "mock_user", NewUsername: "new_mock2", @@ -84,7 +84,7 @@ func TestServices_HandleSkinChanged(t *testing.T) { services, skinRepo, accountsAPI, wd := setupMocks(ctrl) - event := &model.SkinChanged{ + event := &SkinChanged{ AccountId: 1, Uuid: "cdb907ce-84f4-4c38-801d-1e287dca2623", SkinId: 2, diff --git a/worker/worker.go b/worker/worker.go index b2d3eef..4467553 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -19,6 +19,25 @@ type Services struct { Logger wd.Watchdog } +type UsernameChanged struct { + AccountId int `json:"accountId"` + OldUsername string `json:"oldUsername"` + NewUsername string `json:"newUsername"` +} + +type SkinChanged struct { + AccountId int `json:"userId"` + Uuid string `json:"uuid"` + SkinId int `json:"skinId"` + OldSkinId int `json:"oldSkinId"` + Hash string `json:"hash"` + Is1_8 bool `json:"is1_8"` + IsSlim bool `json:"isSlim"` + Url string `json:"url"` + MojangTextures string `json:"mojangTextures"` + MojangSignature string `json:"mojangSignature"` +} + const exchangeName string = "events" const queueName string = "skinsystem-accounts-events" @@ -44,11 +63,11 @@ func (service *Services) HandleDelivery(delivery *amqp.Delivery) { var result bool = true switch delivery.RoutingKey { case "accounts.username-changed": - var event *model.UsernameChanged + var event *UsernameChanged json.Unmarshal(delivery.Body, &event) result = service.HandleChangeUsername(event) case "accounts.skin-changed": - var event *model.SkinChanged + var event *SkinChanged json.Unmarshal(delivery.Body, &event) result = service.HandleSkinChanged(event) default: @@ -64,7 +83,7 @@ func (service *Services) HandleDelivery(delivery *amqp.Delivery) { } } -func (service *Services) HandleChangeUsername(event *model.UsernameChanged) bool { +func (service *Services) HandleChangeUsername(event *UsernameChanged) bool { service.Logger.IncCounter("worker.change_username", 1) if event.OldUsername == "" { service.Logger.IncCounter("worker.change_username_empty_old_username", 1) @@ -98,7 +117,7 @@ func (service *Services) HandleChangeUsername(event *model.UsernameChanged) bool } // TODO: возможно стоит добавить проверку на совпадение id аккаунтов -func (service *Services) HandleSkinChanged(event *model.SkinChanged) bool { +func (service *Services) HandleSkinChanged(event *SkinChanged) bool { service.Logger.IncCounter("worker.skin_changed", 1) var record *model.Skin record, err := service.SkinsRepo.FindByUserId(event.AccountId)