📜 ⬆️ ⬇️

E-Dobavki - Java and Spring Boot food supplement search service, written by my students

Introduction


It so happened that for the last almost two years I have been teaching programming in one of Kiev’s IT schools. I did this Just For Fun. Once I had a programming blog, then I abandoned it. But the desire to tell useful things to interested people has not gone away.


My main language is Java. I wrote mobile games, radio communications software, and various web services on it. And I teach Java.


Here I want to tell the story of learning the last of his group. How they went from the beginning of training to writing a working web service. Useful web service for finding food supplements. Free, no ads, registration and SMS.


The service itself is E-Dobavki.com .



The project is educational, does not contain any advertising. As I understood from this publication , you can provide links to such projects.


Before describing the project itself, tell us a little about the group learning process; without this, the picture will be incomplete.


9 months of study


At the school where I teach, the Java course is divided into 2 parts. In total, the course takes about 9 months, with all the breaks (New Year holidays, time to write intermediate projects).


The first part introduces students to the basic concepts of PL. Variables, methods, basics of OOP and all these things.


The second part of the course assumes that the student already more or less understands how to write in Java, and he can be given an "adult" technology stack. It all starts with SQL, then JDBC, Hibernate. Then HTTP, servlets. Next is Spring, a little about git and maven. And students write final projects.


All training is divided into modules. I conducted classes twice a week. The duration of one lesson is two hours.


My approach to learning


I released 5 groups. It seems like a lot for two years, but I almost always led 2 groups in parallel.


I tried different approaches.


The first option is that one pair stands out for a presentation with theory. The second pair is pure practice. This approach somehow worked, but the effectiveness was not very much, as for me.


The second option, to which I have come and for which I work now, is not to single out a whole pair of theory. Instead, I mix the short segments of the theory for 5-10 minutes, and immediately fix them with practical examples. This approach works better.


If I have enough time, I call students to my place, sit behind my laptop, and they make practical examples themselves. It works great, but unfortunately takes a lot of time.


Not all reach the end


The discovery for me was the fact that not the whole group reaches the end of the course.


According to my observations, only half of the students write the final draft. Most are eliminated in the first part of the course. And those who came to the second part, usually do not fall off.


Leave for various reasons.


The first is complexity. Whatever they say, Java is not the easiest language. To write even the simplest program, it is necessary to understand the concept of a class, a method. And to understand why you need to write public static void main (String [] arg) you need to understand a few more concepts.


Compare this with Turbo Pascal, from which many began, including myself:


begin writeln(" "); end. 

To solve this problem, as far as I know, the school will be the introduction of additional testing. Now not everyone will be able to learn Java. While it is at the concept stage, but the step is clearly the right one.


And the second reason is as in the picture below:



People often think that programming is when they print a lot of text, and get a lot of money for it. As a copywriter, only more money.


The reality is a bit different. A lot of routine code, unobvious bugs, a constant learning process. This is interesting, but not all.


Such statistics. At first it upset me, I thought that maybe I was doing something wrong. Now I understand that about the same statistics on most courses. Now I am not worried about this, but I teach those people who are interested.


Service idea


When the students completed the full course, it’s time to write the final draft. There were different ideas. Offered ToDo sheets, project management projects, something else.


I wanted to do something simple, but useful. My criterion was simple - can I and my friends use it. These requirements are suitable web service search for food additives.


The idea is simple. Buying a product in the store, you see in the composition of some E-shnuyu additive. The code does not understand how dangerous it is or not (and there are also dangerous additives that are prohibited in many countries).


You open the site, type in the name of the additive (number, one of the alternative names), and get a summary of the additive:



There are similar projects. You can also just drive a supplement in Google, although it does not always correctly show the information.


But since the project is educational, the difficulties above did not stop us :)


Implementation


Everyone wrote in Java, the source code of the Github project .


We were 7 people, including me. Everyone made a pull request, and I, or another person from the group, accepted this pull request.


The implementation of the project took about a month - from the voice of the idea to the state that you see now.


Parsing Additives


The first thing that one of the students did, apart from the basic creation of a binding around a database (entities, repositories, etc.), is the parsing of additives from an existing information site.


It was necessary to test the remaining moments. No additional code is needed to populate the database. By quickly sparsing a few additives, you could further test the UI, sorting, and filtering.


Spring Boot allows you to create multiple profiles. A profile is a file with settings.


For the dev environment, we used a profile with a local H2 DBMS and the default HTTP port (8080). Thus, each time the application was launched, the database was cleared. The parser in this case was the thing that saved us.


Search and filtering


An important point is the search and filtering. The person in the store should quickly poke the additive code, or some of the names, and get the result.


