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

fixup request classes and use id/path as a object on method being called #66

Closed
jetersen opened this issue Sep 20, 2019 · 1 comment · Fixed by #68
Closed

fixup request classes and use id/path as a object on method being called #66

jetersen opened this issue Sep 20, 2019 · 1 comment · Fixed by #68

Comments

@jetersen
Copy link
Collaborator

jetersen commented Sep 20, 2019

I'd like to fix up the request classes to move id / path out of the request object and onto the parameter as type object id

So this pattern

public async Task<Project> UpdateAsync(UpdateProjectRequest request)
{
Guard.NotNull(request, nameof(request));
return await _httpFacade.Put<Project>($"projects/{request.ProjectId}", request);
}

is replaced with

 public async Task<Project> UpdateAsync(object id, UpdateProjectRequest request) 
 { 
     Guard.NotNull(request, nameof(request)); 
     return await _httpFacade.Put<Project>($"projects/{id.ProjectIdOrPath}", request); 
 } 
public static string ProjectIdOrPath(this object obj)
{
    switch (obj)
    {
        case null:
            throw new ArgumentException("ID or Path cannot be null");
        case int id:
            return id.ToString();
        case string path:
            return path.UrlEncode();
        case Project project:
        {
            int id = project.Id;
            if (id > 0)
            {
                return id.ToString();
            }

            string path = project.PathWithNamespace?.Trim();
            if (!string.IsNullOrEmpty(path))
            {
                return path.UrlEncode();
            }

            break;
        }
    }
    throw new ArgumentException($"Cannot determine project ID or Path from provided {obj.GetType().Name} instance. " +
                                "Must be int, string, Project instance");
}

reason being id is path parameter and not a body parameter. Same reason for all these query parameter PRs 😄

Would be great to switch all int id, int projectId, int groupId and int userId out with object id so we can allow users to pass string without worrying about URL encoding or finding the damn project id.

This should help solve #18 and #33

@jetersen jetersen changed the title fixup request classes and use id/path as a object fixup request classes and use id/path as a object on method being called Sep 20, 2019
@jetersen
Copy link
Collaborator Author

apparently the user API only supports ID of users

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 a pull request may close this issue.

1 participant