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
import (
	"github.com/sebber/go-wiki-core/entity"
	"github.com/sebber/go-wiki-core/repository"
	"github.com/sebber/go-wiki-core/usecase"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Wikipage", func() {

	var (
		repo repository.MemoryWikipageRepository

		saveWikipage    usecase.SaveWikipage
		loadWikipage    usecase.LoadWikipage
		getAllWikipages usecase.GetAllWikipages
	)

	BeforeEach(func() {
		repo = repository.MemoryWikipageRepository{}
		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() {
Example #3
0
func setup() {
	repo.Pages = make(map[string]*entity.Page)
	SaveWikipageUseCase := usecase.SaveWikipage{repo}
	SaveWikipageUseCase.Execute("A page", []byte("body"))
}