diff --git a/internal/controller/privilege_internal/controller.go b/internal/controller/privilege_internal/controller.go index 8dfdff7..27be00f 100644 --- a/internal/controller/privilege_internal/controller.go +++ b/internal/controller/privilege_internal/controller.go @@ -38,7 +38,8 @@ func (p *PrivilegeInternal) Get(c *fiber.Ctx) error { return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()}) } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege(privileges)) + + return c.Status(fiber.StatusOK).JSON(privileges) } // хаб нода registerPrivilege @@ -62,7 +63,7 @@ func (p *PrivilegeInternal) Create(c *fiber.Ctx) error { } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege([]models.Privilege{result})[0]) + return c.Status(fiber.StatusOK).JSON(result) } // хаб нода replacePrivilege @@ -86,7 +87,7 @@ func (p *PrivilegeInternal) Update(c *fiber.Ctx) error { } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege([]models.Privilege{result})[0]) + return c.Status(fiber.StatusOK).JSON(result) } // хаб нода removePrivilege @@ -113,7 +114,7 @@ func (p *PrivilegeInternal) Delete(c *fiber.Ctx) error { } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege([]models.Privilege{result})[0]) + return c.Status(fiber.StatusOK).JSON(result) } // хаб нода getPrivilege @@ -133,7 +134,7 @@ func (p *PrivilegeInternal) GetByID(c *fiber.Ctx) error { } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege([]models.Privilege{result})[0]) + return c.Status(fiber.StatusOK).JSON(result) } // хаб нода getServicePrivileges @@ -152,7 +153,7 @@ func (p *PrivilegeInternal) GetByService(c *fiber.Ctx) error { } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege(result)) + return c.Status(fiber.StatusOK).JSON(result) } // хаб нода registerPrivileges @@ -182,7 +183,7 @@ func (p *PrivilegeInternal) PostMany(c *fiber.Ctx) error { } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege(result)) + return c.Status(fiber.StatusOK).JSON(result) } // хаб нода replacePrivileges @@ -212,7 +213,7 @@ func (p *PrivilegeInternal) UpdateMany(c *fiber.Ctx) error { } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege(result)) + return c.Status(fiber.StatusOK).JSON(result) } // хаб нода restorePrivilege @@ -239,5 +240,5 @@ func (p *PrivilegeInternal) Restore(c *fiber.Ctx) error { } } - return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege([]models.Privilege{result})[0]) + return c.Status(fiber.StatusOK).JSON(result) } diff --git a/internal/models/reqBodies.go b/internal/models/reqBodies.go index 7ea4f1e..59c728c 100644 --- a/internal/models/reqBodies.go +++ b/internal/models/reqBodies.go @@ -15,6 +15,6 @@ type ManyCreateUpdate struct { } type TariffPagination struct { - TotalPages int `json:"totalPages"` - Tariffs []Tariff `json:"tariffs"` + TotalPages int `json:"totalPages"` + Tariffs []TariffGetList `json:"tariffs"` } diff --git a/internal/models/tariff.go b/internal/models/tariff.go index cc9f2a6..4622b51 100644 --- a/internal/models/tariff.go +++ b/internal/models/tariff.go @@ -6,6 +6,21 @@ import ( ) type Tariff struct { + ID primitive.ObjectID `json:"_id" bson:"_id"` + Name string `json:"name" bson:"name"` + UserID string `json:"userID" bson:"userID"` + Description string `json:"description" bson:"description"` + Price int `json:"price" bson:"price"` + Order int `json:"order" bson:"order"` + IsCustom bool `json:"isCustom" bson:"isCustom"` + Privileges []Privilege `json:"privileges" bson:"privileges"` + IsDeleted bool `json:"isDeleted" bson:"isDeleted"` + CreatedAt time.Time `json:"createdAt" bson:"createdAt"` + UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` + DeletedAt time.Time `json:"deletedAt" bson:"deletedAt"` +} + +type TariffGetList struct { ID primitive.ObjectID `json:"_id" bson:"_id"` Name string `json:"name" bson:"name"` UserID string `json:"userID" bson:"userID"` diff --git a/internal/repository/tariff/tariff.go b/internal/repository/tariff/tariff.go index 1dff678..7ff088e 100644 --- a/internal/repository/tariff/tariff.go +++ b/internal/repository/tariff/tariff.go @@ -2,13 +2,13 @@ package tariff import ( "context" + "gitea.pena/PenaSide/tariffs/internal/errors" + "gitea.pena/PenaSide/tariffs/internal/models" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.uber.org/zap" - "gitea.pena/PenaSide/tariffs/internal/errors" - "gitea.pena/PenaSide/tariffs/internal/models" "math" "time" ) @@ -95,7 +95,7 @@ func (t *Tariff) GetList(ctx context.Context, page, limit int64, userID string) } defer cursor.Close(ctx) - var tariffs []models.Tariff + var tariffs []models.TariffGetList if err = cursor.All(ctx, &tariffs); err != nil { t.logger.Error("failed decode tariffs", zap.Error(err)) return result, err diff --git a/internal/tools/convertToMap.go b/internal/tools/convertToMap.go index 61a5736..09275ae 100644 --- a/internal/tools/convertToMap.go +++ b/internal/tools/convertToMap.go @@ -2,24 +2,15 @@ package tools import "gitea.pena/PenaSide/tariffs/internal/models" -func ConvertPrivilegesToMap(privileges []models.Privilege) map[string][]models.PrivilegeResponse { - resultMap := make(map[string][]models.PrivilegeResponse) +func ConvertPrivilegesToMap(privileges []models.Privilege) map[string][]models.Privilege { + resultMap := make(map[string][]models.Privilege) for _, privilege := range privileges { svcKey := privilege.ServiceKey if _, ok := resultMap[svcKey]; !ok { - resultMap[svcKey] = []models.PrivilegeResponse{} + resultMap[svcKey] = []models.Privilege{} } - resultMap[svcKey] = append(resultMap[svcKey], models.PrivilegeResponse{ - Name: privilege.Name, - PrivilegeID: privilege.PrivilegeID, - ServiceKey: privilege.ServiceKey, - Description: privilege.Description, - Type: privilege.Type, - Value: privilege.Value, - Price: privilege.Price, - Amount: privilege.Amount, - }) + resultMap[svcKey] = append(resultMap[svcKey], privilege) } return resultMap