summaryrefslogtreecommitdiff
path: root/lisp/service/rest-service.lisp
blob: ea374b81a50db878eb5dd2df4432a78882f7caa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(declaim (optimize (speed 0) (safety 3) (debug 3)))

(in-package #:dns-admin)

(defclass rest-service (base-service)
  ((location :initarg :location
             :initform nil
             :accessor location)
   (location-p :initarg :location-p
               :initform t
               :accessor location-p)
   (authmsg :initarg :authmsg
            :initform nil
            :accessor authmsg)
   (errormsg :initarg :errormsg
             :initform nil
             :accessor errormsg)
   (message :initarg :message
            :initform nil
            :accessor message))
  (:documentation ""))

(defmethod initialize-instance :after ((rest-service rest-service) &key)
  (when (and (location-p rest-service) (null (location rest-service)))
    (setf (location rest-service) (type-to-path rest-service))))

(defun handle-location (&optional (location "/home"))
  (format nil "{\"location\":\"~a\"}" location))

(defun type-to-path (rest-type)
  (concatenate 'string "/" (ppcre:regex-replace-all "-" (ppcre:regex-replace "-service$" (string-downcase (type-of rest-type)) "") "/")))

(defmacro with-service ((instance rest-service) &body body)
  `(let ((,instance (make-instance ',rest-service)))
     ,@body
     (objects-to-json `(,,instance))))