Implementing comments and likes services
Let's now implement services for fetching comments and likes. These two services, CommentsService
and LikesService
, encapsulate the logic for liking and commenting on posts, alongside methods for fetching posts' comments and likes with pagination. Proceed as follows:
- Head back to your Terminal and run the following commands to generate
CommentsService
andLikesService
instances:ng g s core/services/comment/comments ng g s core/services/like/likes
- Open the
core/services/comment/comments.service.ts
file and start by adding the following imports to it:import { StoreObject } from '@apollo/client/core'; import { map } from 'rxjs/operators'; import { CommentPostGQL, RemoveCommentGQL, GetCommentsByPostIdGQL } from '../../gql.services';
Next, update the service constructor, as follows:
constructor( private commentPostGQL: CommentPostGQL, &...