diff --git a/deploy/staging/env.yaml b/deploy/staging/env.yaml
new file mode 100644
index 0000000..de9d5f8
--- /dev/null
+++ b/deploy/staging/env.yaml
@@ -0,0 +1,22 @@
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: service-catalog
+ labels:
+ app: service-catalog
+spec:
+ template:
+ spec:
+ containers:
+ - name: service-catalog
+ env:
+ - name: MONGO_USERNAME
+ value: root
+ - name: MONGO_PASSWORD
+ valueFrom:
+ secretKeyRef:
+ name: catalog-mongodb
+ key: ROOT_PASSWORD
+ - name: MONGO_SERVICE
+ value: staging-catalog-mongodb
diff --git a/deploy/staging/kustomization.yaml b/deploy/staging/kustomization.yaml
index ed44016..f978315 100644
--- a/deploy/staging/kustomization.yaml
+++ b/deploy/staging/kustomization.yaml
@@ -5,3 +5,6 @@ namespace: staging
resources:
- ../base
- ingress.yaml
+
+patchesStrategicMerge:
+ - env.yaml
diff --git a/pom.xml b/pom.xml
index bee53d2..8670692 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,6 +35,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-data-mongodb
+
net.logstash.logback
diff --git a/src/main/kotlin/no/digdir/service_catalog/controller/ServiceController.kt b/src/main/kotlin/no/digdir/service_catalog/controller/ServiceController.kt
new file mode 100644
index 0000000..11f51f5
--- /dev/null
+++ b/src/main/kotlin/no/digdir/service_catalog/controller/ServiceController.kt
@@ -0,0 +1,37 @@
+package no.digdir.service_catalog.controller
+
+import no.digdir.service_catalog.model.Service
+import no.digdir.service_catalog.mongodb.ServiceRepository
+import org.springframework.http.HttpHeaders
+import org.springframework.http.HttpStatus
+import org.springframework.http.MediaType
+import org.springframework.http.ResponseEntity
+import org.springframework.stereotype.Controller
+import org.springframework.web.bind.annotation.CrossOrigin
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.PostMapping
+import org.springframework.web.bind.annotation.RequestBody
+import org.springframework.web.bind.annotation.RequestMapping
+
+@Controller
+@CrossOrigin
+@RequestMapping
+class ServiceController(private val serviceRepository: ServiceRepository) {
+
+ @GetMapping(value = ["/services"])
+ fun getAllServices(): ResponseEntity> =
+ ResponseEntity(serviceRepository.findAll(), HttpStatus.OK)
+
+ @PostMapping(value = ["/services"], consumes = [MediaType.APPLICATION_JSON_VALUE])
+ fun createService(
+ @RequestBody service: Service
+ ): ResponseEntity =
+ ResponseEntity(locationHeaderForCreated(serviceRepository.save(service).id),HttpStatus.CREATED)
+
+}
+
+private fun locationHeaderForCreated(newId: String): HttpHeaders =
+ HttpHeaders().apply {
+ add(HttpHeaders.LOCATION, "/services/$newId")
+ add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.LOCATION)
+ }
diff --git a/src/main/kotlin/no/digdir/service_catalog/model/Service.kt b/src/main/kotlin/no/digdir/service_catalog/model/Service.kt
new file mode 100644
index 0000000..f7cc458
--- /dev/null
+++ b/src/main/kotlin/no/digdir/service_catalog/model/Service.kt
@@ -0,0 +1,9 @@
+package no.digdir.service_catalog.model
+
+import org.springframework.data.mongodb.core.mapping.Document
+
+@Document(collection = "services")
+data class Service (
+ val id: String,
+ val title: String
+)
diff --git a/src/main/kotlin/no/digdir/service_catalog/mongodb/ServiceRepository.kt b/src/main/kotlin/no/digdir/service_catalog/mongodb/ServiceRepository.kt
new file mode 100644
index 0000000..52f4820
--- /dev/null
+++ b/src/main/kotlin/no/digdir/service_catalog/mongodb/ServiceRepository.kt
@@ -0,0 +1,8 @@
+package no.digdir.service_catalog.mongodb
+
+import no.digdir.service_catalog.model.Service
+import org.springframework.data.mongodb.repository.MongoRepository
+import org.springframework.stereotype.Repository
+
+@Repository
+interface ServiceRepository : MongoRepository
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index cc45d99..8eb35d2 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -9,4 +9,5 @@ management:
endpoint.health.probes.enabled: true
health:
livenessState.enabled: true
- readinessState.enabled: true
\ No newline at end of file
+ readinessState.enabled: true
+spring.data.mongodb.uri: mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_SERVICE}:27017/serviceCatalog?authSource=admin&authMechanism=SCRAM-SHA-1