Skip to content

CodeURJC-DAW-2019-20/PadelVersus

Repository files navigation

PadelVersus

Table of content

Fase 0

Team members

Name Mail Github user
Alejandro Checa Folguera a.checa.2016@alumnos.urjc.es AlexCh98
Iván Martín Sanz i.martins.2016@alumnos.urjc.es i100van
José Luis Lavado Sánchez jl.lavado.2016@alumnos.urjc.es lujoselu98
Lucas Gómez Torres l.gomezt.2016@alumnos.urjc.es LucasGomezTorres
Daniel Carmona Pedrajas d.carmonape@alumnos.urjc.es Dacarpe03

Other tools used

Trello

https://trello.com/b/FH0qaXPJ/daw

Sections description

Entities

Users, teams, tournament, game. Relations:

  • Games are played by teams.
  • Tournament are composed by teams.
  • Teams are composed by users.

Users and permissions

  • Anonymous user:Read permission over rankings, team statistics, game's calendar and other info.
  • Loged user: All permission of Anonymous user. Write pemission over tournament registration to join them. Write permisions over his personal and login data and his team information data.
  • Admin user: Read permission over all website data. Write over all website data (not login data).

Images

Loged users can upload images to their profile. Loged users and Admin can upload photos of the games.

Graphics

Loged users can see user graphics of their statistics they can choose between diferent formats.

Complementary technology

  • Emails sent to the players as a remainder of the game.
  • Login with facebook, twitter or google.
  • API REST from diferent social media used to post info and results about the games.
  • API from GoogleCalendar to be able to show the matches loaded from the database.

Advanced Algorithmic

The webapp will implement ELO ranking system automatically calculated.

Fase 1

Snapshots

Home

This window will show you some matches of the tournament with their dates, and their places. Moreover, will show you the latest matches and the next matches and the main managers. Home

Loggin

Here, you will can log in on the site with your username and your password. Log

SignUp

Here, you will can sign up on the page, with your username, your password and your email. SingUp

Matches

Contains two list. One for the latest matches and another one for the next matches shown in a slider where you can navigate through next days.

SpecificMatch

Contains the score of the match and their Match Statistics. SpecMatch

Teams

Contains a slider where you can navigate between tournaments to see which teams are inscribed in them. Teams

SpecificTeam

A page where the team logo, the team name and its two members are shown. Below this information we find statistics about the team.

SpecTeam

Player/User

This window will show you main features of the players of each team, the last five matches, the club history and the trophies. Moreover, it shows you the minutes played, one summary of the player, detailed player statistics (graphic)and his points per game (graphic).

UserView

Registration Tournament

You will can choose tournament, write your team name and upload team logo. Moreover, you will can write the first name (player1) and the second player will be found for join to first player. RegTournament

Calendar

Contains one calendar with the matches of each month.

Calendar

Flow Diagram

Diagram

Fase 2

Description of the Fase

Implements web app with Spring Boot, moustache for templating, MySQL for data base.

Top 5 Most Important Commits

Name Github user Most Important 2 3 4 5
Alejandro Checa Folguera AlexCh98 Admin Page Sign Up Automatic Email Log In Page Spring Security
Iván Martín Sanz i100van Querys for replace filtrating Port a MySql Loggin with FaceBook OverviewMatches Pageable for Teams
José Luis Lavado Sánchez lujoselu98 Tournaments Tournaments pdf Link player with users Error handling Navbar based on logged user
Lucas Gómez Torres LucasGomezTorres Matches Page Mustache Index Page Mustache Player_Profile Player_Graphics Logic_Player
Daniel Carmona Pedrajas Dacarpe03 Team Service Player Profile Editing Teamx Page Mustache TeamStatistics TeamEntity

Files focused on

Name Github user 1 2 3 4 5
Alejandro Checa Folguera AlexCh98 AdminController.java UserController.java adminPage.html signUp.html/logIn.html SecurityConfiguration.java
Iván Martín Sanz i100van SocialFacebookControler.java MatchStadistics.java overviewMatch.html index.html MatchStadisticsControler.java
José Luis Lavado Sánchez lujoselu98 TournamentService.java ImageService.java tournaments.html registerTournament.html PdfService.java
Lucas Gómez Torres LucasGomezTorres MatchService.java Matches.html index.html PlayerController.java Player.java
Daniel Carmona Pedrajas Dacarpe03 TeamService.java LastMatchDisplay.java teamx.html Team.java AdminController.java

