Coder Social home page Coder Social logo

e-terven / catarion_stack_overflow Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 13.37 MB

A prototype of a legend - QA Forum Stack Overflow

Java 71.37% CSS 0.24% JavaScript 3.02% HTML 25.37%
dbrider docker-compose dockerfile github gitlab liquibase postgresql springboot swagger rest-api

catarion_stack_overflow's Introduction

catarion_stack_overflow

I was a commuter to an open source project [check the branch "290-dbrider-dataset-2"]

- Environment configuration
- Frontend with HTML and Bootstrap
- API implementation
- Verified and resolved bug reports and issues
- Git Version Control to track changes and deal with Git Conflict

What I configured

🧩 Docker (dockerfile and docker compose)

🧩 Liquibase (connected it to database)

🧩 DBRider customization

Tasks I complited

✅ Built All Questions page with HTML and Bootstrap


alt-текст

✅ Implemented API in ResourceAnswerController:

POST _api/user/question/{questionId}/answer/{id}/downVote_
In Stack Overflow forum, when a User votes for an Answer, the Reputation of the answer's author decreases by 5 points. API should include a documented feature that returns the Total Vote Count, which is the sum of upvotes and downvotes. However, this functionality is only available to authorized users.

First, I took answer id and question id from Url adding an authorized user - from SecurityContextHolder:
(path: src/main/java/com/javamentor/qa/platform/webapp/controllers/rest/ResourceAnswerController.java)

  • alt-текст

The interesting thing here is that there are multiple edge cases we have to consider to count the Total Amount of Votes. Such as:

  1. User can Votedown only once. Thus, the method voteAnswerExists in ResourceAnswerController validates if the object already exists in database: alt-текст further, in VoteAnswerService: (path: src/main/java/com/javamentor/qa/platform/service/impl/model/VoteAnswerServiceImpl.java) alt-текст finally, in a VoteAnswerDao: (path: src/main/java/com/javamentor/qa/platform/dao/impl/model/VoteAnswerDaoImpl.java) alt-текст

  2. User cannot vote for own answer. Therefore, I checked if the User is not an author of the Answer in REST-Controller by implementing the getByIdAndChecked method that queries the information from database: alt-текст Service layer:
    alt-текст Dao layer: alt-текст

  3. The author of the Answer has to be "granted" by -5 points; ergo, his Reputation status should be updated in a few steps:
    (path: src/main/java/com/javamentor/qa/platform/service/impl/model/ReputationServiceImpl.java)
    alt-текст
    __ check if the instance of the Rreputation exists:
    alt-текст
    __ update points or create a new Reputation:
    alt-текст
    __ fill in the fields of newReputation in case it was created:
    alt-текст

  4. To return the Total Amount of Votes we have to compute both down and up votes of the Answer:
    alt-текст

  5. Besides, we have to check if the Answer and the Question (related to the answer) exist. Here I use EnitityManager in Dao layer to query information from database:
    alt-текст

Let us focus on the reputationService.updateCountByDown that takes two parameters: a User who wrote the Answer and an Answer's ID:

✅ Configurated and connected Database Rider


DBRider is a Java testing library that facilitates writing integration tests for database-related code
<dependency>
      <groupId>com.github.database-rider</groupId>
      <artifactId>rider-core</artifactId>
      <version>1.35.0</version>
      <scope>test</scope>
</dependency>

alt-текст

alt-текст

@DataSet annotation is implemented to configure a DataSet (vs. DBUnit) and is specified with the following feature:

  • strategy = SeedStrategy.INSERT meaning that DBUnit will insert data in tables present on provided data;

  • skipCleaningFor allows to skip cleaning for "db_liquibase" to preserve data that is managed by an external tool - Liquibase;

  • cleanAfter calls a cleaning process after test that will ensure any changes are rolled back to leave the database in its original state;

  • tableOrder defines the order in which tables should be cleaned after the test to ensure child tables will be cleaned before their parents.

alt-текст

catarion_stack_overflow's People

Contributors

999nikolai avatar advaito avatar alexthepie avatar alkpankov avatar amargenter avatar anatolii7495 avatar andyvolch avatar armankalmakhambetov avatar asimmetria avatar belyash1990 avatar chegazzz avatar darkside1608 avatar dencyh avatar dina2393 avatar dyachkovstanislav avatar e-terven avatar evgeniyuh avatar evgenq avatar finka759 avatar frotello avatar itimurb avatar kaim-04 avatar mikhail-artemov avatar mirflames avatar morrrun avatar mrbrown969 avatar ripgor avatar tiptopkid avatar vekt0r23 avatar venomy567 avatar

Watchers

 avatar  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.