add variable and method comments

This commit is contained in:
Mike Mason
2023-07-17 19:02:55 +00:00
parent 2681b3d064
commit bc87fa7726
35 changed files with 157 additions and 16 deletions

View File

@@ -15,21 +15,25 @@ type resourceRelationship struct {
SubjectID string `json:"subject_id"`
}
// ResourceRelationship defines the resource to subject relationship.
type ResourceRelationship struct {
ResourceID gidx.PrefixedID
Relation string
SubjectID gidx.PrefixedID
}
// ResourceRelationshipRequest defines the request to relate to a subject.
type ResourceRelationshipRequest struct {
Relation string `json:"relation"`
SubjectID string `json:"subject_id"`
}
// ResourceRelationshipDeleteResponse defines the response for a delete of a relationship.
type ResourceRelationshipDeleteResponse struct {
Success bool `json:"success"`
}
// DeleteResourceRelationship deletes the provided resources relationship to the given subject id.
func (c *Client) DeleteResourceRelationship(ctx context.Context, resourceID gidx.PrefixedID, relation string, relatedResourceID gidx.PrefixedID) error {
path := fmt.Sprintf("/api/v1/resources/%s/relationships", resourceID.String())
@@ -54,6 +58,9 @@ func (c *Client) DeleteResourceRelationship(ctx context.Context, resourceID gidx
return nil
}
// ListResourceRelationships returns resources related to the given id.
// If relatedResourceType is not provied, relations to subjects are returned.
// If relatedResourceType is provided, relations to the given resource are returned which match the given type.
func (c *Client) ListResourceRelationships(ctx context.Context, resourceID gidx.PrefixedID, relatedResourceType string) ([]ResourceRelationship, error) {
query := url.Values{
"resourceType": []string{relatedResourceType},