Textual Description Of Work

Name Github user Description
Alejandro Checa Folguera AlexCh98 All the securityof spring boot. The log in and sign up form with their controllers. Email automatic sending when sign up and start spring boot proyect and merging the page in phase 1 with my teammates.
Iván Martín Sanz i100van Normally tasks of use of API, application of templates Mustache, port to mySQL, and html files of matches.
José Luis Lavado Sánchez lujoselu98 Mainly task related with tournaments logic on TournamentService and display on mustache template, also logic to register team into tournament and pdf library to generate tournament ranking exportable pdf. All error handling via html for wellkonwn errors and via @ControllerAdvice for unexpected unhandled errors. Interceptor to generate the navbar links based on logged user. Link the player and user entity on the database at signup.
Lucas Gómez Torres LucasGomezTorres Mainly tasks related to the player entity such as playerController or playerService besides templating html with mustache in files as index.html or player.html, also helped on matches.
Daniel Carmona Pedrajas Dacarpe03 Mainly tasks related to the team entity such as teamController or teamService besides templating html pages with Mustache, also helped on player and admin tasks and a minor SQL query

Steps for making the website:

  1. Create the html template with css, js ...
  2. Create a spring project with maven and web dependencies, devtools, jpa, h2, mustache.
  3. Create in resources a static folder and another of templates.
  4. We put all our css, js, images and static elements that we already had in the static folder.
  5. We put the html in the templates folder because we will use mustache and it is the configuration that it requires.
  6. We will have to change the links to all the css, js from the html because the static address does not work, so we will have to put, for example, /css/library/bootstrap.css
  7. In the application.properties file we add: a. spring.mustache.suffix = .html i. so that mustache understands the .html files. b. spring.h2.console.enabled = true i. For h2 to work.
  8. We tried to make everything work.
  9. To see that the bbdd works, we load localhost: port / h2-console and on the screen that comes out, we will have to leave everything the same changing what is in JDBC URL by jdbc: h2: mem: testdb and should connect and see the administrator of the bbdd. 10 .The project could already be uploaded to github, because it works, even if it doesn't detect the links between html (index load only).

We start with the player class:

  1. We create a controller class and add the request Mapping in the controller to have the url defined.
  2. Later, we create the java class to define the entity (@Entity) in the bbdd, we put the attributes, define the id with @Id and java @GeneratedValue (strategy = GenerationType.IDENTITY) together with all the getters and setters and constructor (empty and with all the parameters minus id)
  3. We create a repository class of the previous entity, for example: a. java public interface PlayerRepository extends JpaRepository <Player, Long>
  4. Next, we create: a. java public Optional <Player> findById (long id) i. This method method in the PlayerRepository, so we can search for the Id from the class.
  5. To initialize the database with sample data we have Application implement ApplicationRunner. We add an @Autowired from each repository and initialize the values in the main method using the save method of the repository.
  6. An example we are talking about is:
     @GetMapping("/{id}")  
     publicStringplayer(Modelmodel, @PathVariableLong id){  
             Optional<Player> player = playerRepository.findById(id);  
             if (player.isPresent()) {  
                 model.addAttribute("name", player.get().getUsername());  
                 return"player";  
             } else {  
                 return"404";  
             }  
     }  

This is what we have done with the rest of the classes to generate our bbdd scheme.

Highlighting the creation of security:

You have to add the security dependency to the pom, and after that, define a class where you set the privileges for the different roles, and the restricted pages based on each role. In addition, to specifying how to log in, and the methods that will manage this, the logout... Finally, it would be necessary to create the keystore (certificate) that is what will accredit the https page, and add in the application properties server.ssl.key-store = classpath: keystore.jks, server.ssl.key-store-password = password and server.ssl.key-password = secret

