Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
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
93 changes: 90 additions & 3 deletions apps/comms/internal/app/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/comms/internal/app/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ type Mutation {
comms_updateSubscriptionConfig(config: SubscriptionIn!, id: ID!): Subscription

comms_markNotificationAsRead(id: ID!): Notification @isLoggedInAndVerified @hasAccount
comms_markAllNotificationAsRead: Boolean! @isLoggedInAndVerified @hasAccount
}
18 changes: 17 additions & 1 deletion apps/comms/internal/app/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/comms/internal/domain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type Domain interface {
ListNotifications(ctx CommsContext, pagination repos.CursorPagination) (*repos.PaginatedRecord[*types.Notification], error)
MarkNotificationAsRead(ctx CommsContext, id repos.ID) (*types.Notification, error)
MarkAllNotificationsAsRead(ctx CommsContext) error

GetNotificationConfig(ctx CommsContext) (*entities.NotificationConf, error)
UpdateNotificationConfig(ctx CommsContext, config entities.NotificationConf) (*entities.NotificationConf, error)
Expand Down
28 changes: 28 additions & 0 deletions apps/comms/internal/domain/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package domain
import (
"context"

field_constants "github.com/kloudlite/api/apps/comms/internal/domain/entities/field-constants"
"github.com/kloudlite/api/apps/comms/types"
iamT "github.com/kloudlite/api/apps/iam/types"
"github.com/kloudlite/api/common/fields"
Expand Down Expand Up @@ -73,6 +74,33 @@ func (d *Impl) MarkNotificationAsRead(ctx CommsContext, id repos.ID) (*types.Not
return n, nil
}

func (d *Impl) MarkAllNotificationsAsRead(ctx CommsContext) error {
co, err := d.iamClient.Can(ctx, &iam.CanIn{
UserId: string(ctx.UserId),
ResourceRefs: []string{iamT.NewResourceRef(ctx.AccountName, iamT.ResourceAccount, ctx.AccountName)},
Action: string(iamT.UpdateAccount),
})

if err != nil {
return err
}

if !co.Status {
return errors.NewE(errors.Newf("user %s does not have permission to update account %s", ctx.UserId, ctx.AccountName))
}

if err := d.notificationRepo.UpdateMany(ctx, repos.Filter{
fields.AccountName: ctx.AccountName,
}, map[string]any{
field_constants.NotificationRead: true,
}); err != nil {
return err
}

return nil

}

func (d *Impl) Notify(ctx context.Context, notification *types.Notification) error {
_, err := d.notificationRepo.Create(ctx, notification)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions apps/comms/internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Env struct {

CommsDBUri string `env:"MONGO_URI" required:"true"`
CommsDBName string `env:"MONGO_DB_NAME" required:"true"`

Port uint16 `env:"HTTP_PORT" required:"true"`
}

func LoadEnv() (*Env, error) {
Expand Down
11 changes: 11 additions & 0 deletions apps/comms/internal/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ var Module = fx.Module(
return httpServer.NewServer(httpServer.ServerArgs{Logger: logger, CorsAllowOrigins: &corsOrigins, IsDev: e.IsDev})
}),

fx.Invoke(func(lf fx.Lifecycle, server httpServer.Server, ev *env.Env) {
lf.Append(fx.Hook{
OnStart: func(context.Context) error {
return server.Listen(fmt.Sprintf(":%d", ev.Port))
},
OnStop: func(context.Context) error {
return server.Close()
},
})
}),

fx.Provide(
func(ev *env.Env, jc *nats.JetstreamClient) (kv.Repo[*common.AuthSession], error) {
cxt := context.TODO()
Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/supergraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ subgraphs:
schema:
file: ./schemas/console-api.schema
comms-api:
routing_url: http://comms-api:3000/query
routing_url: http://comms:3000/query
schema:
file: ./schemas/comms-api.schema
infra-api:
Expand Down