Skip to content

Commit

Permalink
#257 refactor read
Browse files Browse the repository at this point in the history
  • Loading branch information
grabdoc committed Feb 7, 2024
1 parent 3ceb21b commit 398fbc8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@RequiredArgsConstructor
public class FindOneController {

private final ReadService readService;
private final FindOneService findOneService;

@GetMapping("/{tableName}/one")
public FindOneResponse findOne(@PathVariable String tableName,
Expand All @@ -23,7 +23,7 @@ public FindOneResponse findOne(@PathVariable String tableName,
log.info("select - {}", select);
log.info("filter - {}", filter);

return this.readService.findOne(tableName, select, filter);
return this.findOneService.findOne(tableName, select, filter);
}


Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/homihq/db2rest/rest/read/ReadController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.homihq.db2rest.rest.read;

import com.homihq.db2rest.rest.read.v2.dto.ReadContextV2;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -9,6 +10,8 @@
import static org.springframework.web.bind.ServletRequestUtils.*;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
Expand Down Expand Up @@ -40,4 +43,33 @@ public Object findAll(@PathVariable String tableName,
return readService.findAll(schemaName, tableName,select, filter, pageable, sort);
}

@GetMapping(value = "/V2/{tableName}" , produces = "application/json")
public Object find(@PathVariable String tableName,
@RequestParam(name = "fields", required = false, defaultValue = "*") String fields,
@RequestParam(name = "filter", required = false, defaultValue = "") String filter,
@RequestParam(name = "sort", required = false, defaultValue = "") List<String> sorts,
@RequestParam(name = "limit", required = false, defaultValue = "-1") int limit,
@RequestParam(name = "offset", required = false, defaultValue = "-1") long offset
) {

log.info("fields - {}", fields);
log.info("filter - {}", filter);
log.info("sort - {}", sorts);
log.info("limit - {}", limit);
log.info("offset - {}", offset);

ReadContextV2 readContextV2 = ReadContextV2.builder()
.tableName(tableName)
.fields(fields)
.filter(filter)
.sorts(sorts)
.limit(limit)
.offset(offset)
.build();


return readService.findAll(readContextV2);

}

}
31 changes: 23 additions & 8 deletions src/main/java/com/homihq/db2rest/rest/read/ReadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.homihq.db2rest.rest.read.dto.FindOneResponse;
import com.homihq.db2rest.rest.read.helper.*;
import com.homihq.db2rest.rest.read.dto.QueryRequest;
import com.homihq.db2rest.rest.read.v2.dto.ReadContextV2;
import com.homihq.db2rest.rest.read.v2.processor.QueryCreatorTemplate;
import com.homihq.db2rest.rest.read.v2.processor.ReadPreProcessor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
Expand All @@ -28,6 +31,9 @@ public class ReadService {

private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;

private final List<ReadPreProcessor> processorList;
private final QueryCreatorTemplate queryCreatorTemplate;

public Object findAll(String schemaName, String tableName, String select, String filter,
Pageable pageable, Sort sort) {
ReadContext ctx = ReadContext.builder()
Expand All @@ -51,26 +57,35 @@ public Object findAll(String schemaName, String tableName, String select, String

}

public FindOneResponse findOne(String tableName, String select, String filter) {
public Object findAll(ReadContextV2 readContextV2) {

Pageable currPage = Pageable.ofSize(1).withPage(0);
ReadContext ctx = ReadContext.builder()
.pageable(currPage)
.tableName(tableName).select(select).filter(filter).build();

for(ReadPreProcessor processor : processorList) {
processor.process(readContextV2);
}

queryCreatorTemplate.createQuery(readContextV2);

/*
selectBuilder.build(ctx);
joinBuilder.build(ctx);
whereBuilder.build(ctx);
limitPaginationBuilder.build(ctx);
sortBuilder.build(ctx);
String sql = ctx.prepareSQL();
Map<String, Object> bindValues = ctx.prepareParameters();
Map<String,Object> bindValues = ctx.prepareParameters();
log.info("SQL - {}", sql);
log.info("Bind variables - {}", bindValues);
return new FindOneResponse(
namedParameterJdbcTemplate.queryForObject(sql, bindValues, Object.class));
return namedParameterJdbcTemplate.queryForList(sql, bindValues);
*/

return null;
}

}

This file was deleted.

61 changes: 0 additions & 61 deletions src/main/java/com/homihq/db2rest/rest/read/v2/ReadServiceV2.java

This file was deleted.

0 comments on commit 398fbc8

Please sign in to comment.