Once everything is configured, what we will do is create the necessary queries to load our information on the page, which will be done in a java class called repository, and where each sentence will be preceded by @Query, indicating that it is a query, being an example the following:

      @Query (value = 
      "SELECT m. *" + 
      "FROM tournament_matches tm" + 
      "INNER JOIN tournament t ON tm.tournament_id = t.id" + 
      "INNER JOIN games m ON tm.matches_id = m.id" + 
      "WHERE NOT played and t.name =? 1", 
      nativeQuery = true) 
      List <Match> findNotPlayedByTournamentName (String name); 

Later, we will make the change from h2 to mysql, adding the dependency of mysql to the pom and removing the h2, and adding in the application properties the url, username and pass of access to the bbdd. Finally, if you want you can add CSRF to avoid this type of attacks, deleting in the security configuration class the line crsf.disable (); and adding in all html where there is a form the following: . In addition to a CSRF Handler class that handles the configuration. As we said, all this page was done with mustache, html, css, java and javascript, in addition to spring boot and Maven.

New templates

Registration For a Tournament

ResgistationTournament

SignUp Form

SignUp Form

Admin Page

Admin Page

LogOut Page

LogOut Page

Specific Team Page Update

Specific Team Page Update

404 Page

404Error

Comming Soon

ComingSoon

Unexpected Error

UnexpectedError

Navigation

FlowDiagramFase2

Entity Diagram

EntityDiagram

Class/Template Diagram

TemplateDiagram

Demo Structure

  1. Open Index.html and show all in it
  2. Go to matches for consulting info of next matches
  3. Go to teams and show ajax functionality
  4. Go to Ranking and use save PDF
  5. Go to registration tournament
  6. Use sign up functionality and fill all the fields and upload a image
  7. Show email fuctionality.
  8. Log in.
  9. Go again to registration tournament an fill the fields.
  10. Show the ranking of the tournament.
  11. On the ranking select the first teams, to show the graphics.
  12. On the main bar, got to your profile, and change your image.
  13. Log out and log in with the admin password: adminpass
  14. Add a new match with the team we have made before.
  15. Go to matches and show the match have been added.
  16. Return to admin page and fill the data of that match.
  17. Go to the ranking and show the consecuences, thats our advance consulting.
  18. Go to matches and show the match is change from next matches to last matches, and go into the match overview and show that it have the data we have fill.
  19. Then go to the team and show that the statistics have change.

Changes:

Complementary technology

  • API from GoogleCalendar to be able to show the matches loaded from the database has been changed by the generation of a pdf with the data of a tournament.
  • Emails sent to the players as a remainder of the game has been changed by an email sent when user create a new account.
  • Login with facebook, twitter or google changed by a twitter collection in main page.

Advanced Algorithms

The ELO system has been replaced by the calculation of the ranking in each update made by the admin of the games played, and advanced querys to fill the data such as:

   @Query(value = "SELECT m.* " +
            "FROM tournament_matches AS tm " +
            "INNER JOIN tournament t ON tm.tournament_id = t.id " +
            "INNER JOIN(" +
            "SELECT id, date, played, stadistics_1_id, stadistics_2_id " +
            "FROM (" +
            "SELECT t.name as team_name , g.id as match_id, g.* " +
            "FROM games_teams AS gt " +
            "INNER JOIN games g ON gt.match_id = g.id " +
            "INNER JOIN team t ON gt.teams_id = t.id " +
            "WHERE t.name=?1 OR t.name=?2 " +
            "GROUP BY g.id " +
            "HAVING count(g.id)>1 " +
            ") AS joinned_table " +
            ") m ON tm.matches_id = m.id " +
            "WHERE NOT played and t.name = ?3 ",
            nativeQuery = true)
    Optional<Match> findIdByTeamsNameAndTournamentName(String t1, String t2, String tName);

Fase 3

Description of the Fase

Creating API services of our website, and use Docker to launch.

Top 5 Most Important Commits

Name Github user Most Important 2 3 4 5
Alejandro Checa Folguera AlexCh98 NewPlayerApi NewUserApi AdminPageApi StatsMatchApi NewTournamentApi
Iván Martín Sanz i100van MatchApiCompleted APIDocumentation FutureMatches ConcreteMatchAndAllMacthes MatchAPISimplified
José Luis Lavado Sánchez lujoselu98 Tournament Rest Controller Pom and Script for docker ErrorHandling Docker Compose Manage session
Lucas Gómez Torres LucasGomezTorres TournamentRestController PlayerRestController PlayerEntityApi TeamsByPlayerIdRequest AddDiagramTemplate
Daniel Carmona Pedrajas Dacarpe03 TeamRestController PlayerRestController TeamsByPlayerIdRequest PlayerImageEditing TeamStatistics

Files focused on

Name Github user 1 2 3 4 5
Alejandro Checa Folguera AlexCh98 PlayerRestController.java UserRestController.java MatchRestController.java MatchCreate.java RestLoginController.java
Iván Martín Sanz i100van MatchRestControler.java Match.java MatchStatistics.java API.md MatchService.java
José Luis Lavado Sánchez lujoselu98 TournamentRestController.java RestSecurityConfiguration.java ExceptionHandlerControllerApi.java Script.ps1 docker-compose.yml
Lucas Gómez Torres LucasGomezTorres TournamentRestController.java PlayerRestController.java Player.java TeamsRestController.java API.md
Daniel Carmona Pedrajas Dacarpe03 TeamxRestController.java TeamsRestController.java PlayerRestController.java RestSecurityConfiguration.java API.md

Textual Description Of Work

Name Github user Description
Alejandro Checa Folguera AlexCh98 Focus on all put and post api request. Basically the admin page form and the user and player creation
Iván Martín Sanz i100van Focus on all related to matches API for API Rest service of PadelVersus,obtaining all the necessary information of the matches in Postman, document and prepare all related with the readme.md and API.md
José Luis Lavado Sánchez lujoselu98 Focus mainly on Tournament entity api queries. Also part of securing api urls and error handling. Most of the docker deployment logic.
Lucas Gómez Torres LucasGomezTorres As a summary, I have done tasks related to the PlayerApi and TournamentApi, i have worked in PlayerRestController class and tournamentRestController class. Also I contributed on Postman to Player and Tournament Api and I did the diagramTemplate. Finally i helped a little in the TeamApi to get information about TeamsByPlayerIdRequest
Daniel Carmona Pedrajas Dacarpe03 Mainly tasks related to team API, also helped on PlayerRestController to control the image editing of an unauthorized user. Requests on Postman related to team API and player images.

Steps for making the API:

Steps for use Docker:

  1. As we are going to use a network with two dockers that communicate with each other app and database we need a docker network
    docker network create padelVersus-network 
  1. Download and run the mysql:8 docker container
    docker container run --name mysqldb --network padelVersus-network -e MYSQL_ROOT_PASSWORD=123456789 -e MYSQL_DATABASE=padelversus -d     mysql:8

To check that everything went well:

    docker container logs -f mysqldb 

(If everything goes well put Initializaing database ... and more)

    docker container exec -it mysqldb bash

You open a bash console in the mysql base let's see that the schema has been created well

    mysql -uroot -p123456789

show databases; (See that padelversus comes out as schema to exit and then logout)

  1. Go to the intellij and change in the application.properties
    spring.datasource.url=jdbc:mysql://localhost:3306/padelversus?           useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

by

    spring.datasource.url=jdbc:mysql://mysqldb:3306/padelversus?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

and in the pom.xl+

    <properties>
            <java.version>1.8</java.version>
    </properties>

    <properties>
            <java.version>11</java.version>
            <start-class>com.example.padelversus.PadelversusApplication</start-class>
    </properties>

Go to the maven menu and running the install step creates a .jar in target to move it to a folder to organize the docker and rename it topadelverus.jar

  1. Create Dockerfile In the folder where we moved the jar create a file called Dockerfile with From openjdk:11
    copy ./padelversus.jar padelversus.jar
    CMD ["java","-jar","padelversus.jar"]
  1. Mount the new container with from cmd (terminal) in the folder where the Dockerfile and the jar are
    docker image build -t padelversus -f Dockerfile .
  1. Run the container with
    docker container run --network padelVersus-network --name padelversus-container -p 8443:8443 -d padelversus

