Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion api/handler/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"net/http"
"strconv"

"github.com/String-xyz/go-lib/v2/common"
httperror "github.com/String-xyz/go-lib/v2/httperror"
Expand Down Expand Up @@ -101,7 +102,28 @@ func (a contract) GetAll(c echo.Context) error {

platformId := c.QueryParam("platformId")

m, err := a.service.GetAll(c.Request().Context(), platformId, organizationId)
var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "contract get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "contract get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

m, err := a.service.GetAll(c.Request().Context(), platformId, organizationId, limit, offset)
if err != nil && errors.Cause(err) != serror.NOT_FOUND {
return DefaultErrorHandler(c, err, "contract: get all")
}
Expand Down
24 changes: 23 additions & 1 deletion api/handler/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"net/http"
"strconv"
"strings"

"github.com/String-xyz/go-lib/v2/common"
Expand Down Expand Up @@ -143,8 +144,29 @@ func (i invite) List(c echo.Context) error {
return httperror.Internal500(c, "missing or invalid organizationId")
}

var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "invite get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "invite get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

status := c.QueryParam("status")
m, err := i.service.List(c.Request().Context(), status, organizationId)
m, err := i.service.List(c.Request().Context(), status, organizationId, limit, offset)
if err != nil && errors.Cause(err) != serror.NOT_FOUND {
return DefaultErrorHandler(c, err, "invite: list")
}
Expand Down
24 changes: 23 additions & 1 deletion api/handler/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"net/http"
"strconv"
"strings"

"github.com/String-xyz/go-lib/v2/common"
Expand Down Expand Up @@ -47,7 +48,28 @@ func (a member) GetAll(c echo.Context) error {
return httperror.Internal500(c, "missing or invalid organizationId")
}

m, err := a.service.GetAll(c.Request().Context(), organizationId)
var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "member get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "member get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

m, err := a.service.GetAll(c.Request().Context(), organizationId, limit, offset)
if err != nil && errors.Cause(err) != serror.NOT_FOUND {
common.LogStringError(c, err, "member: get all")
return httperror.Internal500(c)
Expand Down
25 changes: 24 additions & 1 deletion api/handler/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package handler

import (
"net/http"
"strconv"

"github.com/String-xyz/dashboard-api/pkg/service"
"github.com/String-xyz/go-lib/v2/common"
httperror "github.com/String-xyz/go-lib/v2/httperror"
"github.com/labstack/echo/v4"
)

Expand All @@ -30,7 +32,28 @@ func NewNetwork(service service.Network) Network {
// @Failure 500 {object} error
// @Router /networks [get]
func (a network) GetAll(c echo.Context) error {
m, err := a.service.GetAll(c.Request().Context())
var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "network get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "network get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

m, err := a.service.GetAll(c.Request().Context(), limit, offset)
if err != nil {
common.LogStringError(c, err, "network: get all")
return DefaultErrorHandler(c, err, "network: get all")
Expand Down
25 changes: 23 additions & 2 deletions api/handler/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"net/http"
"strconv"

"github.com/String-xyz/dashboard-api/pkg/model"
"github.com/String-xyz/dashboard-api/pkg/service"
Expand Down Expand Up @@ -111,10 +112,30 @@ func (p platform) GetAll(c echo.Context) error {
if !ok {
return httperror.Internal500(c, "missing or invalid organizationId")
}
var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "platform get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "platform get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

m, err := p.service.GetAll(c.Request().Context(), callerId, organizationId)
m, err := p.service.GetAll(c.Request().Context(), callerId, organizationId, limit, offset)
if err != nil && errors.Cause(err) != serror.NOT_FOUND {
return DefaultErrorHandler(c, err, "apikey: get all")
return DefaultErrorHandler(c, err, "platform: get all")
}

return c.JSON(http.StatusOK, m)
Expand Down
9 changes: 6 additions & 3 deletions pkg/repository/member_invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type MemberInvite interface {
GetById(ctx context.Context, id string) (invite MemberInviteInfo, err error)
List(ctx context.Context, limit int, offset int) (invites []model.MemberInvite, err error)
Update(ctx context.Context, id string, updates any) error
GetByOrganization(ctx context.Context, organizationId string) (invites []MemberInviteInfo, err error)
GetByOrganization(ctx context.Context, organizationId string, limit int, offset int) (invites []MemberInviteInfo, err error)
GetByEmail(ctx context.Context, email string) (invite MemberInviteInfo, err error)
SoftDelete(ctx context.Context, id string) error
}
Expand Down Expand Up @@ -89,8 +89,11 @@ func (i memberInvite[T]) Create(ctx context.Context, request model.MemberInvite)
return invite, nil
}

func (i memberInvite[T]) GetByOrganization(ctx context.Context, organizationId string) (invites []MemberInviteInfo, err error) {
err = i.Store.Select(&invites, getBaseQuery()+`WHERE member_invite.organization_id = $1 AND member_invite.deleted_at IS NULL`, organizationId)
func (i memberInvite[T]) GetByOrganization(ctx context.Context, organizationId string, limit int, offset int) (invites []MemberInviteInfo, err error) {
if limit == 0 {
limit = 100
}
err = i.Store.Select(&invites, getBaseQuery()+`WHERE member_invite.organization_id = $1 AND member_invite.deleted_at IS NULL LIMIT $2 OFFSET $3`, organizationId, limit, offset)

if err != nil && err == sql.ErrNoRows {
return []MemberInviteInfo{}, common.StringError(serror.NOT_FOUND)
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

type Contract interface {
Create(ctx context.Context, create model.RequestContractCreate, callerId string, organizationId string) (model.Contract, error)
GetAll(ctx context.Context, platformId string, organizationId string) ([]model.Contract, error)
GetAll(ctx context.Context, platformId string, organizationId string, limit int, offset int) ([]model.Contract, error)
Get(ctx context.Context, contractId string, organizationId string) (model.Contract, error)
Deactivate(ctx context.Context, contractId string, callerId string, organizationId string) (model.Contract, error)
Reactivate(ctx context.Context, contractId string, callerId string, organizationId string) (model.Contract, error)
Expand Down Expand Up @@ -45,17 +45,17 @@ func (c contract) Create(ctx context.Context, create model.RequestContractCreate
return contract, nil
}

func (c contract) GetAll(ctx context.Context, platformId string, organizationId string) (contracts []model.Contract, err error) {
func (c contract) GetAll(ctx context.Context, platformId string, organizationId string, limit int, offset int) (contracts []model.Contract, err error) {
_, finish := Span(ctx, "service.contract.GetAll", SpanTag{"organizationId": organizationId})
defer finish()

if platformId != "" {
contracts, err = c.repos.Contract.ListByPlatform(ctx, platformId, 0, 0)
contracts, err = c.repos.Contract.ListByPlatform(ctx, platformId, limit, offset)
if err != nil {
return contracts, common.StringError(err)
}
} else {
contracts, err = c.repos.Contract.ListByOrganization(ctx, organizationId, 0, 0)
contracts, err = c.repos.Contract.ListByOrganization(ctx, organizationId, limit, offset)
if err != nil {
return contracts, common.StringError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type Invite interface {
Send(ctx context.Context, request model.RequestInviteSend, callerId *string, organizationId string) (repository.MemberInviteInfo, error)
Accept(ctx context.Context, inviteId string, requestBody model.RequestInviteAcceptance) (model.OrganizationMember, JWT, error)
List(ctx context.Context, status string, organizationId string) ([]repository.MemberInviteInfo, error)
List(ctx context.Context, status string, organizationId string, limit int, offset int) ([]repository.MemberInviteInfo, error)
Resend(ctx context.Context, inviteId string, callerId string, organizationId string) (repository.MemberInviteInfo, error)
Update(ctx context.Context, request model.RequestInviteUpdate, inviteId string, callerId string) (repository.MemberInviteInfo, error)
Revoke(ctx context.Context, inviteId string, callerId string) error
Expand Down Expand Up @@ -176,11 +176,11 @@ func (i invite) Accept(ctx context.Context, inviteId string, requestBody model.R
return member, jwt, nil
}

func (i invite) List(ctx context.Context, status string, organizationId string) ([]repository.MemberInviteInfo, error) {
func (i invite) List(ctx context.Context, status string, organizationId string, limit int, offset int) ([]repository.MemberInviteInfo, error) {
_, finish := Span(ctx, "service.invite.List", SpanTag{"organizationId": organizationId})
defer finish()

result, err := i.repos.MemberInvite.GetByOrganization(ctx, organizationId)
result, err := i.repos.MemberInvite.GetByOrganization(ctx, organizationId, limit, offset)
if err != nil {
return result, common.StringError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type MemberCreateResponse struct {
}

type Member interface {
GetAll(ctx context.Context, organizationId string) ([]repository.OrganizationMemberWithRole, error)
GetAll(ctx context.Context, organizationId string, limit int, offset int) ([]repository.OrganizationMemberWithRole, error)
Get(ctx context.Context, callerId string, organizationId string, memberId string) (repository.OrganizationMemberWithRole, error)
UpdateMember(ctx context.Context, request model.RequestMemberUpdateOther, callerId string, memberId string) (repository.OrganizationMemberWithRole, error)
UpdateSelf(ctx context.Context, request model.RequestMemberUpdateSelf, callerId string) (repository.OrganizationMemberWithRole, error)
Expand All @@ -40,11 +40,11 @@ func NewMember(repos repository.Repositories) Member {
return &member{repos}
}

func (m member) GetAll(ctx context.Context, organizationId string) ([]repository.OrganizationMemberWithRole, error) {
func (m member) GetAll(ctx context.Context, organizationId string, limit int, offset int) ([]repository.OrganizationMemberWithRole, error) {
_, finish := Span(ctx, "service.member.GetAll", SpanTag{"organizationId": organizationId})
defer finish()

result, err := m.repos.OrganizationMember.List(ctx, organizationId, 0, 0)
result, err := m.repos.OrganizationMember.List(ctx, organizationId, limit, offset)
if err != nil {
return result, common.StringError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type Network interface {
GetAll(ctx context.Context) ([]model.NetworkData, error)
GetAll(ctx context.Context, limit int, offset int) ([]model.NetworkData, error)
}

type network struct {
Expand All @@ -20,11 +20,11 @@ func NewNetwork(repos repository.Repositories) Network {
return &network{repos}
}

func (n network) GetAll(ctx context.Context) ([]model.NetworkData, error) {
func (n network) GetAll(ctx context.Context, limit int, offset int) ([]model.NetworkData, error) {
_, finish := Span(ctx, "service.network.GetAll")
defer finish()

networks, err := n.repos.Network.List(ctx, 0, 0)
networks, err := n.repos.Network.List(ctx, limit, offset)
if err != nil {
return nil, common.StringError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type Platform interface {
Create(ctx context.Context, request model.RequestPlatformCreate, organizationId string) (platform model.Platform, err error)
Get(ctx context.Context, platformId string, organizationId string) (platform model.Platform, err error)
GetAll(ctx context.Context, callerId string, organizationId string) (platforms []model.Platform, err error)
GetAll(ctx context.Context, callerId string, organizationId string, limit int, offset int) (platforms []model.Platform, err error)
Update(ctx context.Context, request model.RequestPlatformUpdate, platformId string, callerId string, organizationId string) (platform model.Platform, err error)
Deactivate(ctx context.Context, platformId string, callerId string, organizationId string) (model.Platform, error)
Reactivate(ctx context.Context, platformId string, callerId string, organizationId string) (model.Platform, error)
Expand Down Expand Up @@ -57,11 +57,11 @@ func (p platform) Get(ctx context.Context, platformId string, organizationId str
return platform, nil
}

func (p platform) GetAll(ctx context.Context, callerId string, organizationId string) (platforms []model.Platform, err error) {
func (p platform) GetAll(ctx context.Context, callerId string, organizationId string, limit int, offset int) (platforms []model.Platform, err error) {
_, finish := Span(ctx, "service.platform.GetAll", SpanTag{"organizationId": organizationId})
defer finish()

platforms, err = p.repos.Platform.List(ctx, organizationId, 0, 0)
platforms, err = p.repos.Platform.List(ctx, organizationId, limit, offset)
if err != nil {
return platforms, common.StringError(err)
}
Expand Down