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

Refactored and simplified file structure and added data models for in… #8

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

pfredCL
Copy link

@pfredCL pfredCL commented Mar 18, 2024

…tervals, heart rate, and full results (retrieved from a GET call on C2's api rather than from their webhook payload)

@pfredCL pfredCL closed this Mar 18, 2024
@pfredCL pfredCL reopened this Mar 18, 2024
@MoralCode MoralCode self-requested a review March 19, 2024 15:54
@@ -0,0 +1,11 @@
part of 'index.dart';

class C2DetailedResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this class exists as a separate thing from C2WebhookResult? it seems to borrow similar comments from that class and serve the same intended function.

Copy link
Contributor

@MoralCode MoralCode Jun 14, 2024

Choose a reason for hiding this comment

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

the webhook almost gives you all the data you need (except the number of intervals) and making a separate REST call (which may not be fully propagated across C2's network - fun fact) to the c2logbook API to retrieve this extra data is where this comes from

part of 'index.dart';

@freezed
class C2FullResults with _$C2FullResults {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this class provide something separately from the C2Results class? or is it largely just a copy to make changes less destructive/easy to undo/allow more rapid iteration?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this have something to do with differences between the result data from the webhook vs a GET call?

factory C2FullResults({
@JsonKey(name: 'id') @Default(0) int id,
@JsonKey(name: 'user_id') @Default(0) int userId,
@JsonKey(name: 'date') @TimestampConverter() required DateTime date,
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice in all the refactoring the field name for this got renamed from endDate (which i find to be more specific description of its purpose). I assume it was changed back to try and get the json keys to work automatically, but figured id check if theres a reason this cant be changed back now that the @JsonKey annotation is back.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is ok to change but make crewlab a migration guide for name changes

@JsonKey(name: 'rest_time') @DecimalIntConverter.tenths() double? restTime,
@JsonKey(name: 'stroke_rate') int? strokeRate,
@JsonKey(name: 'heart_rate') @Default(null) C2HeartRate? heartRate,
@JsonKey(name: 'workout') @Default(null) C2Workout? workout,
Copy link
Contributor

Choose a reason for hiding this comment

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

was there an issue with the json keys for fields that dont have multiword names (like workout) where they werent getting recognized without making it explicit? or were these just added back for code cleanliness/formatting consistency?

I noticed when testing that if the key and the field name are the same, the @JsonKey isnt necessary to make explicit

Copy link
Contributor

Choose a reason for hiding this comment

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

some fields werent making it in. adding them all fixed it

Copy link
Contributor

Choose a reason for hiding this comment

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

is this config something thats built into dart to help automate the generation of code during the build? or is explicitly running the code gen still necessary?

@Default('') String email,
@Default('') String country,
@JsonKey(name: 'profile_image') String? profileImage,
Copy link
Contributor

Choose a reason for hiding this comment

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

did i get a bunch of the JSON keys in this file wrong? or were you able to find a way to automate them based on the field name in dart?

@MoralCode
Copy link
Contributor

MoralCode commented Mar 25, 2024

Seems like the CI is failing because of some dart formatting (i dont have access to the branch that this PR is from in order to commit the fix to that).

definitely agree with the overall approach of this PR (especially love how all the generated code is combined into one file).

Havent had a chance to run the unit tests yet.

Are there any new testcases that may help ensure that future changes dont break crewLAB's usecase?
Any additional (or changes to) documentation you think are needed for this PR?

Maybe some extra action items:

  • checking the field names of the public types so that breaking changes (like the endDate thing i commented on) dont slip though in future or break other code using this lib
  • actually parsing the full data sample that you sent me
  • documentation updates?

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