Skip to content

Commit

Permalink
Update post/put for store operation in mock testing server;
Browse files Browse the repository at this point in the history
  • Loading branch information
ligangty committed Nov 13, 2023
1 parent bee3129 commit d7efcd8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 87 deletions.
58 changes: 0 additions & 58 deletions src/main/webui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/main/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"babel-loader": "^9.1.3",
"body-parser": "^1.20.2",
"css-loader": "^6.8.1",
"eslint": "^8.51.0",
"eslint-plugin-jest": "^27.6.0",
Expand Down
64 changes: 36 additions & 28 deletions src/main/webui/src/server/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import compression from 'compression';
import express from 'express';
import bodyParser from 'body-parser';
import path from 'path';
import {Config} from './config/AppConfig';

Expand All @@ -9,8 +8,7 @@ const indexHtml=path.join(projectRoot+'/index.html');

const app = express();
app.use(compression());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json({extended: true}));
app.use(express.json());
const server = app.listen(Config.SERVER_PORT, () => {
const host = server.address().address;
const port = server.address().port;
Expand Down Expand Up @@ -102,37 +100,47 @@ app.get('/api/admin/stores/maven/group/:name', (req, res) => {
}
});

const newFakeRepo = (packageType, type, name)=>{
const storeKey = `${packageType}:${type}:${name}`;
const repo = {
"packageType": `${packageType}`,
"type": `${type}`,
"name": `${name}`,
"key": `${storeKey}`,
"description": `This is a fake repo for ${storeKey}`,
"disabled": false,
"disable_timeout": 0,
"path_style": "plain",
"authoritative_index": false,
"prepend_constituent": false
};
return repo;
};
// const newFakeRepo = (packageType, type, name)=>{
// const storeKey = `${packageType}:${type}:${name}`;
// const repo = {
// "packageType": `${packageType}`,
// "type": `${type}`,
// "name": `${name}`,
// "key": `${storeKey}`,
// "description": `This is a fake repo for ${storeKey}`,
// "disabled": false,
// "disable_timeout": 0,
// "path_style": "plain",
// "authoritative_index": false,
// "prepend_constituent": false
// };
// return repo;
// };

app.post('/api/admin/stores/:packageType/:type/:name', (req, res) => {
const [packageType, type, name]=[req.params.packageType, req.params.type, req.params.name];
console.log(packageType, type, name);
const repoBody = req.body;
console.log(repoBody);
const responseRepo = newFakeRepo(packageType, type, name);
if (responseRepo){
res.status(204).json(responseRepo);
const newRepo = req.body;
if(req.headers['content-type']==="application/json"){
if (newRepo.packageType&&newRepo.type&&newRepo.name){
// res.status(204);
res.sendStatus(204);
}else{
res.status(400).json({error: "Bad repo request: missing packageType or type or name for repo!"});
}
}else{
res.status(400).json({error: "Bad repo request"});
res.status(400).json({error: "Bad request: wrong header content-type"});
}
});

app.put('/api/admin/stores/:packageType/:type/:name', (req, res) => {
// TODO: need to implement
const updatedRepo = req.body;
if(req.headers['content-type']==="application/json"){
if (updatedRepo.packageType&&updatedRepo.type&&updatedRepo.name){
res.status(200).json(updatedRepo);
}else{
res.status(400).json({error: "Bad repo request: missing packageType or type or name for repo!"});
}
}else{
res.status(400).json({error: "Bad request: wrong header content-type"});
}
});

0 comments on commit d7efcd8

Please sign in to comment.