added filter and add test with head common
This commit is contained in:
parent
7cc01031cd
commit
9d874f0fbf
@ -9,7 +9,7 @@ services:
|
||||
com.pena.upload: true
|
||||
com.pena.allowed_headers: content-type,authorization,response-type
|
||||
tty: true
|
||||
command: dlv --listen=:2345 --headless=true --log=true --log-output=debugger,debuglineerr,gdbwire,lldbout,rpc --accept-multiclient --api-version=2 exec ./heruvym
|
||||
#command: dlv --listen=:2345 --headless=true --log=true --log-output=debugger,debuglineerr,gdbwire,lldbout,rpc --accept-multiclient --api-version=2 exec ./heruvym
|
||||
environment:
|
||||
HTTP_PORT: 3000
|
||||
HTTP_HOST: 0.0.0.0
|
||||
|
2
go.sum
2
go.sum
@ -58,8 +58,6 @@ gitea.pena/PenaSide/common v0.0.0-20241126121130-cf56ae1e3fb2 h1:9U9JJBwWtQV4z/P
|
||||
gitea.pena/PenaSide/common v0.0.0-20241126121130-cf56ae1e3fb2/go.mod h1:l71j3W1yROhOSfjWZ6wcMuzjBR37gu2ZTcXsorEJoiw=
|
||||
gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9 h1:tBkXWNIt8icmkMMnq8MA421RWkUy4OZh5P7C3q8uCu4=
|
||||
gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9/go.mod h1:sanhSL8aEsfcq21P+eItYiAnKAre+B67nGJmDfk2cf0=
|
||||
gitea.pena/PenaSide/linters-golang v0.0.0-20241119212350-2759fa93724a h1:UySqMgaOKNsR42Y6GQXoM2wn/waYNc9cakMUSvbEEAg=
|
||||
gitea.pena/PenaSide/linters-golang v0.0.0-20241119212350-2759fa93724a/go.mod h1:gdd+vOT6up9STkEbxa2qESLIMZFjCmRbkcheFQCVgZU=
|
||||
gitea.pena/PenaSide/linters-golang v0.0.0-20241127222405-b4bda04c14b4 h1:PxhHDNYggJjvZ7FmDsLmaadE9g2Ld+vjTn7clrGrnB4=
|
||||
gitea.pena/PenaSide/linters-golang v0.0.0-20241127222405-b4bda04c14b4/go.mod h1:gdd+vOT6up9STkEbxa2qESLIMZFjCmRbkcheFQCVgZU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
|
@ -312,6 +312,7 @@ func (t *TicketController) GetMessages(ctx *fiber.Ctx) error {
|
||||
result, err := t.dal.GetMessagesPage(ctx.Context(),
|
||||
request.Search,
|
||||
request.TicketID,
|
||||
role,
|
||||
request.Amount,
|
||||
request.Page,
|
||||
)
|
||||
@ -319,16 +320,6 @@ func (t *TicketController) GetMessages(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusNoContent).JSON(fiber.Map{"error": "No Content"})
|
||||
}
|
||||
|
||||
if role != "admin" {
|
||||
var filtered []model.Message
|
||||
for _, message := range result {
|
||||
if !message.System { // исключаем системные сообщения
|
||||
filtered = append(filtered, message)
|
||||
}
|
||||
}
|
||||
result = filtered
|
||||
}
|
||||
|
||||
return ctx.Status(fiber.StatusOK).JSON(result)
|
||||
}
|
||||
|
||||
|
@ -680,7 +680,7 @@ func (d *DAL) GetTicketPage(
|
||||
}
|
||||
|
||||
func (d *DAL) GetMessagesPage(ctx context.Context,
|
||||
search, ticketID string,
|
||||
search, ticketID, role string,
|
||||
limit, offset int64) ([]model.Message, error) {
|
||||
|
||||
var (
|
||||
@ -703,6 +703,10 @@ func (d *DAL) GetMessagesPage(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
if role != "admin" {
|
||||
query["System"] = false
|
||||
}
|
||||
|
||||
sort := bson.D{{Key: "CreatedAt", Value: -1}}
|
||||
|
||||
cur, err := d.colMsg.Find(ctx, query, options.Find().SetLimit(limit).SetSkip(limit*offset).SetSort(sort))
|
||||
|
45
test/dal_test.go
Normal file
45
test/dal_test.go
Normal file
@ -0,0 +1,45 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
m "gitea.pena/PenaSide/common/mongo"
|
||||
"gitea.pena/PenaSide/heruvym/internal/repository/mongo"
|
||||
"gitea.pena/PenaSide/hlog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/zap"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGetMessagesPage(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
mdb, err := m.Connect(ctx, &m.ConnectDeps{
|
||||
Configuration: &m.Configuration{
|
||||
URL: "mongodb://test:test@localhost:27020/",
|
||||
DatabaseName: "test",
|
||||
},
|
||||
Timeout: 10 * time.Second,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
mDal, err := mongo.New(ctx, mongo.DepsDAL{
|
||||
MongoDatabase: mdb,
|
||||
HLogger: hlog.New(zap.NewExample()),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 1; i <= 10; i++ {
|
||||
iStr := strconv.Itoa(i)
|
||||
flag := false
|
||||
if i%2 == 0 {
|
||||
flag = true
|
||||
}
|
||||
_, err = mDal.PutMessage(ctx, iStr, iStr, iStr, iStr, []string{}, flag)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
result, err := mDal.GetMessagesPage(ctx, "", "2", "", 10, 0)
|
||||
assert.NoError(t, err)
|
||||
fmt.Println(result)
|
||||
}
|
Loading…
Reference in New Issue
Block a user