From 4e0ea115929acef1ba15d4a2f90786db9629cfb3 Mon Sep 17 00:00:00 2001
From: Miika Hyttinen <miika@three.consulting>
Date: Fri, 14 Oct 2022 15:47:50 +0300
Subject: [PATCH] change post timesheet entry endpoint to take an array of
 entries

---
 .../controller/TimesheetEntryController.kt    |  7 +-
 ...TimesheetEntryControllerIntegrationTest.kt |  8 +--
 .../timesheetEntry/validCreation.json         | 70 -------------------
 3 files changed, 2 insertions(+), 83 deletions(-)
 delete mode 100644 src/test/resources/timesheetEntry/validCreation.json

diff --git a/src/main/kotlin/three/consulting/epoc/controller/TimesheetEntryController.kt b/src/main/kotlin/three/consulting/epoc/controller/TimesheetEntryController.kt
index e753f84d..c85304d1 100644
--- a/src/main/kotlin/three/consulting/epoc/controller/TimesheetEntryController.kt
+++ b/src/main/kotlin/three/consulting/epoc/controller/TimesheetEntryController.kt
@@ -39,13 +39,8 @@ class TimesheetEntryController(private val timesheetEntryService: TimesheetEntry
         response.writer.print(csvString)
     }
 
-    @PreAuthorize("hasAuthority('ADMIN') or #timesheetEntry.timesheet.employee.email == authentication.principal.getClaim(\"email\")")
-    @PostMapping(value = ["/timesheet-entry"], consumes = [APPLICATION_JSON_VALUE], produces = [APPLICATION_JSON_VALUE])
-    fun createTimesheetEntry(@Valid @RequestBody timesheetEntry: TimesheetEntryDTO) =
-        timesheetEntryService.createTimesheetEntry(timesheetEntry)
-
     @PreAuthorize("hasAuthority('ADMIN') or #timesheetEntryService.hasValidEmails(timesheetEntries, authentication.principal.getClaim(\"email\"))")
-    @PostMapping(value = ["/timesheet-entries"], consumes = [APPLICATION_JSON_VALUE], produces = [APPLICATION_JSON_VALUE])
+    @PostMapping(value = ["/timesheet-entry"], consumes = [APPLICATION_JSON_VALUE], produces = [APPLICATION_JSON_VALUE])
     fun createTimesheetEntries(@Valid @RequestBody timesheetEntries: List<TimesheetEntryDTO>) =
         timesheetEntryService.createTimesheetEntries(timesheetEntries)
 
diff --git a/src/test/kotlin/three/consulting/epoc/controller/TimesheetEntryControllerIntegrationTest.kt b/src/test/kotlin/three/consulting/epoc/controller/TimesheetEntryControllerIntegrationTest.kt
index 93c58af2..e2d30cb1 100644
--- a/src/test/kotlin/three/consulting/epoc/controller/TimesheetEntryControllerIntegrationTest.kt
+++ b/src/test/kotlin/three/consulting/epoc/controller/TimesheetEntryControllerIntegrationTest.kt
@@ -17,16 +17,10 @@ class TimesheetEntryControllerIntegrationTest : ControllerIntegrationTest() {
         assertThat(response.statusCode).isEqualTo(HttpStatus.OK)
     }
 
-    @Test
-    fun `add timesheetEntry returns 200`() {
-        val httpEntity = jsonPostEntity("timesheetEntry/validCreation.json")
-        val response = restTemplate.postForEntity("/timesheet-entry", httpEntity, ObjectNode::class.java)
-        assertThat(response.statusCode).isEqualTo(HttpStatus.OK)
-    }
     @Test
     fun `add timesheetEntries returns 200`() {
         val httpEntity = jsonPostEntity("timesheetEntry/validCreateMany.json")
-        val response = restTemplate.postForEntity("/timesheet-entries", httpEntity, ArrayNode::class.java)
+        val response = restTemplate.postForEntity("/timesheet-entry", httpEntity, ArrayNode::class.java)
         assertThat(response.statusCode).isEqualTo(HttpStatus.OK)
     }
 
diff --git a/src/test/resources/timesheetEntry/validCreation.json b/src/test/resources/timesheetEntry/validCreation.json
deleted file mode 100644
index 21f8a668..00000000
--- a/src/test/resources/timesheetEntry/validCreation.json
+++ /dev/null
@@ -1,70 +0,0 @@
-{
-  "quantity": 7.5,
-  "date": "2021-09-24",
-  "description": "Testing time category",
-  "timesheet": {
-    "id": 1,
-    "name": "Entry sheet",
-    "description": "testing",
-    "rate": 100.0,
-    "allocation": 100,
-    "project": {
-      "id": 1,
-      "name": "Entry project",
-      "description": "testing",
-      "startDate": "2021-09-24",
-      "customer": {
-        "id": 1,
-        "name": "Maurin Makkara Oy",
-        "description": "Get the pile"
-      },
-      "managingEmployee": {
-        "id": 1,
-        "firstName": "Testi",
-        "lastName": "Tekijä",
-        "email": "testi@tekija.fi",
-        "startDate": "2021-09-24",
-        "role": "USER"
-      },
-      "status": "ACTIVE"
-    },
-    "employee": {
-      "id": 1,
-      "firstName": "test",
-      "lastName": "maker",
-      "email": "test@maker.fi",
-      "startDate": "2021-09-24",
-      "role": "USER"
-    }
-  },
-  "timeCategory": {
-    "id": 1,
-    "name": "Test work"
-  },
-  "task": {
-    "id": 1,
-    "name": "test",
-    "description": "testing",
-    "startDate": "2021-09-24",
-    "project": {
-      "id": 1,
-      "name": "test",
-      "description": "testing",
-      "startDate": "2021-09-24",
-      "customer": {
-        "id": 1,
-        "name": "Test customer",
-        "description": "Get the pile"
-      },
-      "managingEmployee": {
-        "id": 1,
-        "firstName": "Test",
-        "lastName": "Manager",
-        "email": "test@manager.fi",
-        "startDate": "2021-09-24",
-        "role": "USER"
-      },
-      "status": "ACTIVE"
-    }
-  }
-}