Persist posts in Voyage
This commit is contained in:
@@ -4,9 +4,6 @@ Class {
|
|||||||
#instVars : [
|
#instVars : [
|
||||||
'posts'
|
'posts'
|
||||||
],
|
],
|
||||||
#classInstVars : [
|
|
||||||
'uniqueInstance'
|
|
||||||
],
|
|
||||||
#category : #TinyBlog
|
#category : #TinyBlog
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +32,9 @@ TBBlog class >> createDemoPosts [
|
|||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
TBBlog class >> current [
|
TBBlog class >> current [
|
||||||
"answer the instance of the TBRepository"
|
"answer the instance of the TBRepository"
|
||||||
^ uniqueInstance ifNil: [ uniqueInstance := self new ]
|
^ self selectAll
|
||||||
|
ifNotEmpty: [ :x | x anyOne ]
|
||||||
|
ifEmpty: [ self new save ]
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
@@ -43,9 +42,20 @@ TBBlog class >> initialize [
|
|||||||
self reset
|
self reset
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #reading }
|
||||||
|
TBBlog class >> initializeVoyageOnMemoryDB [
|
||||||
|
VOMemoryRepository new enableSingleton
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #reading }
|
||||||
|
TBBlog class >> isVoyageRoot [
|
||||||
|
"Indicates that instances of this class are top level documents in noSQL databases"
|
||||||
|
^ true
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
TBBlog class >> reset [
|
TBBlog class >> reset [
|
||||||
uniqueInstance := nil
|
self initializeVoyageOnMemoryDB.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #reading }
|
{ #category : #reading }
|
||||||
@@ -81,7 +91,8 @@ TBBlog >> initialize [
|
|||||||
|
|
||||||
{ #category : #deleting }
|
{ #category : #deleting }
|
||||||
TBBlog >> removeAllPosts [
|
TBBlog >> removeAllPosts [
|
||||||
posts := OrderedCollection new
|
posts := OrderedCollection new.
|
||||||
|
self save
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
@@ -91,6 +102,7 @@ TBBlog >> size [
|
|||||||
|
|
||||||
{ #category : #writing }
|
{ #category : #writing }
|
||||||
TBBlog >> writeBlogPost: aPost [
|
TBBlog >> writeBlogPost: aPost [
|
||||||
"Add the blog post to the list of posts."
|
"Add the blog post in database."
|
||||||
posts add: aPost
|
self allBlogPosts add: aPost.
|
||||||
|
self save
|
||||||
]
|
]
|
||||||
|
@@ -4,16 +4,17 @@ Class {
|
|||||||
#instVars : [
|
#instVars : [
|
||||||
'blog',
|
'blog',
|
||||||
'post',
|
'post',
|
||||||
'first'
|
'first',
|
||||||
|
'previousRepository'
|
||||||
],
|
],
|
||||||
#category : #'TinyBlog-Tests'
|
#category : #'TinyBlog-Tests'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #running }
|
{ #category : #running }
|
||||||
TBBlogTest >> setUp [
|
TBBlogTest >> setUp [
|
||||||
|
previousRepository := VORepository current.
|
||||||
|
VORepository setRepository: VOMemoryRepository new.
|
||||||
blog := TBBlog current.
|
blog := TBBlog current.
|
||||||
blog removeAllPosts.
|
|
||||||
|
|
||||||
first := TBPost title: 'A title' text: 'A text' category: 'First Category'.
|
first := TBPost title: 'A title' text: 'A text' category: 'First Category'.
|
||||||
blog writeBlogPost: first.
|
blog writeBlogPost: first.
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ TBBlogTest >> setUp [
|
|||||||
|
|
||||||
{ #category : #running }
|
{ #category : #running }
|
||||||
TBBlogTest >> tearDown [
|
TBBlogTest >> tearDown [
|
||||||
TBBlog reset
|
VORepository setRepository: previousRepository
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #tests }
|
{ #category : #tests }
|
||||||
|
Reference in New Issue
Block a user