Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

chore: refactor controllers #461

Closed
wants to merge 3 commits into from
Closed

Conversation

im-adithya
Copy link
Member

Removes PermissionsService and adds ControllerService

@im-adithya im-adithya marked this pull request as draft June 18, 2024 10:48
dbSvc db.DBService
cfg config.Config
svc service.Service
permissionsSvc permissions.PermissionsService
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are adding this svc just to make use of the GetBudgetUsage function, moved GetStartOfBudget to utils folder and after that it is just a one line sql query which I moved to this file directly.

Copy link
Collaborator

@rolznz rolznz Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not like to duplicate that SQL query, this is the core logic to get the budget usage which is also used to see if an app has permission to make a payment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we might have to add the controllersSvc just for that function, should I do it?

@im-adithya im-adithya marked this pull request as ready for review June 18, 2024 13:08

assert.Equal(t, 2, len(responses))
for i := 0; i < len(responses); i++ {
assert.Equal(t, "123preimage", responses[i].Result.(payResponse).Preimage)
assert.Equal(t, "123preimage", responses[i].Result.(controllers.PayResponse).Preimage)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should move the tests to a new package, now we have to make models public just for the tests - this is why I put them side by side with the code. A lot of other projects do this too.

@@ -20,6 +19,10 @@ import (
)

func (svc *nip47Service) HandleEvent(ctx context.Context, sub *nostr.Subscription, event *nostr.Event, lnClient lnclient.LNClient) {
if !svc.controllersService.HasLNClient() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like a hack, can we pass the LNClient to the individual controller handler methods?

@@ -77,7 +77,7 @@ func (notifier *Nip47Notifier) notifySubscribers(ctx context.Context, notificati
notifier.db.Find(&apps)

for _, app := range apps {
hasPermission, _, _ := notifier.permissionsSvc.HasPermission(&app, permissions.NOTIFICATIONS_PERMISSION, 0)
hasPermission, _, _ := notifier.controllersSvc.HasPermission(&app, controllers.NOTIFICATIONS_PERMISSION, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is coupling notifications to controllers - these are two separate things and should not be related

@rolznz
Copy link
Collaborator

rolznz commented Jun 19, 2024

@im-adithya @bumi I feel like we unfortunately went a bit backwards on this PR.

I suggest we make the minimal change to create a common interface for the controller methods and then consider the other stuff as a follow-up. Does that sound ok?

@rolznz
Copy link
Collaborator

rolznz commented Jun 20, 2024

@im-adithya I talked with @bumi and we thought for now it's not worthwhile to make this change as it's opening up some other issues (as per the comments). For now we'd like to close this one and focus on some more other things (changing the authentication to not use a session cookie for example). I will create a new issue keep track of this though and link to this PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants