hackclub / hackclub/elapsed

Code Quality: Always project API types to full MVVM types

Open
#30 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
7
Forks
1
PR merge metrics
No merged PRs in 30d

Description

In the `[app]/Models` folder, we define various strongly-typed models (for MVVM), e.g. `User`.
Many API requests return a non-strongly typed, inconsistent type that's supposed to represent other types.
For example, in `developer/getAllOwnedApps`, a non-strongly-typed `object[]` array is returned, with various fields, such as `createdBy`.
The `createdBy` object instance is supposed to represent a user object, but the API doesn't return the full type enclosing all of its data.

We already correctly project fully-qualified types into custom types, for example, we can easily convert `user/myself` into our strongly-typed `User` class because it provides information for all fields, but we can't so easily for the `createdBy` object from `developer/getAllOwnedApps` because it only includes the `displayName`, `handle` and `id`.
However, what we *can* do is use another API request to convert that object into the fully-qualified `User`.

For example (pseudocode):
```cs
public User(string id)
{
this = [ApiClient(User)].Query(id);
}
```

Therefore, it only requires using this custom constructor of `User` or an extension method to build a fully-qualified `User` object from less information.
So therefore in the `DeveloperApp` class, we can store a full `User` object and implementations should just reroute using this constructor.

> super fun mvvvm yippee!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.