Compare commits
2 Commits
dev
...
privileges
Author | SHA1 | Date | |
---|---|---|---|
96361eec85 | |||
ad005e4bfd |
14
.env.example
14
.env.example
@ -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,7 +5,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
type Privilege struct {
|
||||
ID primitive.ObjectID `bson:"_id" json:"_id"`
|
||||
Name string `bson:"name" json:"name"`
|
||||
@ -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"`
|
||||
}
|
||||
|
@ -16,5 +16,5 @@ type ManyCreateUpdate struct {
|
||||
|
||||
type TariffPagination struct {
|
||||
TotalPages int `json:"totalPages"`
|
||||
Tariffs []Tariff `json:"tariffs"`
|
||||
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
|
||||
|
21
internal/tools/formatting.go
Normal file
21
internal/tools/formatting.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user