Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Admire Token pt1 #1160

Merged
merged 15 commits into from
Aug 23, 2023
Merged

Enable Admire Token pt1 #1160

merged 15 commits into from
Aug 23, 2023

Conversation

Rohan-cp
Copy link
Collaborator

@Rohan-cp Rohan-cp commented Aug 17, 2023

Testing:
wrote the testAdmireToken test

@Rohan-cp Rohan-cp marked this pull request as ready for review August 17, 2023 22:46
Copy link
Collaborator

@jarrel-b jarrel-b left a comment

Choose a reason for hiding this comment

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

Looking awesome so far 💪

db/migrations/core/00119-admire-nft.up.sql Outdated Show resolved Hide resolved
service/persist/admire.go Outdated Show resolved Hide resolved
@@ -0,0 +1 @@
ALTER TABLE admires ADD COLUMN IF NOT EXISTS token_id varchar(255) references token(id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I realized we'll also want to add a constraint on this table so that you can't admire the same token twice. You can add a line to this migration that goes something like this:

create unique index admire_actor_id_token_id_idx on admires(actor_id, token_id) where deleted = false;

@@ -52,6 +52,28 @@ func (a *AdmireRepository) CreateAdmire(ctx context.Context, feedEventID, postID

}

func (a *AdmireRepository) CreateAdmireToken(ctx context.Context, tokenID, actorID persist.DBID) (persist.DBID, error) {
var tokenString sql.NullString
Copy link
Collaborator

Choose a reason for hiding this comment

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

fyi: there's a helper in util/helpers.go named ToNullString which could be useful here!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm, not sure how I would use it here because I would still need to check if tokenID != "" before doing tokenID.String() (to then pass to ToNullString) right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yea, my mistake!

func (api InteractionAPI) AdmireToken(ctx context.Context, tokenID persist.DBID) (persist.DBID, error) {
// Validate
if err := validate.ValidateFields(api.validator, validate.ValidationMap{
"tokenID": validate.WithTag(tokenID, "required"),
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 it would be great to check that not only the tokenID is provided, but also if a token with that tokenID exists

admire: Admire @goField(forceResolver: true)
}

union AdmireTokenPayloadOrError = AdmireTokenPayload | ErrInvalidInput | ErrNotAuthorized
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we add the check for if the token exists, can we add ErrTokenNotFound as a possible returned type here?

@Rohan-cp Rohan-cp requested a review from jarrel-b August 21, 2023 18:22
userF := newUserFixture(t)
c := authedHandlerClient(t, userF.ID)
alice := newUserWithTokensFixture(t)
admireToken(t, ctx, c, alice.TokenIDs[0])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure how to test further if admireToken is working because it doesn't return anything

Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems fine to me! One thing we can test is to return the tokenID from admireToken and verify that it's the token we expect.

We can also test admiring the same token twice to verify that you can only admire a token once per user.

Copy link
Collaborator

@jarrel-b jarrel-b left a comment

Choose a reason for hiding this comment

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

Looks awesome!

userF := newUserFixture(t)
c := authedHandlerClient(t, userF.ID)
alice := newUserWithTokensFixture(t)
admireToken(t, ctx, c, alice.TokenIDs[0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems fine to me! One thing we can test is to return the tokenID from admireToken and verify that it's the token we expect.

We can also test admiring the same token twice to verify that you can only admire a token once per user.

return "", err
}

/*
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 we can remove this comment since the table constraint we added should enforce this now.

@@ -52,6 +52,28 @@ func (a *AdmireRepository) CreateAdmire(ctx context.Context, feedEventID, postID

}

func (a *AdmireRepository) CreateAdmireToken(ctx context.Context, tokenID, actorID persist.DBID) (persist.DBID, error) {
var tokenString sql.NullString
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yea, my mistake!

@Rohan-cp Rohan-cp merged commit f4b2d16 into main Aug 23, 2023
7 checks passed
@Rohan-cp Rohan-cp deleted the enable-admire-nft-p1 branch August 23, 2023 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants