Enable repository only for sub resource level in spring data rest?

巧了我就是萌 提交于 2020-01-04 06:05:28

问题


I have 2 jpa entities Document and DispatchDetail which have one-to-many relationship. i.e. a document can have a list of dispatchDetails. I have created 2 repositories for each entity.

Now I'm gonna try a document GET.

http://localhost:7070/booking-documents-service/docs/5999571

{
    "docType": "SAP_ACCOUNTS_PAYABLE",
    "docStoreId": 456651,
    "qualityChecked": true,
    "format": "pdf",
    "bookingId": -1,
    "_links": {
        "self": {
            "href": "http://localhost:7070/booking-documents-service/docs/5999571"
        },
        "generatedDocument": {
            "href": "http://localhost:7070/booking-documents-service/docs/5999571"
        },
        "dispatchDetails": {
            "href": "http://localhost:7070/booking-documents-service/docs/5999571/dispatchDetails"
        }
    }
}

Now when I try GET request for the link listed as dispatchDetails. It is like this.

http://localhost:7070/booking-documents-service/docs/5999571/dispatchDetails

{
    "_embedded": {
        "dispatchDetails": [
            {
                "dispatchQueId": 207443,
                "dispatchStatus": "S",
                "recipient": "fldcvisla12678.wdw.disney.com|#|/opt/apps/shared/shuttle/SAP/OUT/|#|f-tbxshuttlenp|#|D1$NeY984|#|SFTP|#|22|#|null",
                "description": "Upload :FileUploadDispatcher; FTP:null/null;\n2d89df3d-ca51-4d35-9528-439923fa48d4..",
                "dispatcher": "AD",
                "_links": {
                    "self": {
                        "href": "http://localhost:7070/booking-documents-service/dispatchDetails/1"
                    },
                    "dispatchDetail": {
                        "href": "http://localhost:7070/booking-documents-service/dispatchDetails/1"
                    },
                    "generatedDocument": {
                        "href": "http://localhost:7070/booking-documents-service/dispatchDetails/1/generatedDocument"
                    }
                }
            }
        ]
    },
    "_links": {
        "self": {
            "href": "http://localhost:7070/booking-documents-service/docs/5999571/dispatchDetails"
        }
    }
}

But I don't want dispatch details as a stand alone resource (listed in links above). i.e. I don't want this endpoint

http://localhost:7070/booking-documents-service/dispatchDetails

Instead I only need this.

http://localhost:7070/booking-documents-service/docs/5999571/dispatchDetails

How to achieve this? i.e. allow only sub resource level operations.

来源:https://stackoverflow.com/questions/51247346/enable-repository-only-for-sub-resource-level-in-spring-data-rest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!