Compare commits

...

2 Commits

Author SHA1 Message Date
96361eec85 return, only for getList 2025-02-24 16:47:52 +03:00
ad005e4bfd replace some fields from privileges response 2025-02-24 16:38:39 +03:00
7 changed files with 54 additions and 23 deletions

@ -1,14 +0,0 @@
# Server Options
HTTP_HOST=localhost
HTTP_PORT=8080
# Auth service
AUTH_SERVICE_HOST=http://localhost
AUTH_SERVICE_PORT=8081
# Database Options
DB_HOST=127.0.0.1
DB_PORT=27017
DB_USERNAME=test
DB_PASSWORD=test
DB_NAME=admin

@ -2,12 +2,12 @@ package privilege_internal
import (
"errors"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
our_errors "gitea.pena/PenaSide/tariffs/internal/errors"
"gitea.pena/PenaSide/tariffs/internal/models"
"gitea.pena/PenaSide/tariffs/internal/repository/privilege"
"gitea.pena/PenaSide/tariffs/internal/tools"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
)
type Deps struct {

@ -5,9 +5,8 @@ import (
"time"
)
type Privilege struct {
ID primitive.ObjectID `bson:"_id" json:"_id"`
ID primitive.ObjectID `bson:"_id" json:"_id"`
Name string `bson:"name" json:"name"`
PrivilegeID string `bson:"privilegeId" json:"privilegeId"`
ServiceKey string `bson:"serviceKey" json:"serviceKey"`
@ -22,3 +21,13 @@ type Privilege struct {
DeletedAt *time.Time `bson:"deletedAt" json:"deletedAt"`
}
type PrivilegeResponse struct {
Name string `bson:"name" json:"name"`
PrivilegeID string `bson:"privilegeId" json:"privilegeId"`
ServiceKey string `bson:"serviceKey" json:"serviceKey"`
Description string `bson:"description" json:"description"`
Type string `bson:"type" json:"type"`
Value string `bson:"value" json:"value"`
Price float64 `bson:"price" json:"price"`
Amount float64 `bson:"amount" json:"amount"`
}

@ -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"`
}

@ -19,3 +19,18 @@ type Tariff struct {
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"`
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 []PrivilegeResponse `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"`
}

@ -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

@ -0,0 +1,21 @@
package tools
import "gitea.pena/PenaSide/tariffs/internal/models"
func FormattingPrivilege(current []models.Privilege) []models.PrivilegeResponse {
result := make([]models.PrivilegeResponse, len(current))
for i, cur := range current {
result[i] = models.PrivilegeResponse{
Name: cur.Name,
PrivilegeID: cur.PrivilegeID,
ServiceKey: cur.ServiceKey,
Description: cur.Description,
Type: cur.Type,
Value: cur.Value,
Price: cur.Price,
Amount: cur.Amount,
}
}
return result
}