Skip to content

Latest commit

 

History

History
148 lines (117 loc) · 6.8 KB

LEARN.md

File metadata and controls

148 lines (117 loc) · 6.8 KB

Set Up your Database :

  • Go to your Supabase Dashboard.
  • Select your project / Create a new one.
  • Navigate to the "Project Settings" in the sidebar of your newly created project.
  • Now go to "API" under CONFIGURATION section.
  • Copy the URL and ANON-PUBLIC from this tab and paste in your .env.local file respectively.

For authentication, we have used Github OAuth using Supabase. To set this up:

  • Go to Github website.
  • Click on your profile icon, located on top-right of the webpage.
  • Click on "Settings" and go to Developers settings by scrolling down the page.
  • Click on OAuth Apps and create a new application.
  • From here you'll get two secret credentials - "Client ID" and "Secret".
  • Now navigate to Supabase, and go inside "Authentication" tab from the sidebar.
  • Under "Providers", find GitHub and fill in the "Client ID" and "Secret" fields with the details from your GitHub OAuth App.
  • If you haven't created a GitHub OAuth App yet, you can follow this guide.
  • Save your changes.
  • Now you can do the authentication using github.

For the recent users storage, we need to create a table in Supabase:

  • Go to your Supabase Dashboard.
  • Select your project.
  • Navigate to the "SQL Editor" tab in the sidebar. Screenshot 2024-05-12 at 5 26 14 PM
  • Run the following SQL query:
create table
  public.recent_users (
    id bigint generated by default as identity,
    created_at timestamp with time zone not null default now(),
    name text null,
    avatar_url text null,
    bio text null,
    username text not null,
    stars_recieved numeric null default '0'::numeric,
    forks numeric null default '0'::numeric,
    followers numeric null default '0'::numeric,
    public_repos numeric null default '0'::numeric,
    organizations_count numeric null default '0'::numeric,
    total_prs_merged numeric null default '0'::numeric,
    total_issues_created numeric null default '0'::numeric,
    rating double precision null default '-0.1'::double precision,
    constraint recent_users_pkey primary key (id),
    constraint recent_users_username_key unique (username)
  ) tablespace pg_default;
create table
  public.usage_tracking (
    id bigint generated by default as identity,
    created_at timestamp with time zone not null default now(),
    github_username text null,
    usage_count numeric null default '0'::numeric,
    date date null
  ) tablespace pg_default;
CREATE OR REPLACE FUNCTION get_user_rank(user_username text)
RETURNS TABLE(user_rank int) AS $$
BEGIN
  RETURN QUERY
  SELECT CAST(rnk AS int)
  FROM (
    SELECT username, rating, RANK() OVER (ORDER BY rating DESC) as rnk
    FROM recent_users
    WHERE rating != -0.1
  ) ranked_users
  WHERE username = user_username;
END;
$$ LANGUAGE plpgsql;
  • This will create a table named recent_users and get_user_rank function in your Supabase project.
  • Open that table from Table Editor and disable the RLS Policy. Screenshot 2024-05-12 at 5 32 04 PM Screenshot 2024-05-12 at 5 32 30 PM

Implmentation of Caching

  • Head over to Upstash. Sign up or log in to your account.
  • Select the Redis option from the dashboard.
  • Create a new caching database. Redis Create Database
  • Fill in the details and create the database.
    • Select the Primary Region closest to your location.
    • Select the Read Region closest to your location.
    • Tick the Eviction option. Redis Create DB Form
  • Copy the connection credentials from Rest API section. Redis Connection Credentials
    • Replace the connection credentials in your .env.local file with NEXT_PUBLIC_UPSTASH_REDIS_URL and NEXT_PUBLIC_UPSTASH_REDIS_TOKEN.
  • You are good to go. Caching is ready to be used.

For alternatively contributing using GitHub Desktop

  1. Open GitHub Desktop: Launch GitHub Desktop and log in to your GitHub account if you haven't already.

  2. Clone the Repository:

    • If you haven't cloned the ResourceHub repository yet, you can do so by clicking on the "File" menu and selecting "Clone Repository."
    • Choose the ResourceHub repository from the list of repositories on GitHub and clone it to your local machine.
  3. Switch to the Correct Branch:

    • Ensure you are on the branch that you want to submit a pull request for.
    • If you need to switch branches, you can do so by clicking on the "Current Branch" dropdown menu and selecting the desired branch.
  4. Make Changes: Make your changes to the code or files in the repository using your preferred code editor.

  5. Commit Changes:

    • In GitHub Desktop, you'll see a list of the files you've changed. Check the box next to each file you want to include in the commit.
    • Enter a summary and description for your changes in the "Summary" and "Description" fields, respectively. Click the "Commit to " button to commit your changes to the local branch.
  6. Push Changes to GitHub: After committing your changes, click the "Push origin" button in the top right corner of GitHub Desktop to push your changes to your forked repository on GitHub.

  7. Create a Pull Request:

    • Go to the GitHub website and navigate to your fork of the ResourceHub repository.
    • You should see a button to "Compare & pull request" between your fork and the original repository. Click on it.
  8. Review and Submit:

    • On the pull request page, review your changes and add any additional information, such as a title and description, that you want to include with your pull request.
    • Once you're satisfied, click the "Create pull request" button to submit your pull request.
  9. Wait for Review: Your pull request will now be available for review by the project maintainers. They may provide feedback or ask for changes before merging your pull request into the main branch of the ResourceHub repository.

⭐️ Support the Project If you find this project helpful, please consider giving it a star on GitHub! Your support helps to grow the project and reach more contributors.