Giter Club home page Giter Club logo

ramadan-2020-assessments's Introduction

Ramadan 2020 assessments

Hi all, this is the repo that holds the assessments that covers ramadan 2020 series on Semicolon academy youtube channel, no implementations here, only the assessments, you could check later the resolutions on different repos on github as well, or watch the series and build it up together.

In this repo you will find some given express server configured to make some basic CRUD operations for getting and setting a video request from semicolon academy (as an example), also you will find an HTML file that has basic design of the required elements styled as well with twitter bootstrap, you only need to clone it and install dependencies of server and configure a local mongodb connection, then you are ready to make your first assessment, good luck 😉


Assessment 1 (Junior level friendly)

  1. After cloning the repo and installing the dependencies in the server folder, you should next setup mongodb locally and copy the connection url to the required place in server/models/mongo.config.js.
  2. Navigate to server directory, run npm install then run npm start in the server folder (btw, cors are enabled so you can run server if you want on a separate port).
  3. Implement the frontend code to make it work with the following functionalities:
    • Submit a video request. (API: POST -> /video-request)
    • Show list of requests below the form. (API: GET -> /video-request)
    • Vote up and down on each request. (API: PUT -> /video-request/vote)
    • Sorting options new first the default one, and top voted first.
    • Search box to search for video requests.
    • Client-side validation for the fields with * as required and for the email field, topic title should be max 100 length.
    • Add signup/login form with email.
    • Make votes unique so no one could cheat, using unique user, enhance the voting experience.
    • Make a super user capabilities, delete, add resolution video, and change status. all are only visible to him.
    • Add style to the super user capabilities and make filter by request statuses (NEW, PLANNED, DONE).
  4. Feel free to enhance the APIs to suit your needs if needed.
  5. You are supposed after all to make the requests work using AJAX to make the project looks like a SPA.
  6. Check all payloads in the schema at server/models/video-requests.model.js and check the endpoints at server/index.js
  7. You are obligated to write only pure JavaScript code without using any external utility or libraries.
  8. You should not write any css code or styling effort as the provided index.html file has almost all what you need, but you can use the bootstrap provided classes.

You can find the final version of the solution on the final branch

ramadan-2020-assessments's People

Contributors

dependabot[bot] avatar hameedgamal avatar medhatdawoud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ramadan-2020-assessments's Issues

Failed to execute `npm start` under server directory

Following instructions in first version and READEM.md I was not able to start the server locally because of missing dependancy express. It is not mentioned that I need to run npm install inside server directory

> node index.js
internal/modules/cjs/loader.js:1023
  throw err;
  ^
Error: Cannot find module 'express'

تحسين fetch الإستدعاء عند الحاجة للتنضيم والاداء

لماذا لا يكون استدعى api في ملف منفصل وبدلا من التكرار يمكن كتابة دالة للمعالجة استدعاء api backend
يمكن انشاء طريقة لاستدعء الباك اند وإرسال البيانات والبيانات تسترجع الى callback

function backendLookup(method, endpoint, callback, data) {
  let jsonData;
  if (data) {
    jsonData = JSON.stringify(data);
  }
  const xhr = new XMLHttpRequest();

  const url = `http://localhost/api${endpoint}`; 
  xhr.responseType = "json";
  xhr.open(method, url);
  xhr.setRequestHeader("Content-Type", "application/json");

  xhr.onload = function () {
    if (xhr.status === 403) {
      const detail = xhr.response.detail;
      if (detail === "Authentication credentials were not provided.") {
        if (window.location.href.indexOf("login") === -1) {
          window.location.href = "/login?showLoginRequired=true";
        }
      }
    }
    callback(xhr.response, xhr.status);
  };
  xhr.onerror = function (e) {
    callback(
      {
        message: "The request was an error",
      },
      400
    );
  };
  xhr.send(jsonData);
}

لإستخدام الدالة بطريقة GET

function apiTweetList(username, callback, nextUrl) { //  nextUrl to paigation to load more List
    let endpoint = "/tweets/";
    if (username) { // filter list by username 
        endpoint = `/tweets/?username=${username}`;
    }
    backendLookup("GET", endpoint, callback);
}

const handleLoadListResponse = (response, status) => {
    if (status === 200) {} else {
        alert("There was an error");
    }
};
apiTweetList(username, handleLoadListResponse, nextUrl);

استدعى اخر للدالة بطريقة POST

function apiTweetCreate(newTweet, callback) {
    backendLookup("POST", "/tweets/create/", callback, {
        content: newTweet,
    });
}

const handleBackendUpdate = (response, status) => {
    if (status === 201) {
        didTweet(response)
    } else {
        console.log(response)
        alert("An error occured please try again")
    }
}

const newVal = textAreaRef.current.value
// backend api request
apiTweetCreate(newVal, handleBackendUpdate)
textAreaRef.current.value = ''

ايضا عن طريق هذة الدالة يمككن ارسال زر التصويب وعدم التصويب بإستخدام طريقة واحدة

function apiTweetAction(tweetId, action, callback) {
    const data = {
        id: tweetId,
        action: action,
    };
    backendLookup("POST", "/tweets/action/", callback, data);
}
const handleActionBackendEvent = (response, status) => {
    console.log(response, status);
    if ((status === 200 || status === 201)) {}
};
event.preventDefault();
apiTweetAction(tweet.id, action.type, handleActionBackendEvent); // action.type : "up" or "down"  

دائما انا افضل XMLHttpRequest على fetch لانها ابسط وأسرع في الاداء
اتمنى لك التوفيق ونشكرا اخي على ما تقدمة من الاشياء المفيدة وربي يوفقك

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.