Therefore, the entity Additive has several fields. This is the additive code, alternative names, description. Search goes on Like in all fields at the same time. And if you enter [123] or [amaranth], you will get the same result.


Did all this on the basis of specifications (Specification). This is part of Spring, which allows you to describe the basic search conditions (like for some field, for example), and then combine these conditions (OR or AND).


By writing a dozen specifications, you can ask complex queries like "all hazardous dye additives that have the word [red] in the description".


In terms of working with the database Spring seems to me very convenient. This is especially evident in the case of working with complex queries. I understand that this gives its overhead, and a manually written and optimized SQL query will be executed faster.


But I also adhere to the point of view that it is not necessary to optimize everything in advance. The first version should start, work, and allow for the replacement of individual parts. And if the load goes, these separate parts need to be rewritten.


Security


It's simple. There are users with the role of ADMIN - they can edit additives, delete, add new ones.


And there are other users (registered or not). They can only browse the list of additives and search for the necessary ones.


For the separation of rights used by Spring Security. User data is stored in the database.


Users can register. Now it gives nothing. If students continue to develop the service, and introduce some personalized functions, then registration will be useful.


Adaptability and Bootstrap


The next point is adaptability. In the case of our service (at least as we saw it), most users will be with mobile phones. And from the mobile phone you need to quickly see the additive.


In order not to suffer from CSS, they took Bootstrap. Cheap, angry, and looks decent.


I can not call the interface perfect. The main page is even less, and the page of the detailed description of the supplement is narrow; on mobile phones you need to make it wider.


I can only say that I tried to interfere with the work to a minimum. This is still a student project. And of course, the guys will be able to fix these moments later.


Minute SEO optimization


Since I have been busy with websites and everything related to SEO for more than two years, I could not release a project without at least basic SEO optimization.


In fact, I made the template title and description for each supplement. The URL is almost CNC, although it can be made shorter.


I also added attendance counters. Added a site to Yandex Webmaster and Google Search Console to track warnings from search engines.


It is not enough. You also need to add robots.txt and sitemap.xml for full indexing. But again, this is a student project. I will tell them what to do, and if they want to, they will.


You need to attach an SSL certificate. Suit and free Let's Encrypt. I did this for Spring Boot. It is done easily, and the trust of PS increases.


What's next with the project


Further, in fact the choice for the guys. The original idea of ​​the project also included a database of products with binding to additives.


Enter the snickers and see what food supplements it contains.


Even at the start of the project, I knew that we would have no products :) Therefore, we started only with additives.


Now you can fasten the products, introduce additional. buns. If this is an extensive database, users will be found.


Deployment


The project was deployed on a VPS, Aruba Cloud. This is the cheapest VPS we could find. I have been using this provider for more than a year for my projects, and it makes me happy.


VPS characteristics: 1 GB RAM, 1 CPU (for the frequency I do not know), 20 GB SSD. For our project, this is enough with the head.


The project is going to the usual mvn clean package. It turns out fat jar - an executable file with all dependencies.


To automate all this a bit, I wrote a couple of bash scripts.


The first script deletes the old jar file, and builds a new one.


The second script launches the collected jar, passing it the name of the profile you need. This profile contains database connection information.


DB - MySQL on the same VPS.


Total project restart includes:



This procedure takes three minutes. It seems to me a sensible choice for such a small project.


Difficulties


The main difficulties in creating the project were organizational.


There is a group of people who seem to be able to program, but not really. They know something, but they can not really use it yet. And here it is necessary that they make a project in a month.


I singled out a conditional team leader in this group. He led Google dock with a list of tasks, distributed tasks, supervised their adoption. He also received pull requests.


I also asked the students to write a brief report on the work done on the project every evening. Did not do anything - ok, and write "did nothing." This is a great practice that makes you a little tense. Not everyone followed this rule, unfortunately.


The purpose of all this movement was simple. To form a team, albeit for a short time, will work together.


I wanted the guys to have a sense of the importance of their work. Understand that they do not write spherical code in a vacuum. And what are they doing together a project that people will use later?


The first week or two was swinging. Slowly made entities, small commits. Little by little, I still stirred them, and the work went more fun. Chatting became live, students offered their add-ons.


I believe that the goal has been achieved. The project was made, a little teamwork experience was gained. There is a visible tangible result that you can show your friends, you can further develop.


findings


Learning is interesting.


After each pair I came emotionally agitated. I try to make each pair unique and convey the maximum knowledge.


It's nice when the group I teach comes to the finals. Especially cool when the guys write "I got a job, all the rules, thank you." Let it be a junior, if not the biggest money first. But most importantly - they made a step towards their desires, and they did it.


Although the article turned out to be quite voluminous, but of course it did not work out all the moments. Therefore, write in the comments your questions.


')

Source: https://habr.com/ru/post/448422/


All Articles