Our Development Process

This is the document I believe more teams need to write. How to develop a 'trivial' CRUD screen, in this case its the tasks part of our task management app.

This is a demonstration of the process documentation I describe here.

In this document we will be building the entire tasks domain of our app, from database to Java API to React UI to Pull Request and finally Deployment.

I've focused on getting the steps right for now but will be expanding on what we are actually doing in each step in the future.

Prerequisites

Setup Development Tools.

Design

Process determines design because it will create a lot of the constraints the design needs to address. I'll work on this in the future when our process has stabilised.

Development

  1. Checkout our specially made branch without any tasks.

    git checkout no-tasks-do-not-merge
  2. Open glue-stack in VSCode.

  3. Open the terminal using (Control + `).

  4. Follow the steps at Running locally, using the plus button in VSCode's terminal to create a new tab.

  5. Take a look at the app without any tasks.

Database

  1. Open Glue Stack in VSCode.

  2. Start the database by opening a terminal (Control + `) and running:

Task Table

The task table has a Many-To-One relationship to an organisation (just like the user table) and a Many-To-One relationship to a user. That means a task can be associated with a user and a user can have tasks associated with them.

  1. Open sequel pro.

  2. Connect to the docker database.

  3. Click the plus on the bottom left. Name the table task with utf8mb4 encoding.

  4. Add the organisation field.

    The type of this column is going to match the type of the id of the organisation table. To keep things consistent all id columns are the same type.

  5. Add a foreign key.

    A foreign key is a relational database constraint that means a particular field must match another field. In this case we're making sure the organisationId references an existing organisation.

    1. Click the Relations tab.

    2. Click the plus icon.

    3. Click Add.

  6. Click on the Structure tab again.

  7. Click the plus icon in the middle of the page underneath the lone id Field to add a new field.

  8. Add another Field.

  9. Add another Field.

  10. Add a foreign key constraint to the user table for the previous field.

  11. Add another Field.

  12. Add the standard acive, createdDate, modifiedDate fields by running the following queries in the query tab.

  13. We've just created our new table so all we need to do now is add it to the codebase. If we added a few fields we could use the statement console (top right) and copy the relevant statements but this time we created a whole table so we can right click the table and select Copy Create Table Syntax.

  14. Go back to VSCode.

  15. Create a V2__task.sql at `api/src/main/resources/db/migration.

  16. Paste your Create Table Syntax into the file. It should look like this:

  17. Commit your work.

  18. Delete all your tables by selecting them and forcing deletion. This will let Flyway set them up from scratch using the scripts in the migration folder including your new scripts. (TODO: is there a better way?)

  19. Open a new terminal tab.

  20. Run the server.

API

Entity

  1. Create Task.java at `api/src/main/java/org/gluestack/api/domain/entity.

  2. Create the getters and setters.

  3. Stop the API using Control + c in its terminal window.

  4. Start it again (using the up arrow to find the previously run command). This will validate that the entity we created matches the table in the database.

  5. Commit your work.

Repository

  1. Create the TaskRepository.java at `api/src/main/java/org/gluestack/api/repository.

  2. Commit your work.

Service

  1. Create the TaskService.java at `api/src/main/java/org/gluestack/api/service.

    In this case the TaskService wants to return related entities to the user (the user details of the assigned user) so we use hibernate to load those details and the jackson-datatype-hibernate5 module will automatically serialise it (convert to JSON).

  2. Commit your work.

Controller

  1. Create the TaskController.java at `api/src/main/java/org/gluestack/api/controller.

  2. Commit your work.

Tests

Our current test framework means you make it easy to reuse the test data you use in your tests so there is lest time wasted setting up the same data scenarios over and over again.

  1. Open TestOrganisation.java.

  2. Add a Task field called taskAssignedToActingUser.

  3. Open TestOrganisationService.java and populate that test Task at the end of the create method.

  4. Create FindAllTest.java at api/src/test/java/org/gluestack/api/task.

  5. Run mvn test to make sure its all working!

  6. Commit your work.

UI

JavaScript fundamentals before learning React is a good resource to understand Javascript while learning React.

  1. Create a task folder at ui/src/main/authenticated/task.

  2. Create the index.js file inside that folder. This will be the root task page.

  3. Save.

  4. Open authenticated/index.js (Using Command+p then typing auth/ind).

  5. Add the following below the "users" Route in the render function.

  6. Put your cursor at the end of the word <Task, hit Control + Space and select the Task that says auto import (mine was the second option). It should add the following to the top of the file.

  7. Save.

  8. Open sidebar/index.js using the same hotkey and technique as before.

  9. Add the following below the "users" <ListItem in the render function.

  10. Save

  11. You should now be able to click the Tasks item in the side bottom and it should render a page saying "tasks".

  12. Create the task.js file at ui/src/api/.

  13. Create the list component. Create a new file in theui/src/main/authenticated/task/ folder called list.js.

  14. Change the index.js to this:

  15. The tasks page should now be starting to look more like the users page.

  16. Next we will work on Adding a task.

Last updated