Commit Graph

56 Commits

Author SHA1 Message Date
Naz
cdae2a978d Added ability to fetch collection posts by slug
closes https://github.com/TryGhost/Arch/issues/27

- We need a more convenient method of fetching posts belonging to a collection than by collection's "id". This change adds an alias to the existing endpoint `GET /collections/:id/posts/`. A non-valid ObjectID in the parameter is treated as a slug.
2023-07-11 09:30:01 +08:00
Naz
cb8e009c14 Allowed for index collection to have empty filter
refs https://github.com/TryGhost/Arch/issues/25

- The built in index (soon -> "latest") collection does not require any filtering so that it could contain an index of all posts in the system. All other automatic collections should have a filter defined.
2023-07-10 12:43:52 +08:00
renovate[bot]
aa8cbb9fa3 Update dependency typescript to v5.1.6 2023-06-29 08:24:30 +02:00
Fabien "egg" O'Carroll
16db3bbf17 Removed deletable property in favour of protected slugs
We couldn't decide on the best way to encode this in the database.
e.g. deletable: true? or type: internal? but type conflicts with the
storage of manual/automatic.

For now we can use this, and add something in future if we're finding problems
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
cf83d169db Added use of a slug generator to offload calculation of slugs
When we end up wiring this to the database, this generator will also ensure
uniqueness by appending/incrementing a number on the end of the slug. Long term
it would be good to offload this to a shared slug service, this could also
ensure that slugs are unique globally or between multiple tables, if desired
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
0a3e36cd62 Ensured uniqueness of slug in collections
We require that slugs are unique as slugs can/are used for routing purposes and
act as an identifier for a resource. As this is a core business rule, we want
to encode it in the entity so that it can be unit tested, and be enforced
regardless of underlying persistence layer
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
d29f512823 Required titles for collections
We don't want to allow collections to be created without a title, and we need
to encoe that business rule in the entity.
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
0cfa236570 Fixed visibility of internal _posts member
The _posts member is supposed to be an iternal property to store the data used
by the `posts` getter/setter
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
633cecdf75 Fixed createCollection not waiting for save
This can cause race conditions when writing e2e tests in the case of to the API
responding before persisting the data
2023-06-29 01:40:05 +01:00
renovate[bot]
58b54333a5 Update dependency typescript to v5.1.5 2023-06-28 16:21:27 +02:00
Naz
5dd6159ac6 Added handling for 'post.edited' Ghost model event
refs https://github.com/TryGhost/Team/issues/3169

- Adds optomized collection update handling for when post.edited model event is emitted.
2023-06-27 12:52:10 +07:00
Naz
a8e5cbcc3d Extracted post matching to filter to separate method
refs https://github.com/TryGhost/Team/issues/3169

- This method is also useful for external services when checking if collection needs any updates or not.
2023-06-27 12:52:10 +07:00
Naz
bb13845773 Added future perf oprimization note
refs 1bc2a604c3 (r1239780571)
2023-06-27 12:52:10 +07:00
Naz
cf48d4ef5c Removed ability to change collection type after creation
refs https://github.com/TryGhost/Team/issues/3169

- Being able to change the collection type comes with extra complications we don't wan to support just yet. This came up as a part of the PR review here - 1bc2a604c3 (r1239783573).
2023-06-27 12:52:10 +07:00
Naz
623599af1e Moved DomainEvents to be injected to Collections
refs https://github.com/TryGhost/Team/issues/3169

- With the new architecture all possible dependencies should be  injected rather than required directly - this applies to the DomainEvents module as well.
2023-06-27 12:52:10 +07:00
Naz
36783e456b Added 'post.added' event handling in Collections
refs https://github.com/TryGhost/Team/issues/3169

- This piece of logic handles the 'post.added' model event mapping to Collection's PostAddedEvent domain event and logic related to updating collections when the new post is added.
2023-06-27 12:52:10 +07:00
Naz
42539b954f Added collection editing method
refs https://github.com/TryGhost/Team/issues/3169

- The collection entity properties used to be modified, which is not a good practice for logic encapsulation. Extracted editing logic to it's own method which can also contain validation logic when wrong data is passed when editing a collection.
2023-06-27 12:52:10 +07:00
Naz
58a18d37ea Introduced PostEvent classes to make event handling less generic
refs https://github.com/TryGhost/Team/issues/3169

- When handling a single generic event the code becomes riddled with if statements to detect correct "data" that is being passed with the event. Switching to have a domain event per model event helps solving this problem and makes code more readable.
2023-06-27 12:52:10 +07:00
Naz
ebd58515bd Refactored post removal from all collections
refs https://github.com/TryGhost/Team/issues/3169

- It's easier to read this way and possibly reusable in the future
2023-06-27 12:52:10 +07:00
Naz
e7a0462877 Added model event to domain event bridge
refs https://github.com/TryGhost/Team/issues/3169

- To make the coupling to Ghost's model events as loose as possible added a bridge that maps model events to domain events. These domain events it what the collections module can subscribe to to make necessary updates.
2023-06-27 12:52:10 +07:00
Naz
49d831d971 Optimized handling for post.deleted event in collections
refs https://github.com/TryGhost/Team/issues/3428

- I'm taking an approach of adding specialized support for each event one-by-one.
- The post resource deletion event is the most straight forward and works same for both types of collections.
2023-06-27 12:52:10 +07:00
Naz
25e0cb12c0
Added "getBySlug" method to Collections Service
refs https://github.com/TryGhost/Team/issues/3423

- This is a convenience method that should allow fetching collections by their slug. It is a great developer experience for in case when fetching built-in collections like "featured" and "index", so can avoid an extra call to find the collection and it's ide one wants to use.
2023-06-16 16:31:50 +07:00
Naz
6335033466
Added full post data when returning collection's posts
refs https://github.com/TryGhost/Team/issues/3423

- When querying for posts that belong to a collection we should be returning full post information just like we do for Posts API.
2023-06-15 18:35:58 +07:00
Naz
ddc23b3467 Added collection's posts fetching to collections lib
refs https://github.com/TryGhost/Team/issues/3423

