Building "Know Africa" API

Building "Know Africa" API

Know Africa is a project that aims to correct common misconceptions about Africa held by people around the world. Surprisingly, some people think Africa is one country. They believe everyone speaks the same language, has the same culture, knows the next person, etc. but this is not true. Africa is a large continent with a lot of countries with different languages, cultures, foods, and so on. The goal of Know Africa is to showcase the beauty and diversity of the continent, and also make it easy for everyone to access the relevant information. This project is in the form of a REST API and the technologies used include Node JS, Express JS, Postgresql, and Sequelize.

I am working on this project as part of a team, Devcareer's backend team. So far, I have set up the development environment by installing sequelize and express packages. I created two models - comments and newsletters -, and also managed the continuous integration of the project using Github Actions and Coveralls (for test coverage).

According to Atlassian.com, continuous integration is the practice of automating the integration of code changes from multiple contributors into a single software project.

Continuous integration helps to minimize or prevent the introduction of anything that can "break the codebase." It ensures that all changes made to our project's repository do not affect the build. This particular task was a little challenging.

Github Actions is a recently added feature on Github, and there is a scarcity of tutorials on how to implement it into a project. I initially made use of Codeclimate, another test coverage tool, but my code kept returning errors. I created an issue on codeclimate-action - a GitHub action that publishes your code coverage to Code Climate -, but a response was not forthcoming. So I switched to Coveralls. After going through several materials, I was able to create the CI workflow for Know Africa using Github Actions and Coveralls. build.PNG

I also added badges to the readme file. They give readers an idea of what is going on in the repository even before looking through it. The hound badge shows that Hound is actively checking the quality of the code. The second badge shows that the build is passing. Maintainability shows how easy it is to modify the codebase. The last badge, coverage, shows how much of the code is being covered by tests.

badges.PNG

Currently, I am working on an endpoint http://127.0.0.1:3000/api/v1/admin/addcountry that, using a POST method, allows users to add a country to the database. For this to be possible, the user must be log in and must be an Admin. The route for this endpoint contains two middlewares to enforce these requirements.

import { Router } from "express";
import adminController from "../controllers/addCountry";
import loginAuth from "../middlewares/loggedIn";
import adminAuth from "../middlewares/isAdmin";

const router = Router();
router.post("/admin/addcountry", loginAuth.loggedIn, adminAuth.isAdmin, adminController.addCountry);

export default router;

Once they pass, the user will then be allowed to add a country.

There is still a lot of features to be added, but as a team, we are making good progress. The project can be followed via our Github repo, Code-jammers-backend