Skip to content

Commit 871021e

Browse files
committed
feat: add labels to projects
1 parent 5a2fc99 commit 871021e

File tree

18 files changed

+341
-294
lines changed

18 files changed

+341
-294
lines changed

api/api/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"version": "v1",
55
"status": "active",
6-
"release_date": "2025-08-21T22:58:05.772340699+05:30",
6+
"release_date": "2025-09-02T19:27:36.312579047+05:30",
77
"end_of_life": "0001-01-01T00:00:00Z",
88
"changes": [
99
"Initial API version"

api/doc/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

api/go.mod

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require (
1818
github.com/moby/term v0.5.2
1919
github.com/opencontainers/image-spec v1.1.1
2020
github.com/pkg/sftp v1.13.5
21+
github.com/raghavyuva/caddygo v0.0.0-20250820132249-3db4bc273996
2122
github.com/shirou/gopsutil/v3 v3.24.5
2223
github.com/sirupsen/logrus v1.9.3
2324
github.com/slack-go/slack v0.16.0
@@ -85,9 +86,6 @@ require (
8586
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
8687
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
8788
github.com/go-jose/go-jose/v4 v4.1.2 // indirect
88-
github.com/go-kit/kit v0.13.0 // indirect
89-
github.com/go-kit/log v0.2.1 // indirect
90-
github.com/go-logfmt/logfmt v0.6.0 // indirect
9189
github.com/go-logr/logr v1.4.3 // indirect
9290
github.com/go-logr/stdr v1.2.2 // indirect
9391
github.com/go-ole/go-ole v1.2.6 // indirect
@@ -105,7 +103,7 @@ require (
105103
github.com/golang/snappy v1.0.0 // indirect
106104
github.com/google/cel-go v0.26.0 // indirect
107105
github.com/google/go-cmp v0.7.0 // indirect
108-
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
106+
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
109107
github.com/google/s2a-go v0.1.9 // indirect
110108
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
111109
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
@@ -116,14 +114,8 @@ require (
116114
github.com/inconshreveable/mousetrap v1.1.0 // indirect
117115
github.com/itchyny/gojq v0.12.5 // indirect
118116
github.com/itchyny/timefmt-go v0.1.3 // indirect
119-
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
120-
github.com/jackc/pgconn v1.14.3 // indirect
121-
github.com/jackc/pgio v1.0.0 // indirect
122117
github.com/jackc/pgpassfile v1.0.0 // indirect
123-
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
124118
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
125-
github.com/jackc/pgtype v1.14.4 // indirect
126-
github.com/jackc/pgx/v4 v4.18.3 // indirect
127119
github.com/jackc/puddle/v2 v2.2.2 // indirect
128120
github.com/jinzhu/inflection v1.0.0 // indirect
129121
github.com/josharian/intern v1.0.0 // indirect
@@ -158,7 +150,7 @@ require (
158150
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
159151
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
160152
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
161-
github.com/onsi/ginkgo/v2 v2.24.0 // indirect
153+
github.com/onsi/ginkgo/v2 v2.23.3 // indirect
162154
github.com/onsi/gomega v1.37.0 // indirect
163155
github.com/opencontainers/go-digest v1.0.0 // indirect
164156
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
@@ -173,8 +165,7 @@ require (
173165
github.com/prometheus/procfs v0.17.0 // indirect
174166
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
175167
github.com/quic-go/qpack v0.5.1 // indirect
176-
github.com/quic-go/quic-go v0.54.0 // indirect
177-
github.com/raghavyuva/caddygo v0.0.0-20250820132249-3db4bc273996 // indirect
168+
github.com/quic-go/quic-go v0.50.1 // indirect
178169
github.com/rs/xid v1.6.0 // indirect
179170
github.com/russross/blackfriday/v2 v2.1.0 // indirect
180171
github.com/shoenig/go-m1cpu v0.1.6 // indirect
@@ -211,11 +202,8 @@ require (
211202
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 // indirect
212203
go.opentelemetry.io/otel/metric v1.37.0 // indirect
213204
go.opentelemetry.io/otel/trace v1.37.0 // indirect
214-
go.step.sm/cli-utils v0.9.0 // indirect
215205
go.step.sm/crypto v0.69.0 // indirect
216-
go.step.sm/linkedca v0.22.2 // indirect
217206
go.uber.org/automaxprocs v1.6.0 // indirect
218-
go.uber.org/goleak v1.3.0 // indirect
219207
go.uber.org/mock v0.6.0 // indirect
220208
go.uber.org/multierr v1.11.0 // indirect
221209
go.uber.org/zap v1.27.0 // indirect

api/go.sum

Lines changed: 79 additions & 269 deletions
Large diffs are not rendered by default.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package controller
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/go-fuego/fuego"
7+
"github.com/google/uuid"
8+
"github.com/raghavyuva/nixopus-api/internal/features/logger"
9+
"github.com/raghavyuva/nixopus-api/internal/types"
10+
"github.com/raghavyuva/nixopus-api/internal/utils"
11+
)
12+
13+
type UpdateLabelsRequest struct {
14+
Labels []string `json:"labels" validate:"required"`
15+
}
16+
17+
func (c *DeployController) UpdateApplicationLabels(f fuego.ContextWithBody[UpdateLabelsRequest]) (*types.Response, error) {
18+
data, err := f.Body()
19+
if err != nil {
20+
c.logger.Log(logger.Error, "failed to read request body", err.Error())
21+
return nil, fuego.HTTPError{
22+
Err: err,
23+
Status: http.StatusBadRequest,
24+
}
25+
}
26+
27+
applicationID := f.QueryParam("id")
28+
if applicationID == "" {
29+
c.logger.Log(logger.Error, "application id is required", "")
30+
return nil, fuego.HTTPError{
31+
Err: nil,
32+
Status: http.StatusBadRequest,
33+
}
34+
}
35+
36+
user := utils.GetUser(f.Response(), f.Request())
37+
if user == nil {
38+
c.logger.Log(logger.Error, "user not found", "")
39+
return nil, fuego.HTTPError{
40+
Err: nil,
41+
Status: http.StatusUnauthorized,
42+
}
43+
}
44+
45+
organizationID := utils.GetOrganizationID(f.Request())
46+
if organizationID == uuid.Nil {
47+
c.logger.Log(logger.Error, "organization not found", "")
48+
return nil, fuego.HTTPError{
49+
Err: nil,
50+
Status: http.StatusUnauthorized,
51+
}
52+
}
53+
54+
appID, err := uuid.Parse(applicationID)
55+
if err != nil {
56+
c.logger.Log(logger.Error, "invalid application id", err.Error())
57+
return nil, fuego.HTTPError{
58+
Err: err,
59+
Status: http.StatusBadRequest,
60+
}
61+
}
62+
63+
err = c.service.UpdateApplicationLabels(appID, data.Labels, organizationID)
64+
if err != nil {
65+
c.logger.Log(logger.Error, err.Error(), "")
66+
return nil, fuego.HTTPError{
67+
Err: err,
68+
Status: http.StatusInternalServerError,
69+
}
70+
}
71+
72+
return &types.Response{
73+
Status: "success",
74+
Message: "Labels updated successfully",
75+
Data: data.Labels,
76+
}, nil
77+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package service
2+
3+
import (
4+
"github.com/google/uuid"
5+
)
6+
7+
func (s *DeployService) UpdateApplicationLabels(applicationID uuid.UUID, labels []string, organizationID uuid.UUID) error {
8+
return s.storage.UpdateApplicationLabels(applicationID, labels, organizationID)
9+
}

api/internal/features/deploy/storage/init.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/google/uuid"
99
"github.com/uptrace/bun"
10+
"github.com/uptrace/bun/dialect/pgdialect"
1011

1112
"github.com/raghavyuva/nixopus-api/internal/features/deploy/types"
1213
shared_types "github.com/raghavyuva/nixopus-api/internal/types"
@@ -41,6 +42,7 @@ type DeployRepository interface {
4142
GetDeploymentLogs(deploymentID string, page, pageSize int, level string, startTime, endTime time.Time, searchTerm string) ([]shared_types.ApplicationLogs, int, error)
4243
GetApplicationByRepositoryID(repositoryID uint64) (shared_types.Application, error)
4344
GetApplicationByRepositoryIDAndBranch(repositoryID uint64, branch string) ([]shared_types.Application, error)
45+
UpdateApplicationLabels(applicationID uuid.UUID, labels []string, organizationID uuid.UUID) error
4446
}
4547

4648
func (s *DeployStorage) IsNameAlreadyTaken(name string) (bool, error) {
@@ -422,3 +424,13 @@ func (s *DeployStorage) GetApplicationByRepositoryIDAndBranch(repositoryID uint6
422424

423425
return applications, nil
424426
}
427+
428+
func (s *DeployStorage) UpdateApplicationLabels(applicationID uuid.UUID, labels []string, organizationID uuid.UUID) error {
429+
_, err := s.DB.NewUpdate().
430+
Model((*shared_types.Application)(nil)).
431+
Set("labels = ?", pgdialect.Array(labels)).
432+
Set("updated_at = CURRENT_TIMESTAMP").
433+
Where("id = ? AND organization_id = ?", applicationID, organizationID).
434+
Exec(s.Ctx)
435+
return err
436+
}

api/internal/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ func (router *Router) DeployApplicationRoutes(f *fuego.Server, deployController
360360
fuego.Get(f, "/logs/{application_id}", deployController.GetLogs)
361361
fuego.Get(f, "/deployments/{deployment_id}/logs", deployController.GetDeploymentLogs)
362362
fuego.Get(f, "/deployments", deployController.GetApplicationDeployments)
363+
fuego.Put(f, "/labels", deployController.UpdateApplicationLabels)
363364
}
364365

365366
func (router *Router) FileManagerRoutes(f *fuego.Server, fileManagerController *file_manager.FileManagerController) {

api/internal/types/application.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Application struct {
3333
Logs []*ApplicationLogs `json:"logs,omitempty" bun:"rel:has-many,join:id=application_id"`
3434
Deployments []*ApplicationDeployment `json:"deployments,omitempty" bun:"rel:has-many,join:id=application_id"`
3535
Organization *Organization `json:"organization,omitempty" bun:"rel:belongs-to,join:organization_id=id"`
36+
Labels []string `json:"labels,omitempty" bun:"labels,array"`
3637
}
3738

3839
type ApplicationDeployment struct {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE applications DROP COLUMN IF EXISTS labels;
2+
DROP INDEX IF EXISTS idx_applications_labels;

0 commit comments

Comments
 (0)