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

Allow visitors to create posts with tags #1221

Merged
merged 9 commits into from
Dec 17, 2024
Merged

Conversation

MercierMateo
Copy link
Contributor

Issue: #1211

Visitors can now create post with tags

Copy link
Contributor

@mattwoberts mattwoberts left a comment

Choose a reason for hiding this comment

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

Looking really good - apologies for the slow response in looking at this.

Comment on lines 31 to 43
func (input *CreateNewPost) OnPreExecute(ctx context.Context) error {
input.Tags = make([]*entity.Tag, len(input.TagSlugs))
for i, slug := range input.TagSlugs {
getTag := &query.GetTagBySlug{Slug: slug}
if err := bus.Dispatch(ctx, getTag); err != nil {
return err
}

input.Tags[i] = getTag.Result
}

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea to make this part of OnPreExecute. You'll just need to update that comment though.

BaseURL string `env:"BASE_URL"`
Locale string `env:"LOCALE,default=en"`
JWTSecret string `env:"JWT_SECRET,required"`
PostCreationWithTagsEnabled bool `env:"POST_CREATION_WITH_TAGS_ENABLED,default=false"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this looks good. I was contemplating if we should have a nested AppFeatures struct, and move this into there so that we could add other things in future, but I think we probably don't need to do that...

@mattwoberts
Copy link
Contributor

Looking good. What are you thinking for tests?

@MercierMateo
Copy link
Contributor Author

On the action part I'm not sure anything is needed, but tell me if I'm wrong.

On the handler part I think the needed tests are :

  • create a post with an inexistent tag -> should fail as bad request
  • create a post with a private tag as a standard user -> should fail as bad request
  • create a post with a public tag as a standard user -> should succeed
  • create a post with a public tag and a private tag as an administrator -> should succeed

As of now I think the fails are sent as a 404 error, so I will need to investigate on that before making these tests.

@mattwoberts
Copy link
Contributor

On the action part I'm not sure anything is needed, but tell me if I'm wrong.

On the handler part I think the needed tests are :

  • create a post with an inexistent tag -> should fail as bad request
  • create a post with a private tag as a standard user -> should fail as bad request
  • create a post with a public tag as a standard user -> should succeed
  • create a post with a public tag and a private tag as an administrator -> should succeed

As of now I think the fails are sent as a 404 error, so I will need to investigate on that before making these tests.

I suppose it depends - if you're handler tests poke the action then that's great, if they mock the action though then you might need some action tests to check the logic around building up the tags for example - see how you get on 👍

@MercierMateo
Copy link
Contributor Author

I created the tests, the actions are poked and function well.
Are these tests OK and enough for the backend part ?

Copy link
Contributor

@mattwoberts mattwoberts left a comment

Choose a reason for hiding this comment

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

Cheers, yeah this is coming on nicely, there might be more tests as it progresses but no issues here

app/handlers/apiv1/post_test.go Outdated Show resolved Hide resolved
Co-authored-by: Matt Roberts <[email protected]>
@MercierMateo
Copy link
Contributor Author

Thanks, i will look into the UI further but I struggle a bit more with this part.

I see there are errors on the ui test side, is it normal ? I don't think I made changes on the UI that could trigger these errors but I'm not sure.

@mattwoberts
Copy link
Contributor

Thanks, i will look into the UI further but I struggle a bit more with this part.

I see there are errors on the ui test side, is it normal ? I don't think I made changes on the UI that could trigger these errors but I'm not sure.

Yeah it looks like something has changed, I think a new playwright version is causing problems for our github actions (microsoft/playwright#30368) - it's nothing you've done. I'll take a look at this

@mattwoberts mattwoberts merged commit 513d517 into getfider:main Dec 17, 2024
4 of 8 checks passed
@mattwoberts
Copy link
Contributor

@MercierMateo Ugh, something went badly wrong in github - I tried to add a commit to your PR and ended up merging it into main - sorry about this. I'll sort it out

@mattwoberts
Copy link
Contributor

@MercierMateo Ok confession time. I was trying out the gh command line tool for the first time, I made a change to your pull request, and thought I'd pushed it as a commit onto your fork. Turns out I had messed up badly, and pushed it to main, which resulted in your PR being merged into main and closed. I'd asked chatGPT how to do this and just blindly copied the command without properly checking it. Never trust ChatGPT.

What an idiot I am.

Sorry.

I see 2 options here

  1. I revert all your commits from main to get it back to the state it was in before I did this. However I'm not sure what that would do for your pull request, and how we'd get the commits back into a pull request.

  2. We just accept what I've done, and call that "phase 1" of your work. The functionality is working, you can create posts with tags, it's just that there is no way to do that from the UI. So we can get main working by fixing the issues with the build, and then you can create another pull request, for "phase 2" that then is the work to add this to the UI.

What are your thoughts on this, and do you have any other suggestions?

Thanks!

Matt

@MercierMateo
Copy link
Contributor Author

Ok no problem, I'll add this to my list of reasons to avoid using ChatGPT

I think option 2 is fine. As I separated my work on the UI from my main branch, only the backend part was merged on your main. I can easily create a new PR and continue working on the UI part of the feature.

Obviously if there are any required fixes on the backend part we can go for option 1, but it doesn't seem like it.

@mattwoberts
Copy link
Contributor

Yes I think this is the best option - it's much easier all round I think, I've just got to sort out the issues causing the build to break on my side, and you can work on the UI.

@mattwoberts
Copy link
Contributor

mattwoberts commented Dec 18, 2024 via email

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

Successfully merging this pull request may close these issues.

2 participants