Skip to content

Commit

Permalink
First pass at topics
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardloveall committed Oct 27, 2017
1 parent d64332b commit 99aff4f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
12 changes: 12 additions & 0 deletions db/migrations/20171027125753_create_topics.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateTopics::V20171027125753 < LuckyMigrator::Migration::V1
def migrate
create :topics do
add title : String
add description : String?
end
end

def rollback
drop :topics
end
end
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ dependencies:
version: ~> 0.4.2
lucky_migrator:
github: luckyframework/migrator
version: ~> 0.2.3
version: ~> 0.2.3
2 changes: 1 addition & 1 deletion src/actions/home/index.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Home::Index < BaseAction
get "/" do
render LuckyWeb::WelcomePage
redirect to: Topics::Index
end
end
5 changes: 5 additions & 0 deletions src/actions/topics/index.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Topics::Index < BaseAction
action do
render topics: TopicQuery.new
end
end
6 changes: 6 additions & 0 deletions src/models/topic.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Topic < BaseModel
table :topics do
field title : String
field description : String?
end
end
13 changes: 13 additions & 0 deletions src/pages/topics/index_page.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Topics::IndexPage < BasePage
needs topics : TopicQuery

render do
h1 "Topics"

ul do
@topics.each do |topic|
li topic.title
end
end
end
end
2 changes: 2 additions & 0 deletions src/queries/topic_query.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class TopicQuery < Topic::BaseQuery
end

0 comments on commit 99aff4f

Please sign in to comment.