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

Feature/feed article list #213

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bff/apollo-gateway/src/app/content/content.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
ArticleOGP,
ArticlesInput,
FeedConnection,
Feed,
FeedsInput,
FeedInput,
} from '../../graphql/types/graphql';
import { SupabaseAuthGuard } from '../auth/auth.guard';

Expand Down Expand Up @@ -47,4 +49,14 @@ export class ContentResolver {
const user = context.req.user;
return await this.feedService.getFeeds(user.id, feedsInput);
}

@Query(() => Feed)
@UseGuards(SupabaseAuthGuard)
async feed(
@Args('feedInput') feedInput: FeedInput,
@Context() context: GraphQLContext,
): Promise<Feed> {
const user = context.req.user;
return await this.feedService.getFeed(user.id, feedInput);
}
}
43 changes: 42 additions & 1 deletion bff/apollo-gateway/src/app/content/feed/feed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import {
Int64Value,
StringValue,
} from 'google-protobuf/google/protobuf/wrappers_pb';
import { FeedConnection, FeedsInput } from 'src/graphql/types/graphql';
import {
FeedConnection,
FeedsInput,
Feed,
FeedInput,
} from 'src/graphql/types/graphql';
import { GetFeedsRequest } from 'src/grpc/content/content_pb';

import { convertTimestampToInt } from '../../../utils/timestamp';
Expand Down Expand Up @@ -91,4 +96,40 @@ export class FeedService {
});
});
}

async getFeed(userId: string, input: FeedInput): Promise<Feed> {
console.log('getFeed', userId, input);
return new Promise((resolve) => {
resolve({
apiQueryParam: '',
category: {
createdAt: 0,
id: '',
name: '',
type: 0,
updatedAt: 0,
},
createdAt: 0,
description: '',
id: '',
myFeedIds: [],
name: '',
platform: {
createdAt: 0,
faviconUrl: '',
id: '',
isEng: false,
name: '',
platformSiteType: 0,
siteUrl: '',
updatedAt: 0,
},
rssUrl: '',
siteUrl: '',
thumbnailUrl: '',
trendPlatformType: 0,
updatedAt: 0,
});
});
}
}
6 changes: 6 additions & 0 deletions bff/apollo-gateway/src/graphql/types/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ export class FeedsInput {
before?: Nullable<string>;
}

export class FeedInput {
id: string;
}

export interface Node {
id: string;
}
Expand All @@ -176,6 +180,8 @@ export abstract class IQuery {
abstract favoriteAllFolderArticles(input?: Nullable<FavoriteAllFolderArticlesInput>): FavoriteAllFolderArticleConnection | Promise<FavoriteAllFolderArticleConnection>;

abstract feeds(feedsInput: FeedsInput): FeedConnection | Promise<FeedConnection>;

abstract feed(feedInput?: Nullable<FeedInput>): Feed | Promise<Feed>;
}

