From 1e7713ef0be9712d0bb079382bf5659f9b19a320 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Fri, 11 Oct 2024 15:37:41 +0200
Subject: [PATCH] OZG-6676 proxy adaption

---
 api/proto/fachstelleregistration.model.proto | 12 ++++--------
 internal/mock/grpc_server.go                 | 16 ++++++++--------
 internal/mock/grpc_server_test.go            |  2 +-
 internal/server/handler_test.go              |  8 ++++----
 internal/server/middleware_test.go           |  6 +++---
 5 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/api/proto/fachstelleregistration.model.proto b/api/proto/fachstelleregistration.model.proto
index 7ade329..928fd72 100644
--- a/api/proto/fachstelleregistration.model.proto
+++ b/api/proto/fachstelleregistration.model.proto
@@ -30,14 +30,6 @@ package de.ozgcloud.fachstellenproxy;
 option go_package = "de.ozgcloud.fachstellenproxy";
 
 message GrpcFachstelleRegistrationRequest {
-  GrpcFachstelle fachstelle = 1;
-}
-
-message GrpcFachstelleRegistrationResponse {
-
-}
-
-message GrpcFachstelle {
   string mukId = 1;
   string firmenName = 2;
   string rechtsform = 3;
@@ -46,4 +38,8 @@ message GrpcFachstelle {
   string registerArt = 6;
   string emailAdresse = 7;
   string anschrift = 8;
+}
+
+message GrpcFachstelleRegistrationResponse {
+
 }
\ No newline at end of file
diff --git a/internal/mock/grpc_server.go b/internal/mock/grpc_server.go
index bb37e17..404336c 100644
--- a/internal/mock/grpc_server.go
+++ b/internal/mock/grpc_server.go
@@ -49,16 +49,16 @@ type registrationServer struct {
 }
 
 func (s *registrationServer) Register(_ context.Context, in *pb.GrpcFachstelleRegistrationRequest) (*pb.GrpcFachstelleRegistrationResponse, error) {
-	if in.Fachstelle == nil {
-		return nil, status.Error(codes.InvalidArgument, "fachstelle is missing")
+	if in.MukId == "" {
+		return nil, status.Error(codes.InvalidArgument, "mukId is missing")
 	}
 
-	if in.Fachstelle.MukId == "conflictMukId" {
-		return nil, status.Error(codes.AlreadyExists, "conflict MukId")
-	} else if in.Fachstelle.MukId == "unavailableMukId" {
-		return nil, status.Error(codes.Unavailable, "unavailable MukId")
-	} else if in.Fachstelle.MukId == "erroneousMukId" {
-		return nil, status.Error(codes.Internal, "erroneous MukId")
+	if in.MukId == "conflictMukId" {
+		return nil, status.Error(codes.AlreadyExists, "conflict mukId")
+	} else if in.MukId == "unavailableMukId" {
+		return nil, status.Error(codes.Unavailable, "unavailable mukId")
+	} else if in.MukId == "erroneousMukId" {
+		return nil, status.Error(codes.Internal, "erroneous mukId")
 	}
 
 	return &pb.GrpcFachstelleRegistrationResponse{}, nil
diff --git a/internal/mock/grpc_server_test.go b/internal/mock/grpc_server_test.go
index b9ab84c..808ca74 100644
--- a/internal/mock/grpc_server_test.go
+++ b/internal/mock/grpc_server_test.go
@@ -67,7 +67,7 @@ func TestStartGrpcServer(t *testing.T) {
 			client, cleanUp := setUpGrpcEnv()
 			defer cleanUp()
 
-			resp, err := client.Register(context.Background(), &pb.GrpcFachstelleRegistrationRequest{Fachstelle: &pb.GrpcFachstelle{MukId: "testMukId"}})
+			resp, err := client.Register(context.Background(), &pb.GrpcFachstelleRegistrationRequest{MukId: "testMukId"})
 
 			assert.NoError(t, err)
 			assert.NotNil(t, resp)
diff --git a/internal/server/handler_test.go b/internal/server/handler_test.go
index 976134a..89f372c 100644
--- a/internal/server/handler_test.go
+++ b/internal/server/handler_test.go
@@ -46,7 +46,7 @@ func TestRegisterFachstelleRegistrationEndpoints(t *testing.T) {
 	mock.SetUpGrpcServer()
 	SetUpHttpGateway()
 
-	jsonData := []byte(`{"fachstelle": {"mukId": "testMukId"}}`)
+	jsonData := []byte(`{"mukId": "testMukId"}`)
 	resp, err := http.Post("http://localhost:8080/api/fachstellen", "application/json", bytes.NewBuffer(jsonData))
 
 	assert.NoError(t, err)
@@ -102,19 +102,19 @@ func TestErrorHandler(t *testing.T) {
 	})
 
 	t.Run("should have conflict error", func(t *testing.T) {
-		jsonData := []byte(`{"fachstelle": {"mukId": "conflictMukId"}}`)
+		jsonData := []byte(`{"mukId": "conflictMukId"}`)
 
 		assertErroneousRequest(jsonData, http.StatusConflict)
 	})
 
 	t.Run("should have unavailable error", func(t *testing.T) {
-		jsonData := []byte(`{"fachstelle": {"mukId": "unavailableMukId"}}`)
+		jsonData := []byte(`{"mukId": "unavailableMukId"}`)
 
 		assertErroneousRequest(jsonData, http.StatusServiceUnavailable)
 	})
 
 	t.Run("should have internal server error", func(t *testing.T) {
-		jsonData := []byte(`{"fachstelle": {"mukId": "erroneousMukId"}}`)
+		jsonData := []byte(`{"mukId": "erroneousMukId"}`)
 
 		assertErroneousRequest(jsonData, http.StatusInternalServerError)
 	})
diff --git a/internal/server/middleware_test.go b/internal/server/middleware_test.go
index 90806e9..d6c48e4 100644
--- a/internal/server/middleware_test.go
+++ b/internal/server/middleware_test.go
@@ -47,12 +47,12 @@ func TestRequestLoggingMiddleware(t *testing.T) {
 			logger.BaseLogger.SetFlags(originalFlags)
 		}()
 
-		jsonData := []byte(`{"fachstelle": {"mukId": "testMukId"}}`)
+		jsonData := []byte(`{"mukId": "testMukId"}`)
 		http.Post("http://localhost:8080/api/fachstellen", "application/json", bytes.NewBuffer(jsonData))
 
 		logOutput := buf.String()
-		assert.Contains(t, logOutput, "received POST request for /api/fachstellen with body: {\"fachstelle\": {\"mukId\": \"testMukId\"}}")
-		assert.Contains(t, logOutput, "successfully handled POST request for /api/fachstellen with body: {\"fachstelle\": {\"mukId\": \"testMukId\"}}")
+		assert.Contains(t, logOutput, "received POST request for /api/fachstellen with body: {\"mukId\": \"testMukId\"}")
+		assert.Contains(t, logOutput, "successfully handled POST request for /api/fachstellen with body: {\"mukId\": \"testMukId\"}")
 	})
 
 	t.Run("should not log request", func(t *testing.T) {
-- 
GitLab