2023-03-21

Spring Security

 Spring Boot 3 + Spring Security 6 - JWT Authentication and Authorisation [NEW] [2023]

https://www.youtube.com/watch?v=KxqlJblhzfI


Spring Security Tutorial - [NEW] [2023]

https://www.youtube.com/watch?v=b9O9NI-RJ3o&t=1s


Java Tutorial - Complete User Login and Registration Backend + Email Verification

https://www.youtube.com/watch?v=QwQuro7ekvc&list=PLwvrYc43l1MzeA2bBYQhCWr2gvWLs9A7S&index=3


https://www.youtube.com/watch?v=KYNR5js2cXE

Spring Data JPA

PostgreSQL tips: https://www.youtube.com/watch?v=9SGDpanrc8U&t=2273s

Postgres & docker compose https://youtu.be/-mwpoE0x0JQ?t=3943

https://github.com/amigoscode/microservices/blob/main/docker-compose.yml

docker compose up -d

docker compose ps

docker logs postgres -f

postgres https://youtu.be/p485kUNpPvE?list=PLwvrYc43l1Mwqpf9i-1B1gXfMeHOm6DeY&t=2438

https://github.com/amigoscode/spring-boot-fullstack-professional/blob/6-spring-data-jpa/src/main/resources/application.properties

spring.datasource.url=jdbc:postgresql://localhost:5432/amigoscode

spring.datasource.username=postgres

spring.datasource.password=password

spring.jpa.hibernate.ddl-auto=update

spring.jpa.show-sql=true

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

spring.jpa.properties.hibernate.format_sql=true

> docker exec -it postgres bash

psql -U amigoscode

\l  (to list databases)

CREATE DATABASE customer;

CTRL+D

CTRL+D

####

@Id

@SequenceGenerator(

        name = "customer_id_sequence",

        sequenceName = "customer_id_sequence",

        allocationSize = 1

)

@GeneratedValue(

        strategy = GenerationType.SEQUENCE,

        generator = "customer_id_sequence"

)

private Integer id;

##############################

\c customer (connect to db customer)

\dt (list of relations)

\d (list of relations)

\d customer (see table structure)

##########################

Mongo:

Developing with Docker - Docker in Practice || Docker Tutorial 8 https://youtu.be/6YisG2GcXaw?list=PLy7NrYWoggjwPggqtFsI_zMAwvG0SqYCb&t=231

Docker commands: https://gitlab.com/nanuchi/techworld-js-docker-demo-app/-/blob/master/README.md

https://gitlab.com/nanuchi/techworld-js-docker-demo-app/-/blob/master/docker-compose.yaml

https://gitlab.com/nanuchi/techworld-js-docker-demo-app/-/blob/master/Dockerfile

#################################

h2db

spring.h2.console.enabled=true

spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1

spring.datasource.username=sa

spring.datasource.password=

spring.datasource.driver-class-name=org.h2.Driver

spring.jpa.hibernate.ddl-auto=create-drop

spring.jpa.show-sql=true

#spring.jpa.properties.hibernate.format_sql=true


https://youtu.be/5yquJa2x3Ko?t=759 Mapper as Function


2023-03-10

Spring Boot

Create new test: Ctrl +  Shift + t


Security:

 https://amigoscode.com/courses/728126/lectures/13124158

https://www.youtube.com/watch?v=KxqlJblhzfI

https://www.youtube.com/watch?v=b9O9NI-RJ3o

Dan Vega: 

https://www.youtube.com/playlist?list=PLZV0a2jwt22s5NCKOwSmHVagoDW8nflaC


ObjectMapper:

https://fasterxml.github.io/jackson-databind/javadoc/2.7/com/fasterxml/jackson/databind/ObjectMapper.html

https://www.baeldung.com/jackson-object-mapper-tutorial


https://link.springer.com/book/10.1007/978-1-4842-3676-5

Pro Spring Boot 2

An Authoritative Guide to Building Microservices, Web and Enterprise Applications, and Best Practices


@Entity


@PrePersist

void onCreate() {

this.setCreated(LocalDateTime.now());

this.setModified(LocalDateTime.now());

}


@PreUpdate

void onUpdate() {

this.setModified(LocalDateTime.now());

}


# H2-Console: http://localhost:8080/h2-console

# jdbc:h2:mem:testdb

spring.h2.console.enabled=true


<form id="logout" action="/logout" method="POST">

<input type="hidden" name="_csrf" value="{{_csrf.token}}" />

</form>

<script>

$(function(){

$('#logoutLink').click(function(){

$('#logout').submit();

});

});

</script>


JAVA DTO Pattern Tutorial 
https://www.youtube.com/watch?v=5yquJa2x3Ko&t=193s

RuntimeException:
@ResponseStatus(HttpStatus.NOT_FOUND)
public class TestRuntimeException extends RuntimeException{
public TestRuntimeException(String id_not_found) {
}
}
String to JSON: https://github.com/amigoscode/java-streams/blob/main/src/test/java/com/amigoscode/mockdata/MockData.java
public static List<Person> getPeople() throws IOException {
    InputStream inputStream = Resources.getResource("people.json").openStream();
    String json = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
    Type listType = new TypeToken<ArrayList<Person>>() {
    }.getType();
    return new Gson().fromJson(json, listType);
}

spring-data-jpa-course: https://github.com/amigoscode/spring-data-jpa-course/blob/section-7/src/main/resources/application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/amigoscode
spring.datasource.username=
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

server.error.include-message=always
server.error.include-binding-errors=always

spring:
h2.console.enabled: true
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
username: sa
password:
driver-class-name: org.h2.Driver
jpa:
hibernate.ddl-auto: create-drop
show-sql: true
defer-datasource-initialization: true
# properties.hibernate.format_sql: true

postgresql tips: https://youtu.be/9SGDpanrc8U?t=2273

@Bean
CommandLineRunner commandLineRunner() {
return args -> {
System.out.println("Command line runner hooray");
};
}

@Transient means the field is not for DB

Spring Data JPA https://www.youtube.com/watch?v=8SGI_XS5OPw

How To Handle Exceptions 
https://www.youtube.com/watch?v=PzK4ZXa2Tbc
https://www.youtube.com/watch?v=jFZ4lLLkT7M

??? complete course??? https://www.youtube.com/watch?v=8SGI_XS5OPw&list=PLwvrYc43l1MzeA2bBYQhCWr2gvWLs9A7S
fullstack https://www.youtube.com/watch?v=i-hoSg8iRG0&list=PLwvrYc43l1MzeA2bBYQhCWr2gvWLs9A7S&index=4

Spring Security Tutorial - [NEW] [2023] https://www.youtube.com/watch?v=b9O9NI-RJ3o

@Bean
CommandLineRunner commandLineRunner() {
    return args -> {
        System.out.println(Arrays.toString(args));
    };
}

Software Testing Tutorial - Learn Unit Testing and Integration Testing: https://www.youtube.com/watch?v=Geq60OVyBPg
Mockito: https://youtu.be/Geq60OVyBPg?t=2835
@ExtendWith(MockitoExtension.class)
ArgumentCaptor: https://youtu.be/Geq60OVyBPg?t=3506
given(repo.findById(anyInt()),willReturn(true)

Microservices Using Spring Boot and Spring Cloud
https://www.youtube.com/watch?v=p485kUNpPvE&list=PLwvrYc43l1Mwqpf9i-1B1gXfMeHOm6DeY

10 common mistakes:
Constructor Dependency Injection (not setter)
DefaultExceptionHandler https://youtu.be/CT8dbbe783s?t=558