export class Article implements Node {
Expand Down
5 changes: 5 additions & 0 deletions bff/apollo-gateway/src/schema/feed/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type Query {
Get feeds
"""
feeds(feedsInput: FeedsInput!): FeedConnection!
feed(feedInput: FeedInput): Feed!
}

input FeedsInput {
Expand All @@ -13,4 +14,8 @@ input FeedsInput {
after: String
last: Int
before: String
}

input FeedInput {
id: ID!
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

type ArticlePersistenceAdapter interface {
GetArticles(ctx context.Context, req *cpb.GetArticlesRequest) (entity.ArticleSlice, error)
GetArticles(ctx context.Context, req *cpb.GetArticlesRequest, limit int) (entity.ArticleSlice, error)
GetArticlesByArticleURLAndPlatformURL(ctx context.Context, articleURL, platformURL string) (entity.ArticleSlice, error)
GetPrivateArticlesByArticleURL(ctx context.Context, articleURL string) (entity.ArticleSlice, error)
GetArticleRelationPlatform(ctx context.Context, articleID string) (entity.Article, error)
Expand All @@ -31,12 +31,7 @@ func NewArticlePersistenceAdapter(ar repository.ArticleRepository) ArticlePersis
}
}

func (apa *articlePersistenceAdapter) GetArticles(ctx context.Context, req *cpb.GetArticlesRequest) (entity.ArticleSlice, error) {
limit := 20
if req.GetLimit() != 0 {
limit = int(req.GetLimit())
}

func (apa *articlePersistenceAdapter) GetArticles(ctx context.Context, req *cpb.GetArticlesRequest, limit int) (entity.ArticleSlice, error) {
q := []qm.QueryMod{
qm.InnerJoin("platforms ON articles.platform_id = platforms.id"),
qm.LeftOuterJoin("feed_article_relations ON articles.id = feed_article_relations.article_id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import (
)

func (cu *contentUseCase) GetArticles(ctx context.Context, req *cpb.GetArticlesRequest) (*cpb.GetArticlesResponse, error) {
articles, err := cu.articlePersistenceAdapter.GetArticles(ctx, req)
limit := 20
if req.GetLimit() != 0 {
limit = int(req.GetLimit())
}

articles, err := cu.articlePersistenceAdapter.GetArticles(ctx, req, limit)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -83,7 +88,7 @@ func (cu *contentUseCase) GetArticles(ctx context.Context, req *cpb.GetArticlesR
return &cpb.GetArticlesResponse{
ArticlesEdge: edges,
PageInfo: &cpb.PageInfo{
HasNextPage: len(edges) == 20,
HasNextPage: len(edges) == limit,
EndCursor: edges[len(edges)-1].Cursor,
},
}, nil
Expand Down
12 changes: 7 additions & 5 deletions web/client-v2/src/app/feed/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { redirect } from "next/navigation";

import { getUser } from "@/features/auth/actions/user";
import { FeedArticleListTemplate } from "@/features/feeds/components/Template";

type FeedByIdPageProps = {
params: { id: string };
Expand All @@ -16,9 +17,10 @@ export default async function FeedByIdPage({
redirect("/login");
}
const { id } = params;
return (
<div>
<h1>{`feed ${id}`}</h1>
</div>
);
const keyword =
typeof searchParams["keyword"] === "string"
? searchParams["keyword"]
: undefined;

return <FeedArticleListTemplate id={id} keyword={keyword} />;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import { User } from "@supabase/supabase-js";
import { clsx } from "clsx";
import { FragmentOf, readFragment } from "gql.tada";
import NextLink from "next/link";
Expand All @@ -9,18 +8,13 @@ import { FC } from "react";
import { ZoomableImage } from "@/components/ui/image";
import { Link } from "@/components/ui/link";


import { showDiffDateToCurrentDate } from "@/lib/date";

import { ArticleTabType } from "@/types/article";

import styles from "./ArticleCardItem.module.css";
import { ArticleCardItemFragment } from "./ArticleCardItemFragment";

type ArticleCardItemProps = {
data: FragmentOf<typeof ArticleCardItemFragment>;
user: User;
tab: ArticleTabType;
};

export const ArticleCardItem: FC<ArticleCardItemProps> = ({ data }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import { User } from "@supabase/supabase-js";
import { clsx } from "clsx";
import { FragmentOf, readFragment } from "gql.tada";
import { FC } from "react";
Expand All @@ -27,7 +26,6 @@ type ArticleCardWrapperProps = {
favoriteArticleFolders: FragmentOf<
typeof FavoriteFolderArticleCardWrapperFragment
>;
user: User;
tab: ArticleTabType;
};

Expand All @@ -36,7 +34,6 @@ const TREND_TAB = "trend";
export const ArticleCardWrapper: FC<ArticleCardWrapperProps> = ({
data,
favoriteArticleFolders,
user,
tab,
}: ArticleCardWrapperProps) => {
const fragment = readFragment(ArticleCardWrapperFragment, data);
Expand Down Expand Up @@ -133,7 +130,7 @@ export const ArticleCardWrapper: FC<ArticleCardWrapperProps> = ({
</div>

<div>
<ArticleCardItem data={fragment} user={user} tab={tab} />
<ArticleCardItem data={fragment} />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ export function ArticleList({ user, languageStatus, tab }: ArticleListProps) {
key={`${i}-${edge.node.id}`}
data={edge.node}
favoriteArticleFolders={resSuspenseData.favoriteArticleFolders}
user={user}
tab={tab}
/>
))}
Expand Down
Loading
Loading