github.com/companieshouse/lfp-pay-api@v0.0.0-20230203133422-0ca455cd79f9/dao/service.go (about) 1 package dao 2 3 import ( 4 "github.com/companieshouse/lfp-pay-api-core/models" 5 "github.com/companieshouse/lfp-pay-api/config" 6 "github.com/companieshouse/lfp-pay-api/e5" 7 ) 8 9 // Service interface declares how to interact with the persistence layer regardless of underlying technology 10 type Service interface { 11 // CreatePayableResource will persist a newly created resource 12 CreatePayableResource(dao *models.PayableResourceDao) error 13 // GetPayableResource will find a single payable resource with the given companyNumber and reference 14 GetPayableResource(companyNumber, reference string) (*models.PayableResourceDao, error) 15 // UpdatePaymentDetails will update the resource with changed values 16 UpdatePaymentDetails(dao *models.PayableResourceDao) error 17 // SaveE5Error stored which command to E5 failed e.g. create, authorise or confirm 18 SaveE5Error(companyNumber, reference string, action e5.Action) error 19 // Shutdown can be called to clean up any open resources that the service may be holding on to. 20 Shutdown() 21 } 22 23 // NewDAOService will create a new instance of the Service interface. All details about its implementation and the 24 // database driver will be hidden from outside of this package 25 func NewDAOService(cfg *config.Config) Service { 26 database := getMongoDatabase(cfg.MongoDBURL, cfg.Database) 27 return &MongoService{ 28 db: database, 29 CollectionName: cfg.MongoCollection, 30 } 31 }