如何使用 entity-repository-service-controller-dto 正确设计 Spring 应用程序以使用这些实体?
我是这样理解的:
实体:旅行、公司、乘客、PassInTrip
存储库:TripRepository、CompanyRepository、PassengerRepository、PassInTripRepository
DTO:TripDto、CompanyDto、PassengerDto
进一步的问题出现了。据我所知,业务逻辑应该在服务中描述。
服务:
CompanyService(getCompanyByName、createCompany、deleteCompany、addTripToCompany、getAllCompanies)PassengerService(getPassengerByPassportNumber、createPassenger、updatePassenger、deletePassenger、addPassengerToTrip)
以斜体突出显示的方法会引起怀疑。PassengerService 使用两个存储库 - TripRepository 和PassengerRepository。有一种感觉,从架构的角度来看,这是一个糟糕的决定,一切都应该是错误的。
还有两个控制器,这里是所有端点:
GET /api/passengers - get list of all passengers
GET /api/passengers/{passportNumber} - get passenger by passport number
POST /api/passengers/create - create new passenger
PUT /api/passengers/update/{passportNumber} - update passenger by passport number
PUT /api/passengers/addToTrip/{passportNumber} - add passenger with given passport number to trip
DELETE /api/passengers/delete/{passportNumber} - delete passenger by passport number
GET /api/companies - get list of all companies
GET /api/companies/{name} - get company by name
POST /api/companies/create - create new company
POST /api/companies/{name}/addTrip - add new trip to company with given name
DELETE /api/companies/delete/{name} - delete company by name
实际上,问题是,从架构的角度来看这里有什么问题以及如何正确修复它?