From 2ce59c6097bfb47429117b7e00cb218a5a5aa80c Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Thu, 1 Jun 2017 16:18:21 +0000 Subject: [PATCH] Members persistance in local storage done. Next steps: Repo sincronization, info update and queries. --- repository/Brea/BreaMember.class.st | 17 ++++++++ repository/Brea/BreaWebsite.class.st | 63 ++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/repository/Brea/BreaMember.class.st b/repository/Brea/BreaMember.class.st index 6758e62..07e8c98 100644 --- a/repository/Brea/BreaMember.class.st +++ b/repository/Brea/BreaMember.class.st @@ -104,6 +104,11 @@ BreaMember >> familyName: anObject [ familyName := anObject ] +{ #category : #helpers } +BreaMember >> fullName [ + ^ self givenName asLowercase, '-', self familyName asLowercase +] + { #category : #accessing } BreaMember >> getGenericProfilePicture [ "Other considered avatars where: @@ -393,6 +398,18 @@ BreaMember >> renderTestUserAsHtml [ ^ self class new createTestUser html ] +{ #category : #'server handling' } +BreaMember >> storeInto: aFileDirectory [ + | folder file | + folder := (aFileDirectory asFileReference / self fullName) ensureCreateDirectory. + file := (folder / 'info.ston') ensureCreateFile. + file writeStreamDo: [:stream | + (STON writer on: stream) + newLine: String crlf; + prettyPrint: true; + nextPut: self] +] + { #category : #accessing } BreaMember >> tags [ ^ tags diff --git a/repository/Brea/BreaWebsite.class.st b/repository/Brea/BreaWebsite.class.st index 8baacd4..9419aa4 100644 --- a/repository/Brea/BreaWebsite.class.st +++ b/repository/Brea/BreaWebsite.class.st @@ -14,12 +14,36 @@ Class { { #category : #accessing } BreaWebsite >> fossilRepo [ - ^ fossilRepo + ^ fossilRepo ifNil: [ fossilRepo := FossilRepo new ] ] { #category : #accessing } -BreaWebsite >> fossilRepo: anObject [ - fossilRepo := anObject +BreaWebsite >> fossilRepo: aFossilRepo [ + fossilRepo := aFossilRepo +] + +{ #category : #utility } +BreaWebsite >> local [ + ^ self fossilRepo local +] + +{ #category : #'server handling' } +BreaWebsite >> local: aFilePath [ + "I define the local storage of the Fossil repository. + For the moment aFilePath must be an absolute " + | localSite | + aFilePath asFileReference exists + ifFalse: [ + localSite := (FileLocator temp / 'breaSite') ensureCreateDirectory. + self fossilRepo local: localSite fullName ] + ifTrue: [ self fossilRepo local: aFilePath ]. +] + +{ #category : #'server handling' } +BreaWebsite >> local: aFilePath remote: anUrl [ + "I define the local and remote storages of the Fossil repository" + self remote: anUrl. + self local: aFilePath ] { #category : #'input processing' } @@ -40,17 +64,24 @@ BreaWebsite >> processNewMember: request [ twitter: (request at: #twitter); facebook: (request at: #facebook); tags: (request at: #tags). - ^ member asStonModified + self store: member. + ^ 'New member stored!' +] + +{ #category : #'server handling' } +BreaWebsite >> remote: anUrl [ + "I define the remote storage of the Fossil repository" + self remote: anUrl. ] { #category : #'server handling' } BreaWebsite >> routes [ "I define how the website behaves accordingly to particular routes." self server - serveStatic: '/gig/demo' from: '/opt/gig/'; - GET: '/gig/members/test' -> [ :req | BreaMember new renderTestUserAsHtml ]; - GET: '/gig/members/add' -> [ :req | BreaMember new htmlInput ]; - POST: '/gig/members/summit' -> [ :req | self processNewMember: req ] + serveStatic: 'demo' from: '/opt/gig/'; + GET: 'members/test' -> [ :req | BreaMember new renderTestUserAsHtml ]; + GET: 'members/add' -> [ :req | BreaMember new htmlInput ]; + POST: 'members/summit' -> [ :req | self processNewMember: req ] ] { #category : #accessing } @@ -75,3 +106,19 @@ BreaWebsite >> stop [ "I define the routes and start the server" self server class stopAll ] + +{ #category : #'server handling' } +BreaWebsite >> storageFor: anObject [ + "I define the places where local storage is done for several types of objects" + anObject class = BreaMember + ifTrue: [ ^ self local asFileReference / 'members' ]. + ^ self +] + +{ #category : #'server handling' } +BreaWebsite >> store: anObject [ + "I store different kind of objects in the website repository. + For the moment I will only store BreaMembers, but as long as new + objects will emerge, I will specialize other ways of storage." + anObject storeInto: (self storageFor: anObject) +]