My tasks for coaching
Prequisites:
- installed GitBash
- account on GitHub
Theory:
- what is repository, branch, tags
- succesfull branching model
- Git tutorial
Tasks:
-
Create own repository on github.com with README file
-
Check the ssh public key on github account
-
Clone the repository into the file system
git clone [url]
gitk --all
NOTE: check git settings or run
$ git config --global user.name "John Doe" $ git config --global user.email johndoe@example.com
-
Change the file Readme.md
-
Stash your changes
git stash
git stash pop
-
Commit your changes (local) with
git gui
-
Push your commits to the remote
git push origin master
-
Change the repository of your colleague and push it
-
Change your own repository and commit changes, then try to push it
-
Recovering from conflicts
Prequisites:
- Java JDK 8 installed
- Maven installed
Basic Spring Application:
- Visit page https://start.spring.io/
- Customize your application properties
- Input in box Search for dependencies:
- Web
- JPA
- Actuator
- H2
- Rest Repositories
- Lombok
- Click on Generate Project
- Extract zip into the git repository or folder
- Commit your work
Theory
- Main Application class
- Annotations and Autoconfiguration
- Properties files versus .ymls
- *ApplicationTests class
- Inmemory DBS
- http://localhost:8080
First access to the database:
-
create packeges:
- model
- repositories
- services
-
in model Create class Customer with attributes name, surname, age
-
@Entitie
-
Lombok annotations
-
@Id
@Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id;
-
-
in repositories create CustomerRepository interface, which extends JpaRepository
-
look up methods
List<Customer> findBySurname(String lastName); @Query("SELECT u FROM User u WHERE u.age < 30") List<Customer> findAllUnder30();
-
-
in services create CustomerService class with reference to the repository (Dependency injection)
@Autowired
private CustomerRepository customerRepository;
// @Autowired
// public CustomerService(CustomerRepository customerRepository) {
// this.customerRepository = customerRepository;
// }
public Customer getCustomer(Long id){
Customer one = customerRepository.getOne(id);
//operations on it
return one;
}
public List<Customer> getCustomer(String surname){
List<Customer> bySurname = customerRepository.findBySurname(surname);
if (bySurname.size()==0){
throw new IllegalArgumentException("No Customer with such lastname")
}
return bySurname;
}
-
Lombok and spring Autowiring
@AllArgsConstructor(onConstructor = @__(@Autowired))
-
Test in JUnit
First REST full endpoint:
- Add new package controllers
- Add new class CustomerAPI
- Add endpoint for reaching all customers by surname
- Add Swagger http://localhost:8080/swagger-ui.html#/
Additional tasks:
- Add error handler
- Add Spring Data Rest
- Settings: change a port of the server
- Settings: LOG level