frc-frecon / frecon

An API for building scouting apps for FRC competitions
MIT License
3 stars 0 forks source link

Make FReCon::Controller model support bulk creation. #53

Closed rye closed 9 years ago

rye commented 9 years ago

This is horribly messy, and I think there should be some better way to do it. However, it works in isolated cases, when given a JSON array of teams, for example.

rye commented 9 years ago

This seems rather clean, actually, now that I've checked the custom bulk creation methods.

I'd really like @Sammidysam's evaluation of this.

rye commented 9 years ago

FReCon::Controller.team_number_to_team_id and FReCon::Controller.match_number_and_competition_to_match_id don't seem to work with this recursive stuff yet.

Sammidysam commented 9 years ago

Ah, yes, I understand them not working. You should make them not do anything if the thing is an array.

rye commented 9 years ago

Should I just make those return a recursive map of the data (call the method recursively on each item in post_data if it is an Array?).

rye commented 9 years ago

Oh wait, no, your suggestion is better.

Sammidysam commented 9 years ago

Yeah, it'll be called on each through the create recursion.

rye commented 9 years ago

Will RecordsController.create call itself recursively? Is that how super methods work?

Sammidysam commented 9 years ago

super in RecordsController.create calls Controller.create.

Sammidysam commented 9 years ago

Anyway, comments from my "evaluation": I like it. This is about how I would have done it. :+1:

rye commented 9 years ago

All right. Anything glaring that I should change?

Sammidysam commented 9 years ago

Just add return post_data unless post_data.is_a?(Hash) to the beginning of the two controller methods that convert post_data, then :shipit:

Sammidysam commented 9 years ago

Oh, didn't see your comment. Yes.

Sammidysam commented 9 years ago

You can just look for an error in the results array.

rye commented 9 years ago

An error would be anything other than 201?

Sammidysam commented 9 years ago

I believe so. But you have to account for return values often being an array, and then checking the first element in the subarray.

rye commented 9 years ago

Yes, I know. I'll just map each of the arrays to their first elements, then compare the count of the selection of all non-201 codes to 0. If any non-201 codes exist, then I'll make it return 400.

rye commented 9 years ago

All right. I'll F.I.:shipit: now.