33 lines
655 B
Go
33 lines
655 B
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
"github.com/mainflux/mainflux/readers"
|
|
)
|
|
|
|
func listMessagesEndpoint(svc readers.MessageRepository) endpoint.Endpoint {
|
|
return func(_ context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(listMessagesReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
page, err := svc.ReadAll(req.chanID, req.pageMeta)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return pageRes{
|
|
PageMetadata: page.PageMetadata,
|
|
Total: page.Total,
|
|
Messages: page.Messages,
|
|
}, nil
|
|
}
|
|
}
|