Git Product home page Git Product logo

rent-check-backend's Introduction

Rent Check

logo

Rent Check is an application that serves as a convenient checklist designed to simplify your apartment rental experience.

The app streamlines apartment choice by categorizing check items, allowing you to create groups within each flat based on necessity (must-have and optional), room-specific criteria (bathroom and bedroom), and any other preferences you desire.

In most cases, you confidently assess requirements, checking items like “not ground floor” for a second-floor apartment. In situations of uncertainty, such as when considering pets allowed and a landlord permits cats but is unsure about dogs, Rent Check introduces a meh option.

After inspecting all the apartments and marking your preferences, you'll have a consolidated list of potential flats, conveniently organized based on your specific criteria. This makes comparing apartments and reaching a final decision a simplified process.

Table of contents

User Guide

Register & Login

To register and log in, enter your username and password.

Note that currently, our app supports only one authentication method (refer to Bearer Authentication for details).

Add Flat

Click the + button to add a flat. Provide the mandatory address and, optionally, a title and description. Upon completion, you'll be redirected to a dedicated page for the created flat.

add-flat

Add Group

Click the + button to add a group. Next, either assign a new unique title or select from existing groups – those you currently have or had across all flats. As a result, a new empty group is created.

add-group

Add Item

Click the + button to the right of a group title to add an item to the specific group. Likewise for groups, provide either a new unique title or select an existing item. Thus, a new item is added to the group.

add-item

Set an Item Status

There are four statuses you can assign to an item:

  • unset, no color: Haven't been checked yet.
  • not ok, red color: Doesn't meet the requirement.
  • ok, green color: Meets the requirement.
  • meh, yellow color: Uncertain if it meets the requirement or not.

To change the status, simply tap on the item.

set-item-status

Delete Item

Swipe an item to delete it from the group.

delete-item

Delete Group

To delete a group, click the 🗑️ button at the right.

delete-group

Delete Flat

To delete a flat, long tap on it

delete-flat

What's Next

This version represents an MVP, with more exciting features coming!

Check the Rent Check Project to explore opened issues and stay tuned for updates 💙

Implementation Details

For technical details regarding the backend, please refer to the corresponding section. For the frontend, check out the corresponding repository.

Architecture

The application follows a layered architecture:

  • DB Layer: stores and retrieves data
  • Repository Layer: interface to interact with the database using an ORM
  • Business Logic Layer: core logic of the app
  • Handlers Layer: manages user requests

Technologies Used

The code is implemented in Go, using the following stack:

Database Schema

db-scheme

Authentication and Authorization

The app employs token (Bearer) authorization for secure user access. Here's how it works:

  • Registration: when a user registers, their login and password hash are stored in the database
  • Login: upon login, a new JWT token is generated, or the existing one is retrieved; this token is then sent to the frontend in the Authorization header
  • Logout: when a user logs out, the corresponding token is deleted from the database, terminating the session

Testing

Integration tests have been implemented for the repository layer. Testcontainers is utilized to set up a Docker container with a test database.

The current test coverage averages around 80% for flat, group, item, and user repositories.

Deployment

Docker serves as the deployment solution, here are the key characteristics of its configuration:

  • Two services: db for PostgreSQL and api for the application
  • Usage of the bridge network driver to connect the db and api services
  • Health check of PostgreSQL before starting the api service
  • Integration of the volume driver for persistent storage

Development Team

  • @alyoanton9: backend, business logic, UI design, logo creation
  • @NewUserKK: frontend, business logic, UI design, idea

rent-check-backend's People

Contributors

alyoanton9 avatar

Stargazers

Sofya Povarova avatar  avatar Taya avatar Roman Usik avatar

Watchers

 avatar

rent-check-backend's Issues

Groups Copying Feature

When a user adds a group to a new flat, it's likely the same as some group in the existing flat. In such a case, it would be convenient to copy all the group items from the existing group.

So, at UI some suggestion is needed, and the corresponding endpoint should be provided by the backend and used by the frontend.

This issue is already implemented at the backend, the corresponding closed PR can be found in "mentioned".

