-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
101 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package gorm_crud | ||
|
||
import ( | ||
"github.com/jinzhu/gorm" | ||
) | ||
|
||
type BaseRepositoryInterface interface { | ||
} | ||
|
||
type BaseRepository struct { | ||
BaseRepositoryInterface | ||
db *gorm.DB | ||
logger LoggerInterface | ||
} | ||
|
||
func NewBaseRepository(db *gorm.DB, logger LoggerInterface) BaseRepositoryInterface { | ||
return &BaseRepository{db: db, logger: logger} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gorm_crud | ||
|
||
type BaseServiceInterface interface { | ||
} | ||
|
||
type BaseService struct { | ||
BaseServiceInterface | ||
repository BaseRepositoryInterface | ||
logger LoggerInterface | ||
} | ||
|
||
func NewBaseService(repository BaseRepositoryInterface, logger LoggerInterface) *BaseService { | ||
return &BaseService{repository: repository, logger: logger} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package entity | ||
package gorm_crud | ||
|
||
type InterfaceEntity interface { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package gorm_crud | ||
|
||
type CrudServiceInterface interface { | ||
BaseServiceInterface | ||
GetModel() InterfaceEntity | ||
GetItem(id uint) (InterfaceEntity, error) | ||
GetList(parameters ListParametersInterface) ([]InterfaceEntity, error) | ||
Create(item InterfaceEntity) InterfaceEntity | ||
Update(item InterfaceEntity) InterfaceEntity | ||
Delete(id uint) error | ||
} | ||
|
||
type CrudService struct { | ||
*BaseService | ||
repository CrudRepositoryInterface | ||
} | ||
|
||
func NewCrudService(repository CrudRepositoryInterface, logger LoggerInterface) CrudServiceInterface { | ||
service := NewBaseService(repository, logger) | ||
return &CrudService{service, repository} | ||
} | ||
|
||
func (c CrudService) GetModel() InterfaceEntity { | ||
return c.repository.GetModel() | ||
} | ||
|
||
func (c CrudService) GetItem(id uint) (InterfaceEntity, error) { | ||
return c.repository.Find(id) | ||
} | ||
|
||
func (c CrudService) GetList(parameters ListParametersInterface) ([]InterfaceEntity, error) { | ||
return c.repository.List(parameters) | ||
} | ||
|
||
func (c CrudService) Create(item InterfaceEntity) InterfaceEntity { | ||
return c.repository.Create(item) | ||
} | ||
|
||
func (c CrudService) Update(item InterfaceEntity) InterfaceEntity { | ||
return c.repository.Update(item) | ||
} | ||
|
||
func (c CrudService) Delete(id uint) error { | ||
return c.repository.Delete(id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package common | ||
package gorm_crud | ||
|
||
type LoggerInterface interface { | ||
Error(message string) | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.