To see that everything works

    docker container logs -f padelVersus-network

(You have to see the typical start the spring but without colors)

Everything is ready to try, go https: // localhost: 8443 / and see what the page is going

And now why have to deploy Doker Compose:

    version: "3"
services:
  padelversus:
    image: teampina/padelversus:latest
    restart: always
    ports:
      - "8443:8443"
    networks:
      - padelVersus-network
    environment:
      WAIT_HOSTS: mysql:3306
    depends_on:
      - mysqldb
 
  mysqldb:
    image: mysql:8
    restart: on-failure
    healthcheck:
      test: "/usr/bin/mysql --user=root --password=123456789--execute \"SHOW DATABASES;\""
      interval: 2s
      timeout: 20s
      retries: 10
    networks:
      - padelVersus-network
    environment:
      - MYSQL_ROOT_PASSWORD=123456789
      - MYSQL_DATABASE=padelversus  

networks:
  padelVersus-network: 

Now, to prepare the folder with the necessary files to do the docker-compose up, we will use a Power Shell Script with the following commands:

        # Clean and packge using local .m2 repository to do not download already gotten libraries
        docker run -it --rm -v "$(pwd):/usr/src/project" `
                            -v"$HOME/.m2:/root/.m2" `
                            -w /usr/src/project maven:alpine mvn clean package

        # If there is any problem in compilation we move and rename the .jar
        if(Test-Path ./target/padelversus-0.0.1-SNAPSHOT.jar -PathType Leaf){
            Copy-Item -Path ./target/padelversus-0.0.1-SNAPSHOT.jar -Destination ./Docker/PadelVersus.jar -force
        }else{
            echo "Maven compilation fail"
            exit
        }

        # If there is not already moved we copy recursive the folder with images needed for the demo
        if (!(Test-Path ./Docker/DemoImages -PathType Any)){
            Copy-Item -Path ./DemoImages -Destination ./Docker/DemoImages -Recurse
        }else{
            Remove-Item -Recurse -Force ./Docker/DemoImages
            Copy-Item -Path ./DemoImages -Destination ./Docker/DemoImages -Recurse
        }

        # We move into the folder were the .Dockerfile and docker-compose.yml is
        cd Docker

        # We remove the image in case we have done changes in .Dockerfile
        docker rmi teampina/padelversus

        # We build the app image
        docker image build -t teampina/padelversus -f .Dockerfile .

        # We push the image to docker hub
        docker push teampina/padelversus

        # We reutrned to the started directory
        cd ..

API Documentation

In the following link you can find everything related to the PadelVersus Rest API documentation APIDocuments.

You can also see some examples at Postman PadelVersus Colection

And if you want to se documents in postamn format: Postman Documentation

Class/Template Diagram Updated

Fase3_Diagram

Dockerized application execution instructions

To run the application in docker containers, you just have to launch the Power Shell script, this will be responsible for executing the container with maven that is responsible for the construction of the jar, then moves to the Docker folder, and there we create the image, and push to the repository on docker hub. To run the script on Windows standard cmd:

   C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -File <ProjectPath>/Script.ps1

If you wanted to run for other os, install powershell, run pwsh, go to the project path and run the script:

   ./Script.ps1

If you want to get the image:

  docker push teampina/padelversus:latest

To run application (daemon mode of docker):

  docker-compose up -d

To stop the application and remove containers and network (it does not remove the images).

  docker-compose down

Demo Structure

  1. First, show fuctionality of Teams and matches, notice that you dont have to be logged.
  2. Make the pageable request.
  3. Try to register on a tournament.
  4. Notice that you need to be logged.
  5. Create new user.
  6. Register for a tournament.
  7. Request to see tournament info.
  8. Request the player info.
  9. Request the player image.
  10. Try to change the image of another player different from the logged user.
  11. Change the image from logged player
  12. Log out.
  13. Log in as admin (Clean cookies first)
  14. Post request to create new match with the team we have made before.
  15. Request that match to see info
  16. Put request to update match statistics
  17. Get request to se tournament info

Fase 4

Description of the Fase

