mirror of
https://github.com/elyby/chrly.git
synced 2024-12-23 13:40:11 +05:30
Модели amqp событий перенесены непосредственно в компонент amqp worker
This commit is contained in:
parent
76a3f3ad26
commit
9cb6502f9c
@ -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"`
|
||||
}
|
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user