Coder Social home page Coder Social logo

whatsgood's Introduction

Background

whatsGood, is a platform for users to share lists of books. Users can create their own lists, follow other users, or follow other lists.

Find out whatsGood today!

Technologies Used

  • MongoDB
  • MongooseODM
  • Express
  • React
  • Node
  • Google Books API
  • Webpack
  • Babel
  • Bcrypt
  • Passport
  • Passport-JWT
  • JSON Web Token
  • Validator
  • Heroku
  • Git feature branching workflow
  • Trello KanBan project management
  • Icons from Font Awesome

Technical Challenge

Backend Routing

As our application is built based on relational data structure, the below snippet illustrates that backend provides three-level deep relationship data object that reference documents in other collection for frontend API requests, which significantly reduced the need to make multiple API calls and frontend has all necessary data accessible.

router.get('/:id', async (req, res) => {
    try {
        const userId = req.params.id;
        const user = await User.findById(userId)
            .populate({
                path: "followingLists",
                model: "List",
                populate: {
                    path: "bookItems",
                    model: "Book"
                },
            })
            .populate({
                path: "followingLists",
                model: "List",
                populate: {
                    path: "followers",
                    model: "User"
                },
            })
            .populate({
                path: "followingLists",
                model: "List",
                populate: {
                    path: "owner",
                    model: "User"
                },
            })

            .populate({
                path: "myLists",
                model: "List",
                populate: {
                    path: "followers",
                    model: "User"
                },
            })
            .populate({
                path: "myLists",
                model: "List",
                populate: {
                    path: "bookItems",
                    model: "Book"
                },

            })

            .populate({
                path: "followingUsers",
                model: "User",
                populate: {
                    path: "myLists",
                    model: "User"
                },
            })
            .populate({
                path: "followingUsers",
                model: "User",
                populate: {
                    path: "followingLists",
                    model: "List"
                },
            })
            .populate({
                path: "followingUsers",
                model: "User",
                populate: {
                    path: "followingUsers",
                    model: "User"
                },
            })

        res.json(user)
    } catch (e) {
        res.status(404).json({ user: 'No user found' })
    }
})

Feature

Search bar with debounced API requests

Users can use the search bar to search for books or other users. The search bar debounces the API request and maps through the JSON response. When user clicks user or book, they are taken to the approriate show page.

  const fetch = React.useMemo(
    () =>
      debounce((request) => {
        fetchBooksAndUsers(request)
          .then(json => {
            return setOptions(Object
              .values(json.data)
              .reverse()
              .flat()
              .map((res) => {
                if (res.volumeInfo) {
                  return ({
                    id: res.id,
                    volumeInfo: res.volumeInfo
                  });
                } else if (res.username) {
                  return ({
                    id: res._id,
                    username: res.username
                  });
                } else {
                  return null;
                }
              })
            )
          });
      }, 200),
    [],
  );

whatsgood's People

Contributors

ywbk avatar ethangumin avatar swusteven avatar johnda911 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.