Add paste service with ability to create paste
parent
6b58d28547
commit
dddd9bbe8e
|
@ -0,0 +1,29 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"github.com/ollien/updown/repository"
|
||||
)
|
||||
|
||||
// PasteService is a service to produce pastes
|
||||
type PasteService struct {
|
||||
db repository.PasteRepository
|
||||
pasteDir string
|
||||
}
|
||||
|
||||
// NewPasteService makes a new PasteService
|
||||
func NewPasteService() *PasteService {
|
||||
return initPasteService()
|
||||
}
|
||||
|
||||
// CreatePaste makes a new paste to be stored
|
||||
func (service PasteService) CreatePaste(title string) (Paster, error) {
|
||||
paste, err := service.db.PutPaste(title)
|
||||
if err != nil {
|
||||
return Paster{}, err
|
||||
}
|
||||
|
||||
return Paster{
|
||||
Paste: paste,
|
||||
pasteDir: service.pasteDir,
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate wire
|
||||
//+build !wireinject
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/ollien/updown/config"
|
||||
"github.com/ollien/updown/repository"
|
||||
)
|
||||
|
||||
// Injectors from wire_stubs.go:
|
||||
|
||||
func initPasteService() *PasteService {
|
||||
configConfig := config.Get()
|
||||
databaseConnector := repository.GetConnector()
|
||||
pasteRepository := providePasteRepository(databaseConnector)
|
||||
pasteService := providePasteService(configConfig, pasteRepository)
|
||||
return pasteService
|
||||
}
|
||||
|
||||
// wire_stubs.go:
|
||||
|
||||
func providePasteService(appConfig config.Config, repo repository.PasteRepository) *PasteService {
|
||||
return &PasteService{
|
||||
db: repo,
|
||||
pasteDir: appConfig.StoragePath,
|
||||
}
|
||||
}
|
||||
|
||||
func providePasteRepository(db *repository.DatabaseConnector) repository.PasteRepository {
|
||||
return repository.PasteRepository(db)
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
//+build wireinject
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
"github.com/ollien/updown/config"
|
||||
"github.com/ollien/updown/repository"
|
||||
)
|
||||
|
||||
// initPasteService is generated by wire. Please see wire_gen.go for the generated implementation
|
||||
func initPasteService() *PasteService {
|
||||
wire.Build(providePasteService, providePasteRepository, repository.GetConnector, config.Get)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func providePasteService(appConfig config.Config, repo repository.PasteRepository) *PasteService {
|
||||
return &PasteService{
|
||||
db: repo,
|
||||
pasteDir: appConfig.StoragePath,
|
||||
}
|
||||
}
|
||||
|
||||
func providePasteRepository(db *repository.DatabaseConnector) repository.PasteRepository {
|
||||
return repository.PasteRepository(db)
|
||||
}
|
Loading…
Reference in New Issue