vocascan / vocascan-server

Server for Vocascan
https://vocascan.com
Apache License 2.0
26 stars 5 forks source link

Route for checking duplicate vocabs #91

Open noctera opened 1 year ago

noctera commented 1 year ago

We need a route to checki if vocab already exists in groups/packages when creating them. The check only has do be done client-side, so no additional checking in the vocab creation functions.

Needed Routes:

  1. Route to check if vocab already exists in package /api/check-duplicate?languagePackageId={languagePackageId}&vocab={vocab}

Response:

{
    "duplicate": false,
    "group": {
        "id": "fbd8ee4a-8105-4716-zt72-65d6ef411234",
        "languagePackageId": "81ec68fc-843e-4a76-9fzu-5ae0b1gb05c2",
        "name": "Unit 1",
        "description": "This is a test",
        "active": true,
    },
}
  1. Route to check if vocab already exists in group /api/check-duplicate?groupId={groupId}&vocab={vocab}

Response:

{
   " duplicate": false,
    "group": {
        "id": "fbd8ee4a-8105-4716-zt72-65d6ef411234",
        "languagePackageId": "81ec68fc-843e-4a76-9fzu-5ae0b1gb05c2",
        "name": "Unit 1",
        "description": "This is a test",
        "active": true,
    },
}

For a better overview I have split up the two needed cases. But overall there is only one endpoint, where you can give your needed query parameters to get the result. This includes adding groupId and packageId in one query too (although this is a bit useless).

noctera commented 1 year ago

@luwol03 I have updated the route response

luwol03 commented 1 year ago

what about making groupId and languagePackagId optional and have one controller handler?

noctera commented 1 year ago

what about making groupId and languagePackagId optional and have one controller handler?

Yeah this was my intention I tried to explain here

For a better overview I have split up the two needed cases. But overall there is only one endpoint, where you can give your needed query parameters to get the result. This includes adding groupId and packageId in one query too (although this is a bit useless).

Or did you think of something else

luwol03 commented 1 year ago

oh ok. And what is with the third case without any parameters?

noctera commented 1 year ago

I don't know if not parameters make that much sense. No parameters would mean that it checks in every group and package. But I think you only need this function to check a specific package, not all your packages

luwol03 commented 1 year ago

I was thinking of showing that this vocab already exists in package XXX group XXX

noctera commented 1 year ago

@luwol03 I have added a vocab parameter to the route, as it is a GET. Would you agree with this?

luwol03 commented 1 year ago

What should this be for? And I would also respond with the found vocab so you can show it in the create anyway dialog.

noctera commented 1 year ago

I was thinking of showing that this vocab already exists in package XXX group XXX

Yeah understand what you mean. But when you create a new package you usually don't care if a vocab you want to add is already existing in another package, as it is completely new and created for another learning purpose. I think a global check would be unnecessary and disturbing

noctera commented 1 year ago

What should this be for? And I would also respond with the found vocab so you can show it in the create anyway dialog.

The vocab parameter includes the name (foreign word) that has to be checked. As this is a GET request I wouldn't send it in the body.

Yeah you could add the found vocab I'm the response. But you could just use the foreign word of the input field in the client that is saved there anyways