CenterForDigitalHumanities / TPEN-services

Services required by TPEN interfaces in order to interact with data
1 stars 0 forks source link

Project Entity Class #26

Closed thehabes closed 1 week ago

thehabes commented 9 months ago

Most services exist to interact with a TPEN Project Entity in some way. Once the design of a TPEN Project Entity becomes clear, create a 'TPENProject' class for TPEN Services to work with.

An example of how TPEN Services would could do GET /manifest/123 using a Project class.

router.route('/:id')
   .get((req, res, next) => {
      let id = req.params.id
      id = parseInt(id)
      const project = new TPENProject(id)
      // Projects only have one manifest so will have a simple 'getter' for this
      const manifestObj = await project.getManifest()
      if(manifestObj){
         respondWithManifest(res, manifestObj)
      }
      else{
         utils.respondWithError(res, 404, `TPEN 3 project "${id}" does not exist.`)
      }
   })
   .all((req, res, next) => {
      utils.respondWithError(res, 405, 'Improper request method, please use GET.')
   })
thehabes commented 9 months ago

Check out the work by @cubap in TPEN Interfaces

https://github.com/CenterForDigitalHumanities/TPEN-interfaces/blob/main/api/project.mjs