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

Redirect to campaign detail upon entry creation #537

Merged
merged 9 commits into from
Apr 3, 2022

Conversation

JasonGadoury
Copy link
Contributor

@JasonGadoury JasonGadoury commented Apr 1, 2022

Description

Closes #500

Once a campaign entry or dm entry is successfully created, the user is now redirected to the campaign detail page instead of the character detail or dm entry index pages respectively.

To test:

  1. Seed database
  2. Create a dm entry for a campaign the signed in user is dm for
    (if they are not dm for any campaign, create a campaign and assign them dm)
  3. Observe that you have been redirected to campaign detail page
  4. Create an entry for a campaign the signed in user is participating in with a character
  5. Observe that you have been redirected to campaign detail page

@codeclimate
Copy link

codeclimate bot commented Apr 1, 2022

Code Climate has analyzed commit 90b737e and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (90% is the threshold).

This pull request will bring the total coverage in the repository to 91.6%.

View more on Code Climate.

@JasonGadoury JasonGadoury self-assigned this Apr 1, 2022
@JasonGadoury
Copy link
Contributor Author

Looks like I have a code smell for having too many redirects in the store function. Each redirect is chosen based on the type of entry being created (invalid gm entry, regular or dm entry with campaign, regular or dm w/o campaign...). The two options are to either ignore it or sacrifice one of the redirects. Thoughts? @m-triassi

@m-triassi
Copy link
Contributor

@JasonGadoury there's a third option, instead of returning, assign the route name string to a variable that changes based on the conditions, and then pass that variable to the route() function
something like:

if ($x == "Condition A") {
    $redirect = 'campaign.show';
    $extraData = [...];
} elseif ($x == "Condition B") {
    $redirect = 'character.index'; 
    $extraData = null;
}

return redirect()->route($redirect, $extraData);

@JasonGadoury JasonGadoury marked this pull request as ready for review April 3, 2022 07:04
@sonarcloud
Copy link

sonarcloud bot commented Apr 3, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@m-triassi m-triassi left a comment

Choose a reason for hiding this comment

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

This works, some things to consider for refactor, but I'll handle that at a later date.

Comment on lines +103 to +113
if (isset($campaign)) {
$redirectRoute = 'campaign.show';
$parameter = $campaign;
} elseif (!isset($campaign)) {
if ($entryData['type'] === Entry::TYPE_DM) {
$redirectRoute = 'dm-entry.index';
$parameter = null;
} else {
$redirectRoute = 'character.show';
$parameter = $entry->character_id;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Typically i'd avoid nesting control flow logic more than 1 layer deep if possible. Since we don't really have the luxary of time, ill just say this is a refactor target and move on

@m-triassi m-triassi merged commit ff2bb0d into main Apr 3, 2022
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.

Incorrect redirects after creating entry or DM entry
2 participants