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

Resource Links support #243

Open
spersico opened this issue Oct 25, 2020 · 10 comments
Open

Resource Links support #243

spersico opened this issue Oct 25, 2020 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@spersico
Copy link
Member

We decided to launch to V1 without this feature, but the plan is to someday add support for resource links, and related resource links.

On a first glance, we have 4 big features to implement:

  • Provide Links of the the main resource (ref)
  • Provide Links of the related resources (ref)
  • Provide GET access to the related resources on those links (ref)
  • Provide UPDATE access to the related resources on those links (ref)
@spersico spersico added the discussion Useful for proof-of-concept code or draft PRs label Oct 25, 2020
@joelalejandro joelalejandro added enhancement New feature or request and removed discussion Useful for proof-of-concept code or draft PRs labels Dec 8, 2020
@isBatak
Copy link
Contributor

isBatak commented May 8, 2021

Any updates on this one?
And what about pagination, should this be added to?

  • first: the first page of data
  • last: the last page of data
  • prev: the previous page of data
  • next: the next page of data

https://jsonapi.org/format/#fetching-pagination

@isBatak
Copy link
Contributor

isBatak commented May 10, 2021

@spersico would it be possible to add pagination with a custom Addon?

@spersico
Copy link
Member Author

hi @isBatak!, it should... but the one that built the addons system is @joelalejandro.

@joelalejandro what do you think?

@joelalejandro
Copy link
Member

@isBatak @spersico Hey there! I think it's entirely possible, I made a couple of addons for features that can still be regarded as experimental for Kurier, so sure, it's possible. Once the feature is stable enough, we can consider bundling it as part of the core experience.

@isBatak
Copy link
Contributor

isBatak commented May 12, 2021

@joelalejandro 👋
Can you point out what should I do?
For the first step, I just want to support first, last, prev, next links for resources response.
I guess I need to extend this part https://github.com/kurierjs/kurier/blob/master/src/application.ts#L228 with links object, but how should I do it through Addon?

@isBatak
Copy link
Contributor

isBatak commented May 12, 2021

I figure out how to override buildOperationResponse inside of an addon.

import {
	Addon,
	Application,
	ApplicationInstance,
	HasId,
	KnexProcessor,
	Operation,
	OperationResponse,
	Resource,
} from 'kurier';
import { PaginationOptions } from './types';

const defaults: PaginationOptions = {
	defaultPaginator: 'paged',
	defaultPageSize: 10,
	maximumPageSize: 20,
};

export class PaginationAddon extends Addon {
	constructor(public readonly app: Application, public readonly options?: PaginationOptions) {
		super(app);
		this.options = { ...defaults, ...options };
	}

	async install(): Promise<void> {
		const oldBuildOperationResponse = this.app.buildOperationResponse.bind(this.app);

		this.app.buildOperationResponse = async (
			data: Resource | Resource[] | void,
			appInstance: ApplicationInstance
		): Promise<OperationResponse> => {
			const operationResponse = await oldBuildOperationResponse(data, appInstance);

			let links = {};

			if (Array.isArray(data)) {
			        // TODO
				links = {
					first: '',
					last: '',
					prev: '',
					next: '',
				};
			}

			return {
				...operationResponse,
				links,
			};
		};
	}
}

but the problem is that I need to change this helper also

function convertOperationResponseToHttpResponse(

... sad :(

@isBatak
Copy link
Contributor

isBatak commented May 13, 2021

@joelalejandro @spersico
I made a draft PR #275 to fix the above issue.
Could you check if I'm going in the right direction?

@joelalejandro
Copy link
Member

Sorry for the delay @isBatak, I was on vacation. I will take a look at it today or tomorrow.

@isBatak
Copy link
Contributor

isBatak commented May 19, 2021

@joelalejandro yeah no problem!

@joelalejandro
Copy link
Member

@isBatak I'm OK with the approach you describe in #275, feel free to go along with it 🚀

@joelalejandro joelalejandro added this to the 1.3.0 milestone Oct 17, 2022
@joelalejandro joelalejandro removed this from the 1.3.0 milestone Nov 11, 2022
@joelalejandro joelalejandro self-assigned this May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Waiting
Development

No branches or pull requests

3 participants