Add CI

It's not a priority, but it would be great to have CI, including

  • build check
  • tests pass check

Consider options to check error type in tests

Currently, the way errors are compared in tests is their error messages comparing. It is quite reliable, but perhaps comparing types/objects would be better, e.g. simple assert.Equal(t, err, test.expectedError). Consider the possible variants, find out what are the best practices.

Flats Copying Feature

When a user creates a new flat, checklist elements likely are the same or at least intersect with others already added. In such a case, it would be convenient to copy all the groups and group items from an existing flat.

So, at UI some suggestion is needed, and the corresponding endpoint should be provided by backend and used by frontend.

Copy groups and items from existing flat

When a user wants to add groups to a new flat, they're likely the same as groups in any existing flat. Generally, some suggestion is needed to fulfill group list with some template.

  1. Handler to get all flats that have a certain group (by group id), return flat models but not just ids
  2. Amend AddGroupToFlat: add flat id parameter from which to copy; if nill -- don't copy

Resolves #21

Fix internal server errors

For example, here should be a bad request, so db exceptions need to be handled

2024/01/17 20:19:59 /app/internal/repository/group.go:102 violates foreign key constraint
[108.438ms] [rows:0] INSERT INTO "flat_groups" ("flat_id","group_id") VALUES (0,1)
2024/01/17 20:19:59 error adding group to flat: violates foreign key constraint
reponse body: {"message":"Internal Server Error"}

Add predefined groups and items

It would be cool to provide users with predefined groups & items set.

So, it's required to come up with common groups/items, and add corresponding functionality to backend and frontend.

Provide Flats Statistics

It would be easier to compare flats by having a summary for each, such as the count of items marked as ok, not ok, and other relevant categories.

In UI, embed clear and accessible summary numbers for each flat. Provide the corresponding endpoint at the backend and call it at the frontend.

Refactor `NoAccess` error messages

In case when some entity doesn't have access to other, NoAccess error is produced. E.g.:

  • user has no access to flat: {Msg: "access", Field: "userId,flatId"}
  • flat doesn't contain group: {Msg: "access", Field: "flatId,groupId"}
    ...
  • there is no item in particular flat's group: {Msg: "access", Field: "itemId"}

Consider more suitable error fields/messages.

Amend provision of authorization header

Currently, a new auth token is being generated on each login. There is an issue when the user logs in on several devices simultaneously -- the second token will rewrite the first one and the user will be logged out at the 1st device.

Check the auth token existence first, then generate the new one if there is a null.

Prettify logs

Here is a logging middleware, which produces verbose logs but not quite human-friendly. Consider some logging libs and technics to improve it.

Add "unhide" logic

DELETE /groups/:id doesn't delete the group completely but hides it. Such implementation allows to hide a group from user's search list, and to keep the former in users' flats.

Problems start when creating a new group or updating an existing group with the hidden group's name. In the first case, it's needed to unhide the group somehow. In the second one, to consider the appropriate implementation.

❗ Same for items

Research `Access-Control-Allow-Origin` header sending

When authorization fails, looks like Access-Control-Allow-Origin header is not sent. As a result, the frontend gets a CORS policy violation error. Seems that CORS and Auth echo middleware don't get along. Perhaps, auth wipes out CORS headers.

Research and fix needed

Enable HTTPS to enhance security

For secure communication, HTTPS is a must-have.

Frontend is already hosted via HTTPS, so it's required to protect communication between backend and frontend.

Possible options: Yandex Cloud Serverless Containers, Google Cloud Run (Firebase)

Display User-friendly Error Messages

The current error handling in the application needs improvement, especially in providing clear and user-friendly error messages.

At the backend, refactoring error responses sent is needed, as well as debugging authentication error responses that don't send headers properly.

The frontend requires an implementation of a logic for displaying user-friendly error messages, as well as handling error responses.

Provide Bearer authentication

For now, it was decided to simplify authentication and authorization and use Bearer instead of Google (or any other service) OAuth 2.0

So it's required to provide auth/register, auth/login, and auth/logout handlers

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.