Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batch creation API #159

Open
wants to merge 2 commits into
base: Roadmap-2023
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions appmodule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { BatchController } from './batch.controller';
import { BatchService } from './batch.service';
import { TemplaterService } from './templater.service';

@Module({
imports: [],
controllers: [BatchController],
providers: [BatchService, TemplaterService],
})
export class AppModule {}
13 changes: 13 additions & 0 deletions batchcontroller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Post, Body } from '@nestjs/common';
import { BatchService } from './batch.service';
import { CreateBatchDto } from './dto/create-batch.dto';

@Controller('batches')
export class BatchController {
constructor(private readonly batchService: BatchService) {}

@Post()
async createBatch(@Body() createBatchDto: CreateBatchDto) {
return this.batchService.createBatch(createBatchDto);
}
}
39 changes: 39 additions & 0 deletions batches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const express = require('express');
const { v4: uuidv4 } = require('uuid');
const app = express();

// Define a global array to store the created batches
let batches = [];

// Middleware to parse JSON request bodies
app.use(express.json());

// POST /batches endpoint to create a new batch
app.post('/batches', (req, res) => {
const { template, data, engineType, templateType, outputType } = req.body;

// Generate a unique ID for the batch
const batchId = uuidv4();

// Create a new batch object
const newBatch = {
id: batchId,
template,
data,
engineType,
templateType,
outputType,
status: 'submitted',
};

// Add the new batch to the batches array
batches.push(newBatch);

// Return the created batch in the response
res.status(201).json(newBatch);
});

// Start the server
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
19 changes: 19 additions & 0 deletions batchservice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@nestjs/common';
import { TemplaterService } from './templater.service';
import { CreateBatchDto } from './dto/create-batch.dto';

@Injectable()
export class BatchService {
constructor(private readonly templaterService: TemplaterService) {}

async createBatch(createBatchDto: CreateBatchDto) {
// Perform any necessary validation or pre-processing here

// Call the Templater service to create the batch
const batch = await this.templaterService.createBatch(createBatchDto);

// Perform any additional operations or post-processing if needed

return batch;
}
}
8 changes: 8 additions & 0 deletions createbatchDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class CreateBatchDto {
template: any; // Replace with appropriate type
data: any; // Replace with appropriate type
engineType: string;
templateType: string;
outputType: string;
}

14 changes: 14 additions & 0 deletions templaterservice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { CreateBatchDto } from './dto/create-batch.dto';

@Injectable()
export class TemplaterService {
async createBatch(createBatchDto: CreateBatchDto) {
// Make API call to Templater to create a new batch
const response = await axios.post('/templater/batches', createBatchDto);

// Return the created batch from the response
return response.data;
}
}