aboutsummaryrefslogtreecommitdiff
path: root/src/guff/post-model.cr
blob: 112589bd92c9aec0d76058123cb961cc3e56b3bd (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
38
39
40
41
42
43
44
45
46
47
48
49
50
module Guff
  class PostModel < Model
    SQL = {
      get_posts: "
        SELECT a.post_id,
               a.name,
               a.body,
               a.html

          FROM posts a
          JOIN (
            SELECT DISTICT
                   c.post_id

              FROM post_tags c

              JOIN tags d
                ON (d.tag_id = c.tag_id)
              JOIN (VALUES (%{tags}) e(name)
                ON (e.name = d.name)
          ) b

         WHERE c.%{filter}

         ORDER BY %{sort} %{dir}
         OFFSET ? LIMIT ?
      ",
    }

    def get_posts(req)
      # TODO
      [{foo: "bar"}, {foo: "asdf"}]
    end

    def add_post(req)
      # TODO: return post id
      {ok: true}
    end

    def remove_posts(req)
      # TODO
      {ok: true}
    end

    def set_tags(req)
      # TODO
      {ok: true}
    end
  end
end