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

Extract service logic from controllers #450

Merged
merged 19 commits into from
Nov 14, 2024

Conversation

ThanGerlek
Copy link
Contributor

Converts the "endpoint" Controllers (i.e. excluding TrafficController and WebSocketController) into the beginnings of a Handler layer, and moves most of the logic into Service classes.

This should improve testability and compliance with SRP, Demeter, and DRY. It also isolates and simplifies JavaSpark code, which will make it much easier to migrate to Javalin.

@ThanGerlek ThanGerlek marked this pull request as ready for review October 28, 2024 02:54
Copy link
Contributor

@frozenfrank frozenfrank left a comment

Choose a reason for hiding this comment

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

It looks pretty good to me. I'm really happy that we are properly dividing the app logic and separating concerns according to the good principles were learning from our professors. Thank you @jerodw!

There are some improvements I would still make as discussed in the comments. Additional code duplication to pull out, and a few organizational choices.

Copy link
Collaborator

@19mdavenport 19mdavenport left a comment

Choose a reason for hiding this comment

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

From an in-person conversation it sounded like you were planning on doing this but I would just like to go officially on the record as requesting the GradingObserver implementation become its own class

@ThanGerlek
Copy link
Contributor Author

ThanGerlek commented Nov 7, 2024

How's this?

(I tried but couldn't think of a better name 🤷🏻‍♂️)

Copy link
Contributor

@webecke webecke left a comment

Choose a reason for hiding this comment

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

It looks really good, seems to not have broken anything, and is something we probably should have done a long time ago. Good work!

@webecke
Copy link
Contributor

webecke commented Nov 12, 2024

Just checking in, @frozenfrank @ThanGerlek do we have an update on this PR?

@frozenfrank
Copy link
Contributor

Just checking in, @frozenfrank @ThanGerlek do we have an update on this PR?

@webecke Thanks for checking in. I just realized I still have a pending review comments I'll review it again now.

This is a novel move in this repository, and it is not
applied to other packages as well. In this case, there
are a large number of controller classes intermingled
with multiple exception classes which warrants additional
organizational layers. Other packages that have *both*
fewer classes and fewer exceptions are fine to remain.
Copy link
Contributor

@frozenfrank frozenfrank left a comment

Choose a reason for hiding this comment

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

I have a few adjustments that I've developed locally and will push the branch.

My main comment is an important comment, but I feel it will be appropriate to address in a separate issue. See #476.

private static final Logger LOGGER = LoggerFactory.getLogger(CasService.class);
public static final String BYU_CAS_URL = "https://cas.byu.edu/cas";

public static User callback(String ticket) throws InternalServerException, BadRequestException, DataAccessException, CanvasException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Building the entire system on static methods is contrary to the best practices we teach the students in CS 240. Yes, storing an instance and passing it through each level adds lines of code at each level, but the marginally small change provides big benefits in terms of testing and overall software design. (Do I need to describe more why this is a valuable pattern?)

I'm not sure whether or not the DAO classes are used statically as well. If they're not, we should update those as well. However, if we're introducing (or at least emphasizing) the service layer classes now, then we should start off strong by following good practices.

Copy link
Contributor

Choose a reason for hiding this comment

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

This issue is now represented by #476.

Copy link
Contributor

@frozenfrank frozenfrank left a comment

Choose a reason for hiding this comment

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

Let's move forward with this for now, and address the rest later.

Thank you for making these significant improvements to the AutoGrader!

@frozenfrank frozenfrank added the clean-up Something in the code is a mess and needs refactoring label Nov 12, 2024
@frozenfrank
Copy link
Contributor

@ThanGerlek Are you planning on merging this PR?

On this team, we like to let the original author of the PR press the "Merge" button. Personally, I feel like the tradition leads to hiccups and additional delays, but it is how it is right now. (You may need to re-update the branch since other commits may have been added to main since you last updated it.)

@ThanGerlek
Copy link
Contributor Author

I was, but I'm complete swamped, so I haven't had time to review your changes or the merge from main that still needs to happen. If you want to ping Dallin or Michael to review your changes, they or you can merge with main and then merge in the PR

@ThanGerlek
Copy link
Contributor Author

ThanGerlek commented Nov 12, 2024

Honestly, if you're confident that your changes are small enough, I'd be willing to trust your judgement if you want to go ahead and merge without review. Just be careful obviously

@frozenfrank
Copy link
Contributor

I was, but I'm complete swamped, so I haven't had time to review your changes or the merge from main that still needs to happen. If you want to ping Dallin or Michael to review your changes, they or you can merge with main and then merge in the PR

There's no rush, I just saw that you had updated the branch, and I expected the branch to be merged at the same time. Just review it when you have a moment 👌

@ThanGerlek ThanGerlek merged commit 51ea85f into main Nov 14, 2024
2 checks passed
@ThanGerlek ThanGerlek deleted the extract-service-logic-from-controllers branch November 14, 2024 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean-up Something in the code is a mess and needs refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants