Skip to content

Commit

Permalink
Merge pull request #110 from MichiBaum/develop
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
MichiBaum authored Dec 20, 2024
2 parents cbddfc4 + 18d23ad commit ec2207b
Show file tree
Hide file tree
Showing 97 changed files with 4,050 additions and 3,497 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ on:

jobs:
contrib-readme-job:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
name: Automate contrib in readme
steps:
- name: Contribute List
permissions:
contents: write
pull-requests: write
uses: akhilmhdh/[email protected]
with:
collaborators: all
Expand Down
77 changes: 58 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,56 @@ your project's `pom.xml` files.

#### Up

docker compose up -d
```
docker compose up -d
```

#### Down

docker compose down
```
docker compose down
```

#### Logs

# Follow
docker compose logs -f
```
# Follow
docker compose logs -f
# Single container
docker compose logs ´name´
# Single container
docker compose logs ´name´
```

#### Stats

docker stats
```
docker stats
```

### Docker database backup

Replace 'PASSWORD' with password defined in .env.
Replace path '/data/db-backup' if different location is needed.
```
# Save sql file
docker exec microservices-chess-db-1 mysqldump -u root -pPASSWORD chess > someFilename.sql
# Save gzip
docker exec microservices-chess-db-1 mysqldump -u root -pPASSWORD chess | gzip -c > /data/db-backup/chess_$(date -d "today" +"%Y-%m-%d_%H-%M").sql.gz
# All databases, replace password and save path
docker exec microservices-chess-db-1 mysqldump -u root -pPASSWORD chess | gzip -c > /data/db-backup/chess_$(date -d "today" +"%Y-%m-%d_%H-%M").sql.gz
docker exec microservices-music-db-1 mysqldump -u root -pPASSWORD music | gzip -c > /data/db-backup/music_$(date -d "today" +"%Y-%m-%d_%H-%M").sql.gz
docker exec microservices-fitness-db-1 mysqldump -u root -pPASSWORD fitness | gzip -c > /data/db-backup/fitness_$(date -d "today" +"%Y-%m-%d_%H-%M").sql.gz
docker exec microservices-usermanagement-db-1 mysqldump -u root -pPASSWORD usermanagement | gzip -c > /data/db-backup/usermanagement_$(date -d "today" +"%Y-%m-%d_%H-%M").sql.gz
docker exec microservices-authentication-db-1 mysqldump -u root -pPASSWORD authentication | gzip -c > /data/db-backup/authentication_$(date -d "today" +"%Y-%m-%d_%H-%M").sql.gz
# Add to crontab (escape % with \%)
crontab -e
# List cronjobs
crontab -l
```

### Change HOSTS file (for dev on local machine)
*Remember to take Backup before editing your `hosts` file, mistakes there can block your internet access or cause other network-related issues.*
Expand All @@ -97,16 +130,18 @@ your project's `pom.xml` files.

In *C:\Windows\System32\drivers\etc* find file *hosts* and add those lines:

# Microservices
127.0.0.1 chess.michibaum.ch
127.0.0.1 gateway.michibaum.ch
127.0.0.1 registry.michibaum.ch
127.0.0.1 admin.michibaum.ch
127.0.0.1 usermanagement.michibaum.ch
127.0.0.1 authentication.michibaum.ch
127.0.0.1 fitness.michibaum.ch
127.0.0.1 music.michibaum.ch
127.0.0.1 michibaum.ch
```
# Microservices
127.0.0.1 chess.michibaum.ch
127.0.0.1 gateway.michibaum.ch
127.0.0.1 registry.michibaum.ch
127.0.0.1 admin.michibaum.ch
127.0.0.1 usermanagement.michibaum.ch
127.0.0.1 authentication.michibaum.ch
127.0.0.1 fitness.michibaum.ch
127.0.0.1 music.michibaum.ch
127.0.0.1 michibaum.ch
```

#### Linux

Expand All @@ -115,11 +150,15 @@ File: */etc/hosts*

### Scan docker files

docker scan YourDockerHubUsername/DockerHubRepository:TagName --dependency-tree
```
docker scan YourDockerHubUsername/DockerHubRepository:TagName --dependency-tree
```

## Local dev db

docker run --name microservices -e MARIADB_ROOT_PASSWORD=someRootPass -p 3306:3306 -d mariadb:10.11
```
docker run --name microservices -e MARIADB_ROOT_PASSWORD=someRootPass -p 3306:3306 -d mariadb:10.11
```

After that create the databases in the container.

Expand Down
4 changes: 4 additions & 0 deletions admin-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ server:
shutdown: graceful
undertow:
url-charset: UTF-8
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
min-response-size: 2048

spring:
threads:
Expand Down
4 changes: 4 additions & 0 deletions authentication-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ server:
shutdown: graceful
undertow:
url-charset: UTF-8
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
min-response-size: 2048

spring:
threads:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import java.util.*
interface AccountRepository: JpaRepository<Account, UUID> {
fun findByPlatformAndPlatformIdAndUsername(chessPlatform: ChessPlatform, id: String, username: String): Account?
fun existsByPlatformIdAndUsername(id: String, username: String): Boolean
fun findByPlatformAndUsername(chessPlatform: ChessPlatform, username: String): Account?
fun findByUsernameContainingIgnoreCase(username: String): List<Account>

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class EventController(
eventService.findAll()
.map { eventConverter.toDto(it) }

@GetMapping("/api/events/search")
@Transactional(propagation = Propagation.REQUIRED, readOnly = true, isolation = Isolation.REPEATABLE_READ)
fun searchEvents(@ModelAttribute param: SearchEventDto): List<EventDto> {
return eventService.findAllBy(param.getSpecification(), param.getPageable()).content
.map { eventConverter.toDto(it) }
}

@GetMapping("/api/events/recent-upcoming")
@Transactional(propagation = Propagation.REQUIRED, readOnly = true, isolation = Isolation.REPEATABLE_READ)
fun getAllRecentAndUpcomingEvents(): List<EventDto> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.michibaum.chess_service.app.event

import com.michibaum.chess_service.domain.Event
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import java.time.LocalDate
import java.util.*

interface EventRepository: JpaRepository<Event, UUID> {
interface EventRepository: JpaRepository<Event, UUID>, JpaSpecificationExecutor<Event> {
fun findByDateFromGreaterThanAndDateToLessThan(recent: LocalDate, upcoming: LocalDate): List<Event> // TODO maybe OR????
fun findByCategoriesId(id: UUID): Set<Event>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.michibaum.chess_service.app.person.PersonRepository
import com.michibaum.chess_service.domain.Event
import com.michibaum.chess_service.domain.EventCategory
import com.michibaum.chess_service.domain.Person
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
import org.springframework.data.jpa.domain.Specification
import org.springframework.stereotype.Service
import java.time.LocalDate
import java.util.*
Expand Down Expand Up @@ -74,4 +77,8 @@ class EventService(

fun findByCategoryId(id: UUID): Set<Event> =
eventRepository.findByCategoriesId(id)

fun findAllBy(specification: Specification<Event>, pageable: PageRequest): Page<Event> {
return eventRepository.findAll(specification, pageable)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.michibaum.chess_service.app.event

import com.michibaum.chess_service.domain.Event
import jakarta.persistence.criteria.CriteriaBuilder
import jakarta.persistence.criteria.CriteriaQuery
import jakarta.persistence.criteria.Predicate
import jakarta.persistence.criteria.Root
import org.springframework.data.domain.PageRequest
import org.springframework.data.jpa.domain.Specification

data class SearchEventDto(
val title: String? = null,
val category: String? = null,
val location: String? = null,
val url: Boolean? = null,
val embedUrl: Boolean? = null,
val pageNumber: Int,
val pageSize: Int
){
fun getSpecification(): Specification<Event> =
Specification {
root: Root<Event>, query: CriteriaQuery<*>?, builder: CriteriaBuilder ->
builder.and(*getPredicates(root, builder).toTypedArray())
}

private fun getPredicates(root: Root<Event>, builder: CriteriaBuilder): List<Predicate> {
val specifications = mutableListOf<Predicate>()

if (!title.isNullOrEmpty()) {
specifications.add(builder.like(root.get("title"), title))
}
if (!category.isNullOrEmpty()) {
specifications.add(builder.like(root.get("categories.name"), category))
}
if (!location.isNullOrEmpty()) {
specifications.add(builder.like(root.get("location"), location))
}
// TODO url & embedUrl
return specifications
}

fun getPageable(): PageRequest {
return PageRequest.of(pageNumber, pageSize)
}
}
4 changes: 4 additions & 0 deletions chess-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ server:
shutdown: graceful
undertow:
url-charset: UTF-8
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
min-response-size: 2048

spring:
threads:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
create index person_firstname_index on person (firstname);
create index person_lastname_index on person (lastname);
create index person_firstname_lastname_index on person (lastname, firstname);

create index account_username_index on account (username);
4 changes: 4 additions & 0 deletions fitness-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ server:
shutdown: graceful
undertow:
url-charset: UTF-8
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
min-response-size: 2048

spring:
threads:
Expand Down
4 changes: 4 additions & 0 deletions gateway-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ server:
shutdown: graceful
undertow:
url-charset: UTF-8
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
min-response-size: 2048

spring:
threads:
Expand Down
4 changes: 4 additions & 0 deletions music-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ server:
shutdown: graceful
undertow:
url-charset: UTF-8
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
min-response-size: 2048

spring:
threads:
Expand Down
4 changes: 4 additions & 0 deletions registry-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ server:
undertow:
url-charset: UTF-8
port: 8761
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
min-response-size: 2048

spring:
threads:
Expand Down
4 changes: 4 additions & 0 deletions usermanagement-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ server:
shutdown: graceful
undertow:
url-charset: UTF-8
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
min-response-size: 2048

spring:
threads:
Expand Down
3 changes: 2 additions & 1 deletion website/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"assets": [
"src/manifest.webmanifest",
"src/assets",
"src/robots.txt"
"src/robots.txt",
"src/sitemap.xml"
],
"styles": [
"src/styles.scss",
Expand Down
Loading

0 comments on commit ec2207b

Please sign in to comment.