Last active
September 16, 2022 01:57
-
-
Save fwfurtado/28e5b57285f6db349e0eff15f0a97623 to your computer and use it in GitHub Desktop.
postgres docker compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
micronaut: | |
application: | |
name: demo | |
datasources: | |
default: | |
url: jdbc:postgresql://localhost:5432/demo | |
username: postgres | |
password: postgres | |
dialect: POSTGRES | |
driverClassName: org.postgresql.Driver | |
jpa.default.properties.hibernate.hbm2ddl.auto: update | |
netty: | |
default: | |
allocator: | |
max-order: 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"info": { | |
"_postman_id": "39f2afad-8af6-40d3-bdeb-f50e1d50f577", | |
"name": "Demo", | |
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" | |
}, | |
"item": [ | |
{ | |
"name": "List People", | |
"request": { | |
"method": "GET", | |
"header": [], | |
"url": "http://localhost:8080/people" | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Find Person", | |
"request": { | |
"method": "GET", | |
"header": [], | |
"url": "http://localhost:8080/people/1" | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Save Person", | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\n \"name\": \"Eiji\"\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": "http://localhost:8080/people" | |
}, | |
"response": [] | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.7" | |
services: | |
database: | |
image: postgres | |
environment: | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_USER: postgres | |
POSTGRES_DB: demo | |
volumes: | |
- database:/var/lib/postgresql/data | |
ports: | |
- "5432:5432" | |
volumes: | |
database: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example | |
import io.micronaut.http.annotation.Controller | |
import io.micronaut.http.annotation.Get | |
import io.micronaut.http.annotation.Post | |
import java.lang.IllegalArgumentException | |
@Controller("/people") | |
class PersonController( | |
private val repository: PersonRepository | |
) { | |
@Get | |
fun list(): List<PersonEntity> { | |
return repository.findAll() | |
} | |
@Get("{id}") | |
fun get(id: Long): PersonEntity { | |
return repository.findById(id) ?: throw NotFoundException() | |
} | |
@Post | |
fun create(person: PersonEntity): PersonEntity { | |
return repository.save(person) | |
} | |
} | |
class NotFoundException : IllegalArgumentException() { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example | |
import javax.persistence.Entity | |
import javax.persistence.GeneratedValue | |
import javax.persistence.Id | |
@Entity | |
class PersonEntity { | |
@Id | |
@GeneratedValue | |
var id: Long = 0L | |
var name: String = "" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example | |
import io.micronaut.data.annotation.Repository | |
import io.micronaut.data.repository.GenericRepository | |
@Repository | |
interface PersonRepository : GenericRepository<PersonEntity, Long> { | |
fun findAll(): List<PersonEntity> | |
fun findById(id: Long): PersonEntity? | |
fun save(person: PersonEntity): PersonEntity | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment