return, only for getList
This commit is contained in:
parent
ad005e4bfd
commit
96361eec85
@ -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.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c.Status(fiber.StatusOK).JSON(tools.FormattingPrivilege(privileges))
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(privileges)
|
||||||
}
|
}
|
||||||
|
|
||||||
// хаб нода registerPrivilege
|
// хаб нода 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
|
// хаб нода 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
|
// хаб нода 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
|
// хаб нода 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
|
// хаб нода 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
|
// хаб нода 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
|
// хаб нода 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
|
// хаб нода 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)
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,6 @@ type ManyCreateUpdate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TariffPagination struct {
|
type TariffPagination struct {
|
||||||
TotalPages int `json:"totalPages"`
|
TotalPages int `json:"totalPages"`
|
||||||
Tariffs []Tariff `json:"tariffs"`
|
Tariffs []TariffGetList `json:"tariffs"`
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Tariff struct {
|
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"`
|
ID primitive.ObjectID `json:"_id" bson:"_id"`
|
||||||
Name string `json:"name" bson:"name"`
|
Name string `json:"name" bson:"name"`
|
||||||
UserID string `json:"userID" bson:"userID"`
|
UserID string `json:"userID" bson:"userID"`
|
||||||
|
@ -2,13 +2,13 @@ package tariff
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"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"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"gitea.pena/PenaSide/tariffs/internal/errors"
|
|
||||||
"gitea.pena/PenaSide/tariffs/internal/models"
|
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -95,7 +95,7 @@ func (t *Tariff) GetList(ctx context.Context, page, limit int64, userID string)
|
|||||||
}
|
}
|
||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
var tariffs []models.Tariff
|
var tariffs []models.TariffGetList
|
||||||
if err = cursor.All(ctx, &tariffs); err != nil {
|
if err = cursor.All(ctx, &tariffs); err != nil {
|
||||||
t.logger.Error("failed decode tariffs", zap.Error(err))
|
t.logger.Error("failed decode tariffs", zap.Error(err))
|
||||||
return result, err
|
return result, err
|
||||||
|
@ -2,24 +2,15 @@ package tools
|
|||||||
|
|
||||||
import "gitea.pena/PenaSide/tariffs/internal/models"
|
import "gitea.pena/PenaSide/tariffs/internal/models"
|
||||||
|
|
||||||
func ConvertPrivilegesToMap(privileges []models.Privilege) map[string][]models.PrivilegeResponse {
|
func ConvertPrivilegesToMap(privileges []models.Privilege) map[string][]models.Privilege {
|
||||||
resultMap := make(map[string][]models.PrivilegeResponse)
|
resultMap := make(map[string][]models.Privilege)
|
||||||
|
|
||||||
for _, privilege := range privileges {
|
for _, privilege := range privileges {
|
||||||
svcKey := privilege.ServiceKey
|
svcKey := privilege.ServiceKey
|
||||||
if _, ok := resultMap[svcKey]; !ok {
|
if _, ok := resultMap[svcKey]; !ok {
|
||||||
resultMap[svcKey] = []models.PrivilegeResponse{}
|
resultMap[svcKey] = []models.Privilege{}
|
||||||
}
|
}
|
||||||
resultMap[svcKey] = append(resultMap[svcKey], models.PrivilegeResponse{
|
resultMap[svcKey] = append(resultMap[svcKey], privilege)
|
||||||
Name: privilege.Name,
|
|
||||||
PrivilegeID: privilege.PrivilegeID,
|
|
||||||
ServiceKey: privilege.ServiceKey,
|
|
||||||
Description: privilege.Description,
|
|
||||||
Type: privilege.Type,
|
|
||||||
Value: privilege.Value,
|
|
||||||
Price: privilege.Price,
|
|
||||||
Amount: privilege.Amount,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultMap
|
return resultMap
|
||||||
|
Loading…
Reference in New Issue
Block a user