Skip to content

Commit

Permalink
OC-714 Rename/Split API endpoints and organise services/controllers t…
Browse files Browse the repository at this point in the history
…o reflect the actual resources (#505)

* finished dev work

* fixed api tests

* fixed flag and topics endpoints

* fixed TS type error

* fixed e2e tests and improved app performance

* removed unused components

* fixed eslint issues

* fixed e2e tests

* removed unused publication endpoint

* removed tests for inexistent endpoint

* renamed isReadyTo... to checkIsReadyTo... services

* added extra check on /publications/{id}

* added "latestLive" option for getting pub version

* removed unused publication service

* added ownership checks for /links endpoint

* renamed publication to publicationVersion in tests

* renamed link with linkedPublication

* fixed empty published date

* renamed userPublicationsUrl variable

* renamed pub version endpoints and updated tests

---------

Co-authored-by: Florin H <florin.holhos@wingravity.com>
  • Loading branch information
florin-holhos and Florin H committed Oct 13, 2023
1 parent 1e25101 commit 0d2b86e
Show file tree
Hide file tree
Showing 103 changed files with 2,892 additions and 3,178 deletions.
114 changes: 64 additions & 50 deletions api/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ functions:
seedOpenSearch:
handler: src/lib/testUtils.openSearchSeed
# Publications
getPublications:
handler: src/components/publication/routes.getAll
events:
- http:
path: ${self:custom.versions.v1}/publications
method: GET
cors: true
getPublication:
handler: src/components/publication/routes.get
events:
Expand All @@ -176,27 +169,6 @@ functions:
path: ${self:custom.versions.v1}/publications
method: POST
cors: true
updateStatus:
handler: src/components/publication/routes.updateStatus
events:
- http:
path: ${self:custom.versions.v1}/publications/{id}/status/{status}
method: PUT
cors: true
updatePublication:
handler: src/components/publication/routes.update
events:
- http:
path: ${self:custom.versions.v1}/publications/{id}
method: PATCH
cors: true
deletePublication:
handler: src/components/publication/routes.deletePublication
events:
- http:
path: ${self:custom.versions.v1}/publications/{id}
method: DELETE
cors: true
getPublicationLinks:
handler: src/components/publication/routes.getPublicationLinks
events:
Expand All @@ -219,6 +191,49 @@ functions:
path: ${self:custom.versions.v1}/publications/research-topics
method: GET
cors: true
getPublicationTopics:
handler: src/components/publication/routes.getPublicationTopics
events:
- http:
path: ${self:custom.versions.v1}/publications/{id}/topics
method: GET
cors: true
# Publication Versions
getPublicationVersion:
handler: src/components/publicationVersion/routes.get
events:
- http:
path: ${self:custom.versions.v1}/publications/{id}/publication-versions/{version} # {version} can be a version id, number or "latest"
method: GET
cors: true
getIndexedPublicationVersions:
handler: src/components/publicationVersion/routes.getAll
events:
- http:
path: ${self:custom.versions.v1}/publication-versions
method: GET
cors: true
updatePublicationVersion:
handler: src/components/publicationVersion/routes.update
events:
- http:
path: ${self:custom.versions.v1}/publication-versions/{id}
method: PATCH
cors: true
updateStatus:
handler: src/components/publicationVersion/routes.updateStatus
events:
- http:
path: ${self:custom.versions.v1}/publication-versions/{id}/status/{status}
method: PUT
cors: true
deleteVersion:
handler: src/components/publicationVersion/routes.deleteVersion
events:
- http:
path: ${self:custom.versions.v1}/publication-versions/{id}
method: DELETE
cors: true
# Users
getUsers:
handler: src/components/user/routes.getAll
Expand All @@ -234,11 +249,11 @@ functions:
path: ${self:custom.versions.v1}/users/{id}
method: GET
cors: true
getUserPublications:
handler: src/components/user/routes.getPublications
getUserPublicationVersions:
handler: src/components/user/routes.getPublicationVersions
events:
- http:
path: ${self:custom.versions.v1}/users/{id}/publications
path: ${self:custom.versions.v1}/users/{id}/publication-versions
method: GET
cors: true

Expand Down Expand Up @@ -298,91 +313,91 @@ functions:
handler: src/components/coauthor/routes.get
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/coauthors
path: ${self:custom.versions.v1}/publication-versions/{id}/coauthors
method: GET
cors: true
updateAll:
handler: src/components/coauthor/routes.updateAll
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/coauthors
path: ${self:custom.versions.v1}/publication-versions/{id}/coauthors
method: PUT
cors: true
deleteCoAuthor:
handler: src/components/coauthor/routes.remove
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/coauthors/{coauthor}
path: ${self:custom.versions.v1}/publication-versions/{id}/coauthors/{coauthor}
method: DELETE
cors: true
linkCoAuthor:
handler: src/components/coauthor/routes.link
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/link-coauthor
path: ${self:custom.versions.v1}/publication-versions/{id}/link-coauthor
method: PATCH
cors: true
updateCoAuthorConfirmation:
handler: src/components/coauthor/routes.updateConfirmation
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/coauthor-confirmation
path: ${self:custom.versions.v1}/publication-versions/{id}/coauthor-confirmation
method: PATCH
cors: true
requestApproval:
handler: src/components/coauthor/routes.requestApproval
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/coauthors/request-approval
path: ${self:custom.versions.v1}/publication-versions/{id}/coauthors/request-approval
method: PUT
cors: true
sendApprovalReminder:
handler: src/components/coauthor/routes.sendApprovalReminder
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/coauthors/{coauthor}/approval-reminder
path: ${self:custom.versions.v1}/publication-versions/{id}/coauthors/{coauthor}/approval-reminder
method: POST
cors: true
getFlag:
handler: src/components/flag/routes.get
events:
- http:
path: ${self:custom.versions.v1}/flag/{id}
path: ${self:custom.versions.v1}/flags/{id}
method: GET
cors: true
createFlag:
handler: src/components/flag/routes.createFlag
events:
- http:
path: ${self:custom.versions.v1}/publications/{id}/flag
path: ${self:custom.versions.v1}/publications/{id}/flags
method: POST
cors: true
createFlagComment:
handler: src/components/flag/routes.createFlagComment
events:
- http:
path: ${self:custom.versions.v1}/flag/{id}/comment
path: ${self:custom.versions.v1}/flags/{id}/comment
method: POST
cors: true
resolveFlag:
handler: src/components/flag/routes.resolveFlag
events:
- http:
path: ${self:custom.versions.v1}/flag/{id}/resolve
path: ${self:custom.versions.v1}/flags/{id}/resolve
method: POST
cors: true
getPublicationFlags:
handler: src/components/flag/routes.getPublicationFlags
events:
- http:
path: ${self:custom.versions.v1}/flag/publication/{id}
path: ${self:custom.versions.v1}/publications/{id}/flags
method: GET
cors: true
getUserFlags:
handler: src/components/flag/routes.getUserFlags
events:
- http:
path: ${self:custom.versions.v1}/flag/user/{id}
path: ${self:custom.versions.v1}/user/{id}/flags
method: GET
cors: true
# Images
Expand Down Expand Up @@ -448,29 +463,29 @@ functions:
handler: src/components/funder/routes.create
events:
- http:
path: ${self:custom.versions.v1}/publications/{id}/funders
path: ${self:custom.versions.v1}/publication-versions/{id}/funders
method: POST
cors: true
deleteFunder:
handler: src/components/funder/routes.destroy
events:
- http:
path: ${self:custom.versions.v1}/publications/{id}/funders/{funder}
path: ${self:custom.versions.v1}/publication-versions/{id}/funders/{funder}
method: DELETE
cors: true
# References
getReferences:
handler: src/components/reference/routes.get
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/reference
path: ${self:custom.versions.v1}/publication-versions/{id}/references
method: get
cors: true
updateAllReference:
handler: src/components/reference/routes.updateAll
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/reference
path: ${self:custom.versions.v1}/publication-versions/{id}/references
method: put
cors: true

Expand All @@ -479,7 +494,7 @@ functions:
handler: src/components/affiliations/routes.updateAffiliations
events:
- http:
path: ${self:custom.versions.v1}/publicationVersions/{id}/my-affiliations
path: ${self:custom.versions.v1}/publication-versions/{id}/my-affiliations
method: PUT
cors: true

Expand Down Expand Up @@ -520,4 +535,3 @@ functions:
path: ${self:custom.versions.v1}/publications/{id}/topics
method: PUT
cors: true

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('update coAuthor affiliations per publication', () => {

test('Corresponding author can add an affiliation to their DRAFT publication', async () => {
const updateAffiliationsResponse = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/my-affiliations')
.put('/publication-versions/publication-problem-draft-v1/my-affiliations')
.query({ apiKey: '000000005' })
.send({
affiliations: orcidTestAffiliations,
Expand All @@ -82,7 +82,7 @@ describe('update coAuthor affiliations per publication', () => {

test('Corresponding author needs to add affiliations if not independent before locking the publication', async () => {
const updateAffiliationsResponse = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/my-affiliations')
.put('/publication-versions/publication-problem-draft-v1/my-affiliations')
.query({ apiKey: '000000005' })
.send({
affiliations: [],
Expand All @@ -92,7 +92,7 @@ describe('update coAuthor affiliations per publication', () => {
expect(updateAffiliationsResponse.status).toEqual(200);

const updateStatusResponse = await testUtils.agent
.put('/publications/publication-problem-draft/status/LOCKED')
.put('/publication-versions/publication-problem-draft-v1/status/LOCKED')
.query({ apiKey: '000000005' })
.send();

Expand All @@ -104,7 +104,7 @@ describe('update coAuthor affiliations per publication', () => {

test('Author needs to fill out affiliations if the publication is LOCKED', async () => {
const updateAffiliationsResponse = await testUtils.agent
.put('/publicationVersions/publication-problem-locked-v1/my-affiliations')
.put('/publication-versions/publication-problem-locked-v1/my-affiliations')
.query({ apiKey: '000000005' })
.send({
affiliations: [],
Expand All @@ -117,7 +117,7 @@ describe('update coAuthor affiliations per publication', () => {

test('User cannot add affiliations if they are not part of the publication', async () => {
const updateAffiliationsResponse = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/my-affiliations')
.put('/publication-versions/publication-problem-draft-v1/my-affiliations')
.query({ apiKey: '123456789' })
.send({
affiliations: [],
Expand All @@ -132,7 +132,7 @@ describe('update coAuthor affiliations per publication', () => {

test('User cannot add affiliations if the publication is LIVE', async () => {
const updateAffiliationsResponse = await testUtils.agent
.put('/publicationVersions/publication-problem-live-v1/my-affiliations')
.put('/publication-versions/publication-problem-live-v1/my-affiliations')
.query({ apiKey: '123456789' })
.send({
affiliations: [],
Expand All @@ -145,7 +145,7 @@ describe('update coAuthor affiliations per publication', () => {

test('Only corresponding author can update his affiliations while the publication is DRAFT', async () => {
const updateAffiliationsResponse = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/my-affiliations')
.put('/publication-versions/publication-problem-draft-v1/my-affiliations')
.query({ apiKey: '000000005' })
.send({
affiliations: orcidTestAffiliations,
Expand All @@ -156,7 +156,7 @@ describe('update coAuthor affiliations per publication', () => {
expect(updateAffiliationsResponse.body.message).toEqual('Successfully updated affiliations.');

const updateAffiliationsResponse2 = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/my-affiliations')
.put('/publication-versions/publication-problem-draft-v1/my-affiliations')
.query({ apiKey: '000000006' })
.send({
affiliations: orcidTestAffiliations,
Expand All @@ -171,7 +171,7 @@ describe('update coAuthor affiliations per publication', () => {

test('Cannot add duplicate affiliations', async () => {
const updateAffiliationsResponse = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/my-affiliations')
.put('/publication-versions/publication-problem-draft-v1/my-affiliations')
.query({ apiKey: '000000005' })
.send({
affiliations: orcidTestAffiliations.concat(orcidTestAffiliations),
Expand Down
2 changes: 1 addition & 1 deletion api/src/components/affiliations/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const updateAffiliations = async (
const affiliations = event.body.affiliations;
const publicationVersionId = event.pathParameters.id;
// Get publication version
const version = await publicationVersionService.get(publicationVersionId);
const version = await publicationVersionService.getById(publicationVersionId);

// Check that the version exists
if (!version) {
Expand Down
10 changes: 5 additions & 5 deletions api/src/components/coauthor/__tests__/createCoAuthor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('create coauthor', () => {

test('Update co-authors for a specific publication version', async () => {
const coauthor = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/coauthors')
.put('/publication-versions/publication-problem-draft-v1/coauthors')
.query({ apiKey: '000000005' })
.send([
{
Expand All @@ -34,7 +34,7 @@ describe('create coauthor', () => {

test('Cannot create a co-author with duplicate email', async () => {
const coauthor = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/coauthors')
.put('/publication-versions/publication-problem-draft-v1/coauthors')
.query({ apiKey: '000000005' })
.send([
{
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('create coauthor', () => {

test('Cannot create a co-author record if the user is not the author of the publication version', async () => {
const coauthor = await testUtils.agent
.put('/publicationVersions/publication-problem-draft-v1/coauthors')
.put('/publication-versions/publication-problem-draft-v1/coauthors')
.query({ apiKey: '987654321' })
.send([
{
Expand All @@ -93,7 +93,7 @@ describe('create coauthor', () => {

test('Cannot create a co-author record on a publication version that does not exist', async () => {
const coauthor = await testUtils.agent
.put('/publicationVersions/non-existent-publication-version/coauthors')
.put('/publication-versions/non-existent-publication-version/coauthors')
.query({ apiKey: '123456789' })
.send([
{
Expand All @@ -111,7 +111,7 @@ describe('create coauthor', () => {

test('Cannot create a co-author record on a publication version that is live', async () => {
const coauthor = await testUtils.agent
.put('/publicationVersions/publication-problem-live-v1/coauthors')
.put('/publication-versions/publication-problem-live-v1/coauthors')
.query({ apiKey: '123456789' })
.send([
{
Expand Down
Loading

0 comments on commit 0d2b86e

Please sign in to comment.