In this phase, we have to create an angular application connected with the api rest created in the phase 3. The first step is installing node.js, npm and angular cli. With all this correctly installed, we can create a new angular proyect in the IDE you are working on. The next step is creating all the configuration necessary to create each module. Each part is in a folder with a component.ts where is all the logic connected with a componen.html, also a component.css with the style for this html and service.ts where you make the get, post, put or delete request to the API. Finally, you can modify the html template making it more beautiful using ng-material, Bootstrap or primeng. The last step, if you want to upload to Docker. You have to add the node.js container to Docker-compose and in the dockerfile, add the configuration for doing ng-build. With al this steps done, you have an angular application connected with an api, and Working all of this in Docker, with an springboot backend and an independent front with mustache.

Top 5 Most Important Commits

Name Github user Most Important 2 3 4 5
Lucas Gómez Torres LucasGomezTorres FuncionalitiesPlayerPage DesignPlayerPage Upload Images Working Changes Images Working showEmailIfPlayerIsLogged
Ivan Martin Sanz i100van FinishedMatchPage NavBar Footer AllMatches LogicButtons
Daniel Carmona Pedrajas Dacarpe03 TeamPageRemake TeamsPagination ListTeamsPage TeamService PhotosCard
Alejandro Checa Folguera AlexCh98 log in, sign up, sign up player working Admin Page working Sign up player working Sign Up User working Log In working
José Luis Lavado Sánchez lujoselu98 Tournament ranking Home Matches Navigation Error Pages

Files focused on

Name Github user 1 2 3 4 5
Lucas Gómez Torres LucasGomezTorres player.component.ts player.service.ts radar.component.ts images.component.ts player.component.html
Ivan Martin Sanz i100van match.component.ts match.service.ts header.component.ts header.service.ts footer.component.ts
Daniel Carmona Pedrajas Dacarpe03 team.component.ts team.service.ts teamsOfTournament.component.ts linechart.component.ts donutchart.component.ts
Alejandro Checa Folguera AlexCh98 signUp.component.ts signUpPlayer.service.ts admin.component.ts admin.service.ts authentication.service.ts
José Luis Lavado Sánchez lujoselu98 tournament.service.ts tournament-registration.component.ts tournament-ranking.component.ts home.component.ts next-matches-date.component.ts

Textual Description Of Work

Name Github user Description
Lucas Gómez Torres LucasGomezTorres All the funcionalities of the player component and their templates. Also all the funcionalities of the images of the page, uploads images and change images
Ivan Martin Sanz i100van Mainly tasks related to matches, and how to show them. Also header and footer with logic related to the kind of user, in all cases services to the templates of each component
Daniel Carmona Pedrajas Dacarpe03 Mainly tasks related to teams component, from the services to the templates of each component and pagination functionality. Also helped in changing the image of a player
Alejandro Checa Folguera AlexCh98 Mainly all the login, log out, sign up, sign up player tasks. Also all the authentication service logic and all the admin page for adding new match, new stats match...
José Luis Lavado Sánchez lujoselu98 Mainly all home, matches and tournament ranking and registration pages. Also make navigation and error pages (404, 403) and help with style apperance

Prepare Develop Enviroment

1. The first step is installing node.js, npm and angular cli. With all this correctly installed, we can create a new angular proyect in the IDE you are working on. 
2. The next step is creating all the configuration necessary to create each module.
3. Each part is in a folder with a component.ts where is all the logic connected with a componen.html, also a component.css with the style for this html and service.ts where you make the get, post, put or delete request to the API.
4. You can modify the html template making it more beautiful using ng-material, Bootstrap or primeng. The last step, if you want to upload to Docker.
5. ```DOCKER:``` add the node.js container to Docker-compose and in the dockerfile, add the configuration for doing ng-build.
6. Last step, there is an angular application connected with an api, and working all of this in Docker, with an springboot backend and an independent front with mustache.

Class/Templates Diagram

Here we can see the SPA diagram os the angular application.

Fase4_Diagram

Link to youtube

https://youtu.be/4jhL8U50lIA

About

Web Page made with Angular9 in front and API Rest with Spring in back

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors