Example #1
0
func saveHandler(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()

	if err != nil {
		log.Fatal(err)
		http.Redirect(w, r, "/", 302)
	}

	page := new(PageInput)
	err = decoder.Decode(page, r.PostForm)

	if err != nil {
		log.Fatal(err)
		http.Redirect(w, r, "/", 302)
	}

	SaveWiki := usecase.SaveWikipage{repo}
	SaveWiki.Execute(page.Title, []byte(page.Body))

	http.Redirect(w, r, "/view/"+page.Title, 302)
}
Example #2
0
		repo.Pages = make(map[string]*entity.Page)

		saveWikipage = usecase.SaveWikipage{repo}
		loadWikipage = usecase.LoadWikipage{repo}
		getAllWikipages = usecase.GetAllWikipages{repo}
	})

	Context("Usecase API", func() {
		It("should return 0 pages if trying to find all when none exist", func() {
			pages, err := getAllWikipages.Execute()
			Expect(err).To(BeNil())
			Expect(len(pages)).To(Equal(0))
		})

		It("Saving page with title 'A page' should be available to find", func() {
			saveWikipage.Execute("A page", []byte("body"))
			page, err := loadWikipage.Execute("A page")
			Expect(err).To(BeNil())
			Expect(page.Title).To(Equal("A page"))
		})

		It("should return 1 page of trying to find all when 1 has been created", func() {
			saveWikipage.Execute("A page", []byte("body"))
			pages, err := getAllWikipages.Execute()
			Expect(err).To(BeNil())
			Expect(len(pages)).To(Equal(1))
		})
	})

})
Example #3
0
func setup() {
	repo.Pages = make(map[string]*entity.Page)
	SaveWikipageUseCase := usecase.SaveWikipage{repo}
	SaveWikipageUseCase.Execute("A page", []byte("body"))
}