- This is a building block to allow paging, querying etc. of the posts belonging to a collection
2023-06-13 17:23:09 +07:00
Fabien 'egg' O'Carroll
92172aca8e
Wired up collections to posts endpoint (#16945)
- Added support for `include=collections` to the Posts Admin API behind a flag
- Refactored some of the collections work to support it
2023-06-07 15:06:15 +02:00
Naz
fab5b1845c
Made builtin collections un-deletable
closes https://github.com/TryGhost/Team/issues/3376

- It should not be possible to delete a built-in collection.
2023-06-06 22:04:16 +07:00
Naz
5a8eec402f
Restricted built-in collection init to run once
refs https://github.com/TryGhost/Team/issues/3376
fixes b4a97d084f

- The in-memory stores are not cleaned up when the Ghost instance is "shallow restarted" between test suite runs, causing the initialization of built-in collections to run multiple times. The initialization should ever add the collections once.
2023-06-06 13:35:06 +07:00
Naz
2390afc6f1
Added automatic collection recalculation
closes https://github.com/TryGhost/Team/issues/3170

- When resources that are related to automatic collection filter are updated the posts in collections should be updated as well.
- This change adds a super-basic way to track changes in post/tag/author resources and updated all automatic collections when any of those resources change. In the future we can optimize the update process to be more performant, but it's good enough for current needs
2023-06-05 18:33:39 +07:00
Naz
3599cfdd7a
Added test coverage for collection updates
refs https://github.com/TryGhost/Team/issues/3170

- When the collection filter is updated the collection's posts should be updated automatically.
2023-06-05 16:23:02 +07:00
Naz
bfefcfd4df
Added automatic collection creation based on filter
refs https://github.com/TryGhost/Team/issues/3170

- This implementation allows to create an automatic collection with a filter defining automatically populated posts that belong to a collection
- To populate collection using a filter the API client can send a `filter` property along with a collection request
- Filter values are compatible with the filters used in Content API (https://ghost.org/docs/content-api/#filter)
2023-06-05 13:39:52 +07:00
Naz
6e224f3702
Added automatic collection validation
refs https://github.com/TryGhost/Team/issues/3170

- When an automatic collection is created it should always have a valid filter assigned
2023-06-05 13:39:52 +07:00
renovate[bot]
17acd2437b Update dependency typescript to v5.1.3 2023-06-02 09:06:20 +02:00
Naz
e8220b1387
Added DEL /collections/:id/posts/:post_id to Admin API
refs https://github.com/TryGhost/Team/issues/3260

- We need a way to remove posts form collections without fetching the whole collection's content. This API method allows to remove posts from manual collections by collection id and post id.
- As a response it returns up to date collection state without the removed post.
2023-06-01 14:59:05 +07:00
Naz
253f144501 Fixed fromDTO collection mapping
refs https://github.com/TryGhost/Team/issues/3260

- Whenever properties of the DTO are undefined they should be removed to avoid unintentional empty assignments to the stored collection
2023-06-01 14:25:49 +07:00
Naz
a0a7c3a61b Added coverage to all editable collection properties
refs https://github.com/TryGhost/Team/issues/3260

- Made sure we have sufficient coverage for all editable properties of the collection to avoid sneaky bugs
2023-06-01 14:25:49 +07:00
Naz
5d16425428 Fixed description editing in collections service
refs https://github.com/TryGhost/Team/issues/3260

- Fixed broken functionality after a refactor
2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
b48a1d0a57 Implemented adding posts to collections; 2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
bd4fac451c Update CollectionsService to remove CollectionPost usage 2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
27f60b4ab5 Added logic for adding posts to collection
Also removes concept of CollectionPost in an effort to simplify the structure
2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
917ab0a79e Added CollectionRepository
This defines the interface required by the CollectionsService
2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
5282c4a72b Update eslint and c8 to support using TS interfaces
This will allow us to define the repository interface
2023-06-01 14:25:49 +07:00
Naz
a0c36e16d0 Added "addPost" method do collections module
refs https://github.com/TryGhost/Team/issues/3260

- The method allows to append individual posts to the collection
2023-06-01 14:25:49 +07:00
Naz
87df8754ee Moved bookshelf posts repository to core
refs https://github.com/TryGhost/Team/issues/3260

- Moved the posts bookshelf repository into core codebase where it should belong.
2023-05-31 22:55:35 +07:00
Naz
66d489b8b3 Added Posts relation support to collections package
refs https://github.com/TryGhost/Team/issues/3260

- Adds "posts" relation to Collection entity to manage posts belonging to the collection
2023-05-31 22:55:35 +07:00
Fabien "egg" O'Carroll
b58dac262e Updated collections package to use .d.ts for external lib types
Rather than using `require` we can add a type definition file, this allows us
to add custom types in the future if we want. We need to add some config for
ts-node to pick up the types correctly.
2023-05-24 12:47:20 -04:00
Naz
258a562031
Fixed linting error
refs fdd73d01b7
2023-05-24 17:31:14 +07:00
Naz
4cb5cc9087
Added default collection values
refs https://github.com/TryGhost/Team/issues/3259

- For collection entity creation consistency have set defaults
2023-05-24 17:01:28 +07:00
Naz
b52ec948b0
Added property mapper to collections responses
closes https://github.com/TryGhost/Team/issues/3259

- API output mappers (soon to be serializers) are meant to work based on allowlist set of output properties. Having the allowlist early on will allow to track the API evolution consistently.
2023-05-24 17:01:28 +07:00
Naz
fdd73d01b7
Refactored collections entity logic
refs https://github.com/TryGhost/Team/issues/3294

- The factory method for the Collection and validations should live close together based on our latest architectural direction
2023-05-24 17:01:28 +07:00
Naz
735edf5f87 Fixed editing unexistent collection behavior
refs https://github.com/TryGhost/Team/issues/3167

- When editing collection that does not exist the API should be returning a 404 instead of creating a new collection
2023-05-19 20:42:46 +07:00