From 2015977797df7b649a9954cad0d4f9230cec4df5 Mon Sep 17 00:00:00 2001 From: TohaVoice Date: Thu, 13 Apr 2023 04:00:26 +0400 Subject: [PATCH] Added HealthController, helm templates, Makefile, postman collection, changed credentials, refactored code, changed readme file #7 --- hw03-crud/Makefile | 23 +++ hw03-crud/README.md | 20 +++ hw03-crud/docker/docker-compose.yaml | 18 +- hw03-crud/helm/chart/Chart.yaml | 6 + hw03-crud/helm/chart/templates/_helpers.tpl | 62 +++++++ .../helm/chart/templates/app_configmap.yaml | 9 + .../helm/chart/templates/app_deployment.yaml | 29 ++++ .../helm/chart/templates/app_ingress.yaml | 38 +++++ .../helm/chart/templates/app_secret.yaml | 9 + .../helm/chart/templates/app_service.yaml | 15 ++ .../chart/templates/postgres_configmap.yaml | 8 + .../helm/chart/templates/postgres_secret.yaml | 9 + .../chart/templates/postgres_service.yaml | 11 ++ .../chart/templates/postgres_statefulset.yaml | 36 ++++ hw03-crud/helm/chart/values.yaml | 21 +++ hw03-crud/helm/deploy.sh | 5 + hw03-crud/helm/remove.sh | 4 + hw03-crud/postman/crud_collection.json | 157 ++++++++++++++++++ .../ru/otus/shatokhin/UserApplication.java | 17 -- .../otus/shatokhin/config/DbProperties.java | 17 +- .../controller/HealthController.java | 19 +++ .../shatokhin/controller/UserController.java | 6 +- 22 files changed, 507 insertions(+), 32 deletions(-) create mode 100644 hw03-crud/Makefile create mode 100644 hw03-crud/helm/chart/Chart.yaml create mode 100644 hw03-crud/helm/chart/templates/_helpers.tpl create mode 100644 hw03-crud/helm/chart/templates/app_configmap.yaml create mode 100644 hw03-crud/helm/chart/templates/app_deployment.yaml create mode 100644 hw03-crud/helm/chart/templates/app_ingress.yaml create mode 100644 hw03-crud/helm/chart/templates/app_secret.yaml create mode 100644 hw03-crud/helm/chart/templates/app_service.yaml create mode 100644 hw03-crud/helm/chart/templates/postgres_configmap.yaml create mode 100644 hw03-crud/helm/chart/templates/postgres_secret.yaml create mode 100644 hw03-crud/helm/chart/templates/postgres_service.yaml create mode 100644 hw03-crud/helm/chart/templates/postgres_statefulset.yaml create mode 100644 hw03-crud/helm/chart/values.yaml create mode 100644 hw03-crud/helm/deploy.sh create mode 100644 hw03-crud/helm/remove.sh create mode 100644 hw03-crud/postman/crud_collection.json create mode 100644 hw03-crud/src/main/java/ru/otus/shatokhin/controller/HealthController.java diff --git a/hw03-crud/Makefile b/hw03-crud/Makefile new file mode 100644 index 0000000..2fa6556 --- /dev/null +++ b/hw03-crud/Makefile @@ -0,0 +1,23 @@ +docker-build: + docker build -f docker/Dockerfile . -t avshatokhin/msa:hw03-crud + +docker-push: + docker push avshatokhin/msa:hw03-crud + +docker-start: + cd docker && docker-compose up -d + +docker-stop: + cd docker && docker-compose down + +k8s-deploy-sh: + helm/deploy.sh + +k8s-remove-sh: + helm/remove.sh + +k8s-deploy: + kubectl create ns otus && helm install nginx --namespace otus nginx-stable/nginx-ingress --set controller.service.httpPort.port=80 --set controller.enableSnippets=True && helm upgrade --install -n otus hw03-crud helm/chart + +k8s-remove: + helm uninstall -n otus nginx && kubectl delete ns otus diff --git a/hw03-crud/README.md b/hw03-crud/README.md index ee7a0e4..d95a6d2 100644 --- a/hw03-crud/README.md +++ b/hw03-crud/README.md @@ -1,3 +1,23 @@ +### Установка + +Все деплоится в namespace otus, если данный namespace был в системе, то сначала запустить make k8s-remove-sh команду.
+Если никаких рудиментов нет, запускаем как на примере ниже +``` +1. make k8s-deploy-sh +2. make k8s-remove-sh +``` +В случае когда sh файлы не отрабатывают (Windows или что то не настроено), запускаем пример как указано ниже.
+Однако в данном случае нужно будет следить чтобы вся цепочка команд выполнилась без ошибок +``` +1. make k8s-deploy +2. make k8s-remove +``` + +Шаблонизация в папке +``` + helm/chart +``` + ### Домашнее задание Инфраструктурные паттерны diff --git a/hw03-crud/docker/docker-compose.yaml b/hw03-crud/docker/docker-compose.yaml index ffa2056..9fb608d 100644 --- a/hw03-crud/docker/docker-compose.yaml +++ b/hw03-crud/docker/docker-compose.yaml @@ -4,15 +4,13 @@ services: container_name: postgres-sql image: postgres:15.2-alpine restart: always -# ports: -# - 5434:5434 networks: - hw03-crud environment: POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256 - POSTGRES_USER: sa - POSTGRES_DB: test - POSTGRES_PASSWORD: example + POSTGRES_USER: ashatokhin + POSTGRES_DB: msaDb + POSTGRES_PASSWORD: root TZ: Europe/Samara app: container_name: crud-app @@ -25,13 +23,11 @@ services: environment: HTTP_PORT: 8000 APP_LOG_LEVEL: ERROR - DB_HOST: jdbc:postgresql://db/test - DB_USER: sa - DB_PASSWORD: example + DB_HOST: jdbc:postgresql://db/msaDb + DB_USER: ashatokhin + DB_PASSWORD: root depends_on: - db networks: - hw03-crud: - -# jdbc:postgresql://postgres:5432/postgresdb \ No newline at end of file + hw03-crud: \ No newline at end of file diff --git a/hw03-crud/helm/chart/Chart.yaml b/hw03-crud/helm/chart/Chart.yaml new file mode 100644 index 0000000..7b798d0 --- /dev/null +++ b/hw03-crud/helm/chart/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: app-chart +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: v1 diff --git a/hw03-crud/helm/chart/templates/_helpers.tpl b/hw03-crud/helm/chart/templates/_helpers.tpl new file mode 100644 index 0000000..3714881 --- /dev/null +++ b/hw03-crud/helm/chart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "hw03-crud.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "hw03-crud.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "hw03-crud.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "hw03-crud.labels" -}} +helm.sh/chart: {{ include "hw03-crud.chart" . }} +{{ include "hw03-crud.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "hw03-crud.selectorLabels" -}} +app.kubernetes.io/name: {{ include "hw03-crud.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "hw03-crud.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "hw03-crud.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/hw03-crud/helm/chart/templates/app_configmap.yaml b/hw03-crud/helm/chart/templates/app_configmap.yaml new file mode 100644 index 0000000..b8b8ab1 --- /dev/null +++ b/hw03-crud/helm/chart/templates/app_configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: app-config +data: + DB_HOST: "jdbc:postgresql://postgres-db/msaDb" + HTTP_PORT: "8000" + APP_LOG_LEVEL: "ERROR" + DB_USER: "ashatokhin" diff --git a/hw03-crud/helm/chart/templates/app_deployment.yaml b/hw03-crud/helm/chart/templates/app_deployment.yaml new file mode 100644 index 0000000..f2e26dc --- /dev/null +++ b/hw03-crud/helm/chart/templates/app_deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "hw03-crud.fullname" . }} + labels: + {{- include "hw03-crud.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "hw03-crud.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "hw03-crud.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + envFrom: + - configMapRef: + name: app-config + - secretRef: + name: app-secrets diff --git a/hw03-crud/helm/chart/templates/app_ingress.yaml b/hw03-crud/helm/chart/templates/app_ingress.yaml new file mode 100644 index 0000000..8fad21c --- /dev/null +++ b/hw03-crud/helm/chart/templates/app_ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "hw03-crud.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "hw03-crud.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + ingressClassName: {{ .Values.ingress.className }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + {{- end }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/hw03-crud/helm/chart/templates/app_secret.yaml b/hw03-crud/helm/chart/templates/app_secret.yaml new file mode 100644 index 0000000..851c849 --- /dev/null +++ b/hw03-crud/helm/chart/templates/app_secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +type: Opaque +metadata: + name: app-secrets + labels: + name: hw03-crud +data: + DB_PASSWORD: cm9vdA== diff --git a/hw03-crud/helm/chart/templates/app_service.yaml b/hw03-crud/helm/chart/templates/app_service.yaml new file mode 100644 index 0000000..8d96001 --- /dev/null +++ b/hw03-crud/helm/chart/templates/app_service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "hw03-crud.fullname" . }} + labels: + {{- include "hw03-crud.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.targetPort }} + protocol: TCP + name: http + selector: + {{- include "hw03-crud.selectorLabels" . | nindent 4 }} diff --git a/hw03-crud/helm/chart/templates/postgres_configmap.yaml b/hw03-crud/helm/chart/templates/postgres_configmap.yaml new file mode 100644 index 0000000..d85ba23 --- /dev/null +++ b/hw03-crud/helm/chart/templates/postgres_configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-config +data: + POSTGRES_USER: "ashatokhin" + POSTGRES_DB: "msaDb" + PGDATA: "/data/pgdata" diff --git a/hw03-crud/helm/chart/templates/postgres_secret.yaml b/hw03-crud/helm/chart/templates/postgres_secret.yaml new file mode 100644 index 0000000..a3c27b8 --- /dev/null +++ b/hw03-crud/helm/chart/templates/postgres_secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +type: Opaque +metadata: + name: postgres-secrets + labels: + name: hw03-crud +data: + POSTGRES_PASSWORD: cm9vdA== diff --git a/hw03-crud/helm/chart/templates/postgres_service.yaml b/hw03-crud/helm/chart/templates/postgres_service.yaml new file mode 100644 index 0000000..3d33659 --- /dev/null +++ b/hw03-crud/helm/chart/templates/postgres_service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgres-db +spec: + selector: + app: postgresql-db + type: LoadBalancer + ports: + - port: 5432 + targetPort: 5432 diff --git a/hw03-crud/helm/chart/templates/postgres_statefulset.yaml b/hw03-crud/helm/chart/templates/postgres_statefulset.yaml new file mode 100644 index 0000000..7814985 --- /dev/null +++ b/hw03-crud/helm/chart/templates/postgres_statefulset.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: StatefulSet + +metadata: + name: postgresql-db + +spec: + serviceName: postgresql-db-service + selector: + matchLabels: + app: postgresql-db + replicas: 1 + template: + metadata: + labels: + app: postgresql-db + spec: + containers: + - name: postgresql-db + image: postgres:15.2-alpine + volumeMounts: + - name: postgresql-db-disk + mountPath: /data + envFrom: + - configMapRef: + name: postgres-config + - secretRef: + name: postgres-secrets + volumeClaimTemplates: + - metadata: + name: postgresql-db-disk + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/hw03-crud/helm/chart/values.yaml b/hw03-crud/helm/chart/values.yaml new file mode 100644 index 0000000..05cf734 --- /dev/null +++ b/hw03-crud/helm/chart/values.yaml @@ -0,0 +1,21 @@ +replicaCount: 1 + +image: + repository: avshatokhin/msa + pullPolicy: IfNotPresent + tag: hw03-crud + +service: + type: NodePort + port: 80 + targetPort: 8000 + +ingress: + enabled: true + className: nginx + annotations: {} + hosts: + - host: arch.homework + paths: + - path: / + pathType: Prefix diff --git a/hw03-crud/helm/deploy.sh b/hw03-crud/helm/deploy.sh new file mode 100644 index 0000000..d5f3d58 --- /dev/null +++ b/hw03-crud/helm/deploy.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +kubectl create ns otus +helm install nginx --namespace otus nginx-stable/nginx-ingress --set controller.service.httpPort.port=80 --set controller.enableSnippets=True +helm upgrade --install -n otus hw03-crud chart \ No newline at end of file diff --git a/hw03-crud/helm/remove.sh b/hw03-crud/helm/remove.sh new file mode 100644 index 0000000..9d5feb9 --- /dev/null +++ b/hw03-crud/helm/remove.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +helm uninstall -n otus nginx +kubectl delete ns otus \ No newline at end of file diff --git a/hw03-crud/postman/crud_collection.json b/hw03-crud/postman/crud_collection.json new file mode 100644 index 0000000..650d487 --- /dev/null +++ b/hw03-crud/postman/crud_collection.json @@ -0,0 +1,157 @@ +{ + "info": { + "_postman_id": "ac599381-f709-47f5-96ac-fed11557b057", + "name": "crud_collection", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "26774686" + }, + "item": [ + { + "name": "healthCheck", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://arch.homework/api/v1/health", + "protocol": "http", + "host": [ + "arch", + "homework" + ], + "path": [ + "api", + "v1", + "health" + ] + } + }, + "response": [] + }, + { + "name": "getAllUsers", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://arch.homework/api/v1/users", + "protocol": "http", + "host": [ + "arch", + "homework" + ], + "path": [ + "api", + "v1", + "users" + ] + } + }, + "response": [] + }, + { + "name": "createUser", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"userName\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"email\": \"bestjohn@doe.com\",\n \"phone\": \"+71002003040\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://arch.homework/api/v1/user", + "protocol": "http", + "host": [ + "arch", + "homework" + ], + "path": [ + "api", + "v1", + "user" + ] + } + }, + "response": [] + }, + { + "name": "updateUser", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"userName\": \"newName\",\n \"firstName\": \"newFirstName\",\n \"lastName\": \"newLastName\",\n \"email\": \"pavlov@gmail.com\",\n \"phone\": \"+79001234005\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://arch.homework/api/v1/user/5", + "protocol": "http", + "host": [ + "arch", + "homework" + ], + "path": [ + "api", + "v1", + "user", + "5" + ] + } + }, + "response": [] + }, + { + "name": "deleteUser", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "http://arch.homework/api/v1/user/4", + "protocol": "http", + "host": [ + "arch", + "homework" + ], + "path": [ + "api", + "v1", + "user", + "4" + ] + } + }, + "response": [] + }, + { + "name": "findUserById", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://arch.homework/api/v1/user/3", + "protocol": "http", + "host": [ + "arch", + "homework" + ], + "path": [ + "api", + "v1", + "user", + "3" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/hw03-crud/src/main/java/ru/otus/shatokhin/UserApplication.java b/hw03-crud/src/main/java/ru/otus/shatokhin/UserApplication.java index f4ec384..9261c45 100644 --- a/hw03-crud/src/main/java/ru/otus/shatokhin/UserApplication.java +++ b/hw03-crud/src/main/java/ru/otus/shatokhin/UserApplication.java @@ -1,29 +1,12 @@ package ru.otus.shatokhin; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.RequestMapping; @SpringBootApplication -@RequestMapping("${web.root}") public class UserApplication { - @Value("${spring.datasource.url}") - private static String dbUrl; - - @Value("${spring.datasource.password}") - private static String dbPassword; - - @Value("${spring.datasource.username}") - private static String dbUser; - public static void main(String[] args) { - System.out.println("CRUD application starting...\n\n" - + "DB_URL=" + dbUrl + "\n" - + "DB_PASSWORD=" + dbPassword + "\n" - + "DB_USER_NAME=" + dbUser + "\n"); - SpringApplication.run(UserApplication.class, args); } diff --git a/hw03-crud/src/main/java/ru/otus/shatokhin/config/DbProperties.java b/hw03-crud/src/main/java/ru/otus/shatokhin/config/DbProperties.java index ff634a5..e0d8b67 100644 --- a/hw03-crud/src/main/java/ru/otus/shatokhin/config/DbProperties.java +++ b/hw03-crud/src/main/java/ru/otus/shatokhin/config/DbProperties.java @@ -1,13 +1,18 @@ package ru.otus.shatokhin.config; import jakarta.annotation.PostConstruct; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.context.properties.ConfigurationProperties; +import ru.otus.shatokhin.UserApplication; import java.util.StringJoiner; @ConfigurationProperties(prefix = "spring.datasource") public class DbProperties { + private static final Logger LOGGER = LoggerFactory.getLogger(DbProperties.class); + private static final String ERROR_MSG_PATTERN = "Environment variable %s is empty. Please set it"; private String username; private String password; @@ -15,7 +20,7 @@ public class DbProperties { @PostConstruct public void printInit() { -// log.info(toString()); + LOGGER.info(toString()); StringJoiner errors = new StringJoiner(", "); if (url.equals("${DB_HOST}")) { errors.add("DB_HOST"); @@ -29,6 +34,7 @@ public void printInit() { if (errors.length() > 0) { throw new IllegalArgumentException(String.format(ERROR_MSG_PATTERN, errors)); } + } public String getUsername() { @@ -54,4 +60,13 @@ public String getUrl() { public void setUrl(String url) { this.url = url; } + + @Override + public String toString() { + return "DbProperties{" + + "username='" + username + '\'' + + ", password='" + password + '\'' + + ", url='" + url + '\'' + + '}'; + } } diff --git a/hw03-crud/src/main/java/ru/otus/shatokhin/controller/HealthController.java b/hw03-crud/src/main/java/ru/otus/shatokhin/controller/HealthController.java new file mode 100644 index 0000000..4a8bb6c --- /dev/null +++ b/hw03-crud/src/main/java/ru/otus/shatokhin/controller/HealthController.java @@ -0,0 +1,19 @@ +package ru.otus.shatokhin.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("${web.root}") +public class HealthController { + + @GetMapping(value = "/health", produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseStatus(HttpStatus.OK) + public String healthCheck() { + return "{\"status\": \"OK\"}"; + } +} \ No newline at end of file diff --git a/hw03-crud/src/main/java/ru/otus/shatokhin/controller/UserController.java b/hw03-crud/src/main/java/ru/otus/shatokhin/controller/UserController.java index 57d8c5f..6b87006 100644 --- a/hw03-crud/src/main/java/ru/otus/shatokhin/controller/UserController.java +++ b/hw03-crud/src/main/java/ru/otus/shatokhin/controller/UserController.java @@ -10,7 +10,7 @@ import java.util.List; @RestController -//@RequestMapping("${web.root}") +@RequestMapping("${web.root}") public class UserController { @Autowired @@ -42,8 +42,8 @@ private void deleteUserById(@PathVariable("id") Long userId) { @PutMapping("/user/{id}") @ResponseStatus(HttpStatus.OK) - private void updateUser(@PathVariable("id") Long userId, @RequestBody User user) throws UserNotFoundException { - userService.updateUser(userId, user); + private User updateUser(@PathVariable("id") Long userId, @RequestBody User user) throws UserNotFoundException { + return userService.updateUser(userId, user); } }