Skip to content

Commit

Permalink
fix: extra column in cluster (#121)
Browse files Browse the repository at this point in the history
Signed-off-by: closetool <[email protected]>
  • Loading branch information
kilosonc authored Apr 6, 2023
1 parent d18a6ae commit 2d9fc8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
16 changes: 8 additions & 8 deletions core/controller/cluster/controller_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,17 @@ func (c *controller) List(ctx context.Context, query *q.Query) ([]*ListClusterWi
perror.WithMessage(err, "failed to list user clusters")
}

if _, ok := query.Keywords[common.ClusterQueryWithFavorite]; ok {
err = c.addIsFavoriteForClusters(ctx, currentUserID, clusters)
if err != nil {
return nil, 0, err
}
}

responses, err := c.getFullResponsesWithRegion(ctx, clusters)
if err != nil {
return nil, 0, err
}

if _, ok := query.Keywords[common.ClusterQueryWithFavorite]; ok {
err = c.addIsFavoriteForClusters(ctx, currentUserID, responses)
if err != nil {
return nil, 0, err
}
}
return responses, count, nil
}

Expand Down Expand Up @@ -179,6 +178,7 @@ func (c *controller) getFullResponses(ctx context.Context,
}
responses = append(responses, &ListClusterWithFullResponse{
response,
nil,
fullName,
fullPath,
})
Expand Down Expand Up @@ -1112,7 +1112,7 @@ var (
)

func (c *controller) addIsFavoriteForClusters(ctx context.Context,
userID uint, clusters []*cmodels.ClusterWithRegion) error {
userID uint, clusters []*ListClusterWithFullResponse) error {
ids := make([]uint, 0, len(clusters))
for i := range clusters {
ids = append(ids, clusters[i].ID)
Expand Down
10 changes: 5 additions & 5 deletions core/controller/cluster/models_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@ func ofCluster(cluster *models.Cluster) *ListClusterResponse {
Git: &GitResponse{
GitURL: cluster.GitURL,
},
IsFavorite: cluster.IsFavorite,
CreatedAt: cluster.CreatedAt,
UpdatedAt: cluster.UpdatedAt,
CreatedAt: cluster.CreatedAt,
UpdatedAt: cluster.UpdatedAt,
}
}

Expand Down Expand Up @@ -288,8 +287,9 @@ type GetClusterByNameResponse struct {

type ListClusterWithFullResponse struct {
*ListClusterResponse
FullName string `json:"fullName,omitempty"`
FullPath string `json:"fullPath,omitempty"`
IsFavorite *bool `json:"isFavorite"`
FullName string `json:"fullName,omitempty"`
FullPath string `json:"fullPath,omitempty"`
}

type ListClusterWithExpiryResponse struct {
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/models/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type Cluster struct {
GitSubfolder string
GitRef string
GitRefType string
IsFavorite *bool
Template string
TemplateRelease string
Status string
Expand Down

0 comments on commit 2d9fc8d

Please sign in to comment.