REST Service for POPCORN - ILIAS
alex
2025-05-15 9e1cd642d87d67c645b687231a002753fdfb28ca
adding REST routes
1 files modified
38 ■■■■ changed files
app.js 38 ●●●● patch | view | raw | blame | history
app.js
@@ -5,15 +5,41 @@
/////////////////////////////////////////////////////////////////////////
fastify.get('/api/users', async function (req, res) {
   const {offset, limit} = req.query
   const users = await db.getUsers(offset, limit)
   return res.send(users)
})
fastify
   .get('/api/users', async function (req, res) {
      const {offset, limit} = req.query
      const users = await db.getUsers(offset, limit)
      return res.send(users)
   })
   .get("/api/users/count", async function (req, res) {
      const count = await db.getUserCount()
      return res.send(count)
   })
   .get("/api/user/login/:login", async function (req, res) {
      const {login} = req.params
      const user = await db.getUserByLogin(login)
      if (user.length) {
         return res.send(user[0])
      }
      else {
         return res.code(404).send({status: "error", msg: "not found"})
      }
   })
   .get("/api/user/userid/:userid", async function (req, res) {
      const {userid} = req.params
      const user = await db.getUserByUserId(userid)
      if (user.length) {
         return res.send(user[0])
      }
      else {
         return res.code(404).send({status: "error", msg: "not found"})
      }
   })
/////////////////////////////////////////////////////////////////////////
fastify.listen({ port: 4101 }, function (err, address) {
fastify.listen({port: 4101}, function (err, address) {
   if (err) {
      fastify.log.error(err)
      process.exit(1)