Skip to content

Commit 047db2d

Browse files
committed
dicome api improved documentation, further implemented apply and discard endpoints
1 parent d31e60a commit 047db2d

1 file changed

Lines changed: 38 additions & 30 deletions

File tree

src/api/dicome.ts

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,77 @@
11
import { Router } from "express";
2-
import { createDiff } from "../services/createDiff.js";
3-
import { getInputModelsOrError } from "../utils/prepInputModels.js";
2+
import { getInputModelsOrError, prepForPatch } from "../utils/prepInput.js";
3+
import * as comparissonMergingService from "../services/comparisonMerging.service.js";
4+
import * as patchingService from "../services/patching.service.js";
45

56
const dicome = Router();
67

78
/**
89
* Compare two models and detect conflicts
910
*
10-
* @param {InputModels} req.body - The first operand
11-
* @returns {DiffModel} The sum of both operands
11+
* @param {InputModels} req.body
12+
* @returns {DiffModel}
1213
*/
1314
dicome.post("/compare", (req, res) => {
1415
console.log("request body", req.body);
1516
const inputModelsOrError = getInputModelsOrError(req.body, req.session);
1617

1718
if (typeof inputModelsOrError === "string") {
1819
console.log(inputModelsOrError);
19-
res.status(500).send(inputModelsOrError);
20+
res.status(400).send(inputModelsOrError);
2021
} else {
21-
const diffModel = createDiff(inputModelsOrError);
22+
const diffModel = comparissonMergingService.createDiff(inputModelsOrError);
2223
req.session.diffModel = diffModel;
2324
res.send(diffModel);
2425
}
2526
});
2627

2728
/**
2829
* Apply differences
30+
* @description for conflict: opposing change is automatically rejected (DISCARD)
31+
*
32+
* changes State of respective differences in DiffModel
2933
*
30-
* for conflicts: if this is a left change then right automatically rejected and vis a versa
31-
*
32-
* @param {number[]} req.body - non-empty list of DiffModel Differences IDs
33-
* @returns {object} JSON patch (if technically possible) of diff model and left/right
34+
* @param {leftIds: number[], rightIds: number[]} req.body - json with a list of DiffModel Differences IDs coming from left and right side
35+
* @returns {object} JSON patch
36+
*
3437
*/
3538
dicome.put("/apply", (req, res) => {
36-
const sessionDiffModel = req.session.diffModel;
39+
const userInputOrError = prepForPatch(req.body, req.session);
40+
41+
if (typeof userInputOrError === "string") {
42+
res.status(400).send(userInputOrError);
43+
} else {
44+
const applyResp = patchingService.applyDifferences(userInputOrError.leftIds as number[], userInputOrError.rightIds as number[], userInputOrError.diffmodel);
45+
46+
res.sendStatus(applyResp);
47+
}
3748

38-
// TODO
39-
// create service
40-
// get differences from id array
41-
// ...
42-
// change status of conflict if 3 way
49+
// TODO: Test if diff model in sess is really overwritten ???
4350

44-
res.sendStatus(200);
4551
});
4652

4753
/**
4854
* Discard differences
55+
* @description if conflict: opposing difference will NOT be applied automatical
56+
*
57+
* changes State of respective differences in DiffModel
4958
*
50-
* for conflicts: if this is a left change then right will NOT be applied automatical,
51-
* the change has to be in list of apply endpoint
52-
* and vis a versa
53-
*
54-
* @param {number[]} req.body - non empty list of DiffModel Differences IDs
55-
* @returns {object} JSON patch (if technically possible) of diff model and left/right
59+
* @param {leftIds: number[], rightIds: number[]} req.body - json with a list of DiffModel Differences IDs coming from left and right side
60+
* @returns {object} JSON patch
61+
* Sideeffect:
5662
*/
5763
dicome.put("/discard", (req, res) => {
58-
const sessionDiffModel = req.session.diffModel;
64+
const userInputOrError = prepForPatch(req.body, req.session);
65+
66+
if (typeof userInputOrError === "string") {
67+
res.status(400).send(userInputOrError);
68+
} else {
69+
const discardResp = patchingService.discardDifferences(userInputOrError.leftIds as number[], userInputOrError.rightIds as number[], userInputOrError.diffmodel);
5970

60-
// TODO
61-
// create service
62-
// get differences from id array
63-
// ...
64-
// change status of conflict if 3 way
71+
res.sendStatus(discardResp);
72+
}
6573

66-
res.sendStatus(200);
74+
// TODO: Test if diff model in sess is really overwritten ???
6775
});
6876

6977
dicome.delete("/session", (req, res) => {

0 commit comments

Comments
 (0)