Skip to content

Commit

Permalink
#215 - refactored bulk create controller
Browse files Browse the repository at this point in the history
  • Loading branch information
grabdoc committed Jan 31, 2024
1 parent f0fc377 commit 24c06e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/homihq/db2rest/rest/create/BulkCreateApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.homihq.db2rest.rest.create;

import com.homihq.db2rest.rest.create.dto.CreateBulkResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

public interface BulkCreateApi {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping(value = "/{tableName}/bulk",
consumes = {"application/json", "text/csv"}
)
CreateBulkResponse save(@PathVariable String tableName,
@RequestHeader(name = "Content-Profile", required = false) String schemaName,
@RequestParam(name = "tsid", required = false) String tsid,
@RequestParam(name = "tsidType", required = false, defaultValue = "number") String tsidType,
HttpServletRequest request) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -15,21 +14,18 @@
@RestController
@Slf4j
@RequiredArgsConstructor
public class BulkCreateController {
public class BulkCreateController implements BulkCreateApi {

private final CreateService createService;

private final List<DataProcessor> dataProcessors;

@ResponseStatus(HttpStatus.CREATED)
@PostMapping (value= "/{tableName}/bulk",
consumes = {"application/json", "text/csv"}
)
public CreateBulkResponse save(@PathVariable String tableName,
@RequestHeader(name = "Content-Profile" , required = false) String schemaName,
@RequestParam(name = "tsid", required = false) String tsid,
@RequestParam(name = "tsidType", required = false, defaultValue = "number") String tsidType,
HttpServletRequest request) throws Exception{
@Override
public CreateBulkResponse save(String tableName,
String schemaName,
String tsid,
String tsidType,
HttpServletRequest request) throws Exception{

DataProcessor dataProcessor = dataProcessors.stream()
.filter(d -> d.handle(request.getContentType()))
Expand Down

0 comments on commit 24c06e5

Please sign in to comment.