Sort messages by creation time
This commit is contained in:
parent
78d47c4035
commit
4ac7e29909
4 changed files with 37 additions and 6 deletions
|
|
@ -3,6 +3,7 @@ package api
|
|||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
|
|
@ -72,6 +73,16 @@ func listCommunication(ctx context.Context, r *http.Request, org *models.Organiz
|
|||
Type: "water",
|
||||
}
|
||||
}
|
||||
_by_created := func(a, b communication) int {
|
||||
if a.Created == b.Created {
|
||||
return 0
|
||||
} else if a.Created.Before(b.Created) {
|
||||
return 1
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
slices.SortFunc(comms, _by_created)
|
||||
return &contentListCommunication{
|
||||
Communications: comms,
|
||||
}, nil
|
||||
|
|
|
|||
|
|
@ -19,12 +19,6 @@ import (
|
|||
|
||||
var decoder = schema.NewDecoder()
|
||||
|
||||
type queryParams struct {
|
||||
Limit *int `schema:"limit"`
|
||||
Sort *string `schema:"sort"`
|
||||
Type *string `schema:"type"`
|
||||
}
|
||||
|
||||
type handlerFunctionGet[T any] func(context.Context, *http.Request, *models.Organization, *models.User, queryParams) (*T, *nhttp.ErrorWithStatus)
|
||||
type wrappedHandler func(http.ResponseWriter, *http.Request)
|
||||
type contentAuthenticated[T any] struct {
|
||||
|
|
|
|||
25
api/query_params.go
Normal file
25
api/query_params.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package api
|
||||
|
||||
type queryParams struct {
|
||||
Limit *int `schema:"limit"`
|
||||
Sort *string `schema:"sort"`
|
||||
Type *string `schema:"type"`
|
||||
}
|
||||
|
||||
func (qp queryParams) SortOrDefault(default_name string, ascending bool) (string, bool) {
|
||||
if qp.Sort == nil {
|
||||
return default_name, ascending
|
||||
}
|
||||
s := *qp.Sort
|
||||
if s == "" {
|
||||
return default_name, ascending
|
||||
}
|
||||
a := true
|
||||
if s[0] == '-' {
|
||||
a = false
|
||||
}
|
||||
if s[0] == '+' || s[0] == '-' {
|
||||
s = s[1:]
|
||||
}
|
||||
return s, a
|
||||
}
|
||||
|
|
@ -130,6 +130,7 @@
|
|||
try {
|
||||
// Build query parameters from filters
|
||||
const params = new URLSearchParams();
|
||||
params.append("sort", "-created");
|
||||
if (this.typeFilter) params.append("type", this.typeFilter);
|
||||
|
||||
const response = await fetch(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue