package visamasteractions import ( "encoding/json" "strings" "time" "online-back/internal/shared" ) // Action names, as the "Ammallar" table's Amalyň ady column shows them. const ( NameCreate = "create" NameUpdate = "update" NameDelete = "delete" ) // Action statuses: finished once the change is committed, failed (with // Exception) when it was attempted but rolled back. const ( StatusFinished = "finished" StatusFailed = "failed" ) // orderTypeSber is the type value of Sber orders, matched case-insensitively // like visamaster and visamasterpay do. const orderTypeSber = "sber" var nameLabels = map[string]shared.LocalizedText{ NameCreate: {Tm: "Goşmak", Ru: "Создание", En: "Create"}, NameUpdate: {Tm: "Üýtgetmek", Ru: "Изменение", En: "Update"}, NameDelete: {Tm: "Pozmak", Ru: "Удаление", En: "Delete"}, } var ( sberTargetLabel = shared.LocalizedText{Tm: "Sber töleg (talyplar üçin)", Ru: "Оплата Sber (для студентов)", En: "Sber payment (for students)"} visaMasterTargetLabel = shared.LocalizedText{Tm: "Visa/Master töleg (talyplar üçin)", Ru: "Оплата Visa/Master (для студентов)", En: "Visa/Master payment (for students)"} ) // NameLabel is the display name of an action name; unknown names fall // back to the name itself. func NameLabel(name string) shared.LocalizedText { if label, ok := nameLabels[name]; ok { return label } return shared.LocalizedText{Tm: name, Ru: name, En: name} } // TargetLabel is the display name of the order an action was done to, // by the order's (current) type. func TargetLabel(orderType *string) shared.LocalizedText { if orderType != nil && strings.EqualFold(strings.TrimSpace(*orderType), orderTypeSber) { return sberTargetLabel } return visaMasterTargetLabel } // OrderActionTargetDTO is the order an action was done to - Amalyň // nyşany (targedi), e.g. "TB6312-14083 (Sber töleg (talyplar üçin))". type OrderActionTargetDTO struct { Id int64 `json:"id"` UniqueId *string `json:"uniqueId"` Type *string `json:"type"` Label shared.LocalizedText `json:"label"` } // OrderActionDTO is one row of an order's "Ammallar" table. CreatedById is // null (and CreatedByName empty) when no user started the action - the // GBÜS callback finalizing a payment. type OrderActionDTO struct { Id int64 `json:"id"` OrderId int64 `json:"orderId"` Name string `json:"name"` NameLabel shared.LocalizedText `json:"nameLabel"` Status string `json:"status"` Target OrderActionTargetDTO `json:"target"` CreatedById *int64 `json:"createdById"` CreatedByName string `json:"createdByName"` CreatedAt time.Time `json:"createdAt"` } // OrderActionDetailDTO is a single action with what it changed - the list // leaves these out so pages stay small. Original holds the changed // columns' values before the action and Changes their values after (or, // for a failed action, the values it attempted); either is null when // there's nothing on that side (Original for a create, Changes for a // delete). type OrderActionDetailDTO struct { OrderActionDTO Original json.RawMessage `json:"original" swaggertype:"object"` Changes json.RawMessage `json:"changes" swaggertype:"object"` Exception *string `json:"exception"` } type ListOrderActionDTO struct { Count int64 `json:"count"` Actions []OrderActionDTO `json:"actions"` } // CreateOrderActionDTO is one action to record, written by the // repositories that change orders (cards/visamaster, payment/visamasterpay) // - never through the API. type CreateOrderActionDTO struct { OrderId int64 Name string Status string Original map[string]interface{} Changes map[string]interface{} Exception *string CreatedBy *int64 } type ListFilter struct { OrderId int64 Page int Limit int }