gmccannon / ISPProject

ISP Term Project
https://isp-project.vercel.app
0 stars 0 forks source link

Query Database #2

Open Thenewchicken55 opened 3 days ago

Thenewchicken55 commented 3 days ago

For now, the code can read an array of articles and display it. We need to somehow query the database (or dataset) instead and get data. Note, the database is not implemented yet I don't think.

let sampleArticles: NewsArticle[] = [
  {
    title: "Article 1",
    subtitle: "Subtitle 1",
    content: "Content 1",
  },
  {
    title: "Article 2",
    subtitle: "Subtitle 2",
    content: "Content 2",
  },
  {
    title: "Article 3",
    subtitle: "Subtitle 3",
    content: "Content 3",
  },
];

image

gmccannon commented 3 days ago

The endpoint is something along the lines of this: https://newsapi.org/v2/{{type}}?q=&from=&sortBy=&apiKey=

type: can be "top-headlines" or "everything", i think there are more?????? ill have to check q: refers to content in the title (ie 'apple' would return all articles with apple in the title) from: refers to a date, 2024-11-20 sortBy: self explanatory, popularity and date are two options apiKey: the api key

i think the mongoose type should look something like:

const newsApiRequestSchema = new mongoose.Schema({ type: { type: String, required: true, enum: ['top-headlines', 'everything'] }, q: { type: String, }, from: { type: Date, }, sortBy: { type: String, enum: ['popularity', 'date'], // there are more options we can add later }, });

Thenewchicken55 commented 3 days ago

Sounds good. Feel free to make any commits u want. Just to confirm, So are we querying news and storing it in db? I think that works well.

gmccannon commented 3 days ago

yep

gmccannon commented 3 days ago

oops, i just realized you were referring to the news article type, not the request

This is what i found as a suggestion on newsapi all of these values should be in the payload we get back from the call

type NewsArticle = { source: { id: string | null; name: string; }; author: string | null; title: string; description: string | null; url: string; urlToImage: string | null; publishedAt: string; content: string | null; };