feat: [CDE-332]: updated swagger for gitspaces and sort order for gitspaces activation (#2913)

* feat: [CDE-332]: added a way to filter gitspaces
* feat: [CDE-332]: updated swagger for gitspaces and sort order for gitspaces activation
* feat: [CDE-332]: updated swagger for gitspaces
This commit is contained in:
Ansuman Satapathy 2024-11-04 04:40:28 +00:00 committed by Harness
parent 4244cbaa5a
commit 2fc779c32a
6 changed files with 50 additions and 6 deletions

View File

@ -51,8 +51,9 @@ type getGitspaceRequest struct {
} }
type gitspacesListRequest struct { type gitspacesListRequest struct {
Sort string `query:"sort" enum:"id,created,updated"` Sort string `query:"sort" enum:"created,last_used,last_activated"`
Order string `query:"order" enum:"asc,desc"` Order string `query:"order" enum:"asc,desc"`
GitspaceOwner string `query:"gitspace_owner" enum:"self,all"`
// include pagination request // include pagination request
paginationRequest paginationRequest

View File

@ -23,6 +23,7 @@ import (
const ( const (
PathParamGitspaceIdentifier = "gitspace_identifier" PathParamGitspaceIdentifier = "gitspace_identifier"
QueryParamGitspaceOwner = "gitspace_owner"
) )
func GetGitspaceRefFromPath(r *http.Request) (string, error) { func GetGitspaceRefFromPath(r *http.Request) (string, error) {
@ -36,11 +37,19 @@ func ParseGitspaceSort(r *http.Request) enum.GitspaceSort {
) )
} }
// ParseGitspaceOwner extracts the gitspace owner type from the url.
func ParseGitspaceOwner(r *http.Request) enum.GitspaceOwner {
return enum.ParseGitspaceOwner(
r.URL.Query().Get(QueryParamGitspaceOwner),
)
}
// ParseGitspaceFilter extracts the gitspace filter from the url. // ParseGitspaceFilter extracts the gitspace filter from the url.
func ParseGitspaceFilter(r *http.Request) types.GitspaceFilter { func ParseGitspaceFilter(r *http.Request) types.GitspaceFilter {
return types.GitspaceFilter{ return types.GitspaceFilter{
QueryFilter: ParseListQueryFilterFromRequest(r), QueryFilter: ParseListQueryFilterFromRequest(r),
Sort: ParseGitspaceSort(r), Sort: ParseGitspaceSort(r),
Owner: ParseGitspaceOwner(r),
Order: ParseOrder(r), Order: ParseOrder(r),
} }
} }

View File

@ -313,7 +313,7 @@ func addGitspaceFilter(stmt squirrel.SelectBuilder, filter *types.GitspaceFilter
stmt = stmt.Where(squirrel.Eq{"gconf_is_deleted": false}) stmt = stmt.Where(squirrel.Eq{"gconf_is_deleted": false})
} }
if filter.UserIdentifier != "" { if filter.Owner == enum.GitspaceOwnerSelf && filter.UserIdentifier != "" {
stmt = stmt.Where(squirrel.Eq{"gconf_user_uid": filter.UserIdentifier}) stmt = stmt.Where(squirrel.Eq{"gconf_user_uid": filter.UserIdentifier})
} }
@ -334,8 +334,10 @@ func addOrderBy(stmt squirrel.SelectBuilder, filter *types.GitspaceFilter) squir
return stmt.OrderBy("gits_last_used " + filter.Order.String()) return stmt.OrderBy("gits_last_used " + filter.Order.String())
case enum.GitspaceSortCreated: case enum.GitspaceSortCreated:
return stmt.OrderBy("gconf_created " + filter.Order.String()) return stmt.OrderBy("gconf_created " + filter.Order.String())
case enum.GitspaceSortLastActivated:
return stmt.OrderBy("gits_active_time_started " + filter.Order.String())
default: default:
return stmt.OrderBy("gits_last_used " + filter.Order.String()) return stmt.OrderBy("gits_active_time_started " + filter.Order.String())
} }
} }

View File

@ -63,6 +63,7 @@ const (
descending = "descending" descending = "descending"
value = "value" value = "value"
lastUsed = "last_used" lastUsed = "last_used"
lastActivated = "last_activated"
) )
func toInterfaceSlice[T interface{}](vals []T) []interface{} { func toInterfaceSlice[T interface{}](vals []T) []interface{} {

View File

@ -25,6 +25,7 @@ type GitspaceSort string
const ( const (
GitspaceSortLastUsed GitspaceSort = lastUsed GitspaceSortLastUsed GitspaceSort = lastUsed
GitspaceSortCreated GitspaceSort = created GitspaceSortCreated GitspaceSort = created
GitspaceSortLastActivated GitspaceSort = lastActivated
) )
var GitspaceSorts = sortEnum([]GitspaceSort{ var GitspaceSorts = sortEnum([]GitspaceSort{
@ -42,7 +43,36 @@ func ParseGitspaceSort(s string) GitspaceSort {
return GitspaceSortLastUsed return GitspaceSortLastUsed
case created, createdAt: case created, createdAt:
return GitspaceSortCreated return GitspaceSortCreated
case lastActivated:
return GitspaceSortLastActivated
default: default:
return GitspaceSortLastUsed return GitspaceSortLastUsed
} }
} }
type GitspaceOwner string
var GitspaceOwners = sortEnum([]GitspaceOwner{
GitspaceOwnerSelf,
GitspaceOwnerAll,
})
const (
GitspaceOwnerSelf GitspaceOwner = "self"
GitspaceOwnerAll GitspaceOwner = "all"
)
func (GitspaceOwner) Enum() []interface{} { return toInterfaceSlice(GitspaceOwners) }
// ParseGitspaceSort parses the gitspace sort attribute string
// and returns the equivalent enumeration.
func ParseGitspaceOwner(s string) GitspaceOwner {
switch strings.ToLower(s) {
case string(GitspaceOwnerSelf):
return GitspaceOwnerSelf
case string(GitspaceOwnerAll):
return GitspaceOwnerAll
default:
return GitspaceOwnerSelf
}
}

View File

@ -84,6 +84,7 @@ type GitspaceFilter struct {
QueryFilter ListQueryFilter QueryFilter ListQueryFilter
Sort enum.GitspaceSort `json:"sort"` Sort enum.GitspaceSort `json:"sort"`
Order enum.Order `json:"order"` Order enum.Order `json:"order"`
Owner enum.GitspaceOwner
IncludeDeleted bool IncludeDeleted bool
IncludeMarkedForDeletion bool IncludeMarkedForDeletion bool
GitspaceInstanceFilter GitspaceInstanceFilter