From 23401f09fd8422c82e95147446b44a91174d64d9 Mon Sep 17 00:00:00 2001 From: fatchul Date: Wed, 13 Oct 2021 16:28:57 +0700 Subject: [PATCH 1/2] update merge student bussiness logic into one file --- services/student/service.create.go | 31 ---------------- services/student/service.delete.go | 28 --------------- services/student/service.go | 56 +++++++++++++++++++++++++++++ services/student/service.result.go | 28 --------------- services/student/service.results.go | 26 -------------- services/student/service.update.go | 32 ----------------- services/student/usecase.go | 23 ++++++++++++ 7 files changed, 79 insertions(+), 145 deletions(-) delete mode 100644 services/student/service.create.go delete mode 100644 services/student/service.delete.go create mode 100644 services/student/service.go delete mode 100644 services/student/service.result.go delete mode 100644 services/student/service.results.go delete mode 100644 services/student/service.update.go create mode 100644 services/student/usecase.go diff --git a/services/student/service.create.go b/services/student/service.create.go deleted file mode 100644 index dcc3dfa..0000000 --- a/services/student/service.create.go +++ /dev/null @@ -1,31 +0,0 @@ -package student - -import ( - "github.com/restuwahyu13/gin-rest-api/models" - repositorys "github.com/restuwahyu13/gin-rest-api/repositorys/student" - "github.com/restuwahyu13/gin-rest-api/schemas" -) - -type ServiceCreate interface { - CreateStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) -} - -type serviceCreate struct { - repository repositorys.RepositoryCreate -} - -func NewServiceCreate(repository repositorys.RepositoryCreate) *serviceCreate { - return &serviceCreate{repository: repository} -} - -func (s *serviceCreate) CreateStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) { - - var student schemas.SchemaStudent - student.Name = input.Name - student.Npm = input.Npm - student.Fak = input.Fak - student.Bid = input.Bid - - res, err := s.repository.CreateStudentRepository(&student) - return res, err -} diff --git a/services/student/service.delete.go b/services/student/service.delete.go deleted file mode 100644 index cd37854..0000000 --- a/services/student/service.delete.go +++ /dev/null @@ -1,28 +0,0 @@ -package student - -import ( - "github.com/restuwahyu13/gin-rest-api/models" - repositorys "github.com/restuwahyu13/gin-rest-api/repositorys/student" - "github.com/restuwahyu13/gin-rest-api/schemas" -) - -type ServiceDelete interface { - DeleteStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) -} - -type serviceDelete struct { - repository repositorys.RepositoryDelete -} - -func NewServiceDelete(repository repositorys.RepositoryDelete) *serviceDelete { - return &serviceDelete{repository: repository} -} - -func (s *serviceDelete) DeleteStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) { - - var student schemas.SchemaStudent - student.ID = input.ID - - res, err := s.repository.DeleteStudentRepository(&student) - return res, err -} diff --git a/services/student/service.go b/services/student/service.go new file mode 100644 index 0000000..43b455c --- /dev/null +++ b/services/student/service.go @@ -0,0 +1,56 @@ +package student + +import ( + "github.com/restuwahyu13/gin-rest-api/models" + model "github.com/restuwahyu13/gin-rest-api/models" + "github.com/restuwahyu13/gin-rest-api/schemas" +) + +func (s *service) Result(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) { + + var student schemas.SchemaStudent + student.ID = input.ID + + res, err := s.repository.ResultStudentRepository(&student) + return res, err +} + +func (s *service) ResultsStudentService() (*[]model.ModelStudent, schemas.SchemaDatabaseError) { + + res, err := s.repository.ResultsStudentRepository() + return res, err +} + +func (s *service) DeleteStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) { + + var student schemas.SchemaStudent + student.ID = input.ID + + res, err := s.repository.DeleteStudentRepository(&student) + return res, err +} + +func (s *service) CreateStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) { + + var student schemas.SchemaStudent + student.Name = input.Name + student.Npm = input.Npm + student.Fak = input.Fak + student.Bid = input.Bid + + res, err := s.repository.CreateStudentRepository(&student) + return res, err +} + +func (s *service) UpdateStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) { + + var student schemas.SchemaStudent + student.ID = input.ID + student.Name = input.Name + student.Npm = input.Npm + student.Fak = input.Fak + student.Bid = input.Fak + + res, err := s.repository.UpdateStudentRepository(&student) + return res, err +} diff --git a/services/student/service.result.go b/services/student/service.result.go deleted file mode 100644 index 223a0f1..0000000 --- a/services/student/service.result.go +++ /dev/null @@ -1,28 +0,0 @@ -package student - -import ( - "github.com/restuwahyu13/gin-rest-api/models" - repositorys "github.com/restuwahyu13/gin-rest-api/repositorys/student" - "github.com/restuwahyu13/gin-rest-api/schemas" -) - -type ServiceResult interface { - ResultStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) -} - -type serviceResult struct { - repository repositorys.RepositoryResult -} - -func NewServiceResult(repository repositorys.RepositoryResult) *serviceResult { - return &serviceResult{repository: repository} -} - -func (s *serviceResult) ResultStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) { - - var student schemas.SchemaStudent - student.ID = input.ID - - res, err := s.repository.ResultStudentRepository(&student) - return res, err -} diff --git a/services/student/service.results.go b/services/student/service.results.go deleted file mode 100644 index e14b740..0000000 --- a/services/student/service.results.go +++ /dev/null @@ -1,26 +0,0 @@ -package student - -import ( - "github.com/restuwahyu13/gin-rest-api/models" - model "github.com/restuwahyu13/gin-rest-api/models" - repositorys "github.com/restuwahyu13/gin-rest-api/repositorys/student" - "github.com/restuwahyu13/gin-rest-api/schemas" -) - -type ServiceResults interface { - ResultsStudentService() (*[]models.ModelStudent, schemas.SchemaDatabaseError) -} - -type serviceResults struct { - repository repositorys.RepositoryResults -} - -func NewServiceResults(repository repositorys.RepositoryResults) *serviceResults { - return &serviceResults{repository: repository} -} - -func (s *serviceResults) ResultsStudentService() (*[]model.ModelStudent, schemas.SchemaDatabaseError) { - - res, err := s.repository.ResultsStudentRepository() - return res, err -} diff --git a/services/student/service.update.go b/services/student/service.update.go deleted file mode 100644 index 61daa3c..0000000 --- a/services/student/service.update.go +++ /dev/null @@ -1,32 +0,0 @@ -package student - -import ( - "github.com/restuwahyu13/gin-rest-api/models" - repositorys "github.com/restuwahyu13/gin-rest-api/repositorys/student" - "github.com/restuwahyu13/gin-rest-api/schemas" -) - -type ServiceUpdate interface { - UpdateStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) -} - -type serviceUpdate struct { - repository repositorys.RepositoryUpdate -} - -func NewServiceUpdate(repository repositorys.RepositoryUpdate) *serviceUpdate { - return &serviceUpdate{repository: repository} -} - -func (s *serviceUpdate) UpdateStudentService(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) { - - var student schemas.SchemaStudent - student.ID = input.ID - student.Name = input.Name - student.Npm = input.Npm - student.Fak = input.Fak - student.Bid = input.Fak - - res, err := s.repository.UpdateStudentRepository(&student) - return res, err -} diff --git a/services/student/usecase.go b/services/student/usecase.go new file mode 100644 index 0000000..65365f2 --- /dev/null +++ b/services/student/usecase.go @@ -0,0 +1,23 @@ +package student + +import ( + "github.com/restuwahyu13/gin-rest-api/models" + repositorys "github.com/restuwahyu13/gin-rest-api/repositorys/student" + "github.com/restuwahyu13/gin-rest-api/schemas" +) + +type Service interface { + Create(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) + Delete(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) + Result(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) + Results() (*[]models.ModelStudent, schemas.SchemaDatabaseError) + Update(input *schemas.SchemaStudent) (*models.ModelStudent, schemas.SchemaDatabaseError) +} + +type service struct { + repository repositorys.RepositoryCreate +} + +func NewService(repository repositorys.RepositoryCreate) *serviceCreate { + return &serviceCreate{repository: repository} +} From 541953f3fc9a8708a20cd7f5133bb994f3ee863e Mon Sep 17 00:00:00 2001 From: fatchul Date: Thu, 14 Oct 2021 00:00:29 +0700 Subject: [PATCH 2/2] update adding all repos in service --- services/student/service.go | 10 +++++----- services/student/usecase.go | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/services/student/service.go b/services/student/service.go index 43b455c..b6e3f3e 100644 --- a/services/student/service.go +++ b/services/student/service.go @@ -11,13 +11,13 @@ func (s *service) Result(input *schemas.SchemaStudent) (*models.ModelStudent, sc var student schemas.SchemaStudent student.ID = input.ID - res, err := s.repository.ResultStudentRepository(&student) + res, err := s.repositoryResult.ResultStudentRepository(&student) return res, err } func (s *service) ResultsStudentService() (*[]model.ModelStudent, schemas.SchemaDatabaseError) { - res, err := s.repository.ResultsStudentRepository() + res, err := s.repositoryResults.ResultsStudentRepository() return res, err } @@ -26,7 +26,7 @@ func (s *service) DeleteStudentService(input *schemas.SchemaStudent) (*models.Mo var student schemas.SchemaStudent student.ID = input.ID - res, err := s.repository.DeleteStudentRepository(&student) + res, err := s.repositoryDelete.DeleteStudentRepository(&student) return res, err } @@ -38,7 +38,7 @@ func (s *service) CreateStudentService(input *schemas.SchemaStudent) (*models.Mo student.Fak = input.Fak student.Bid = input.Bid - res, err := s.repository.CreateStudentRepository(&student) + res, err := s.repositoryCreate.CreateStudentRepository(&student) return res, err } @@ -51,6 +51,6 @@ func (s *service) UpdateStudentService(input *schemas.SchemaStudent) (*models.Mo student.Fak = input.Fak student.Bid = input.Fak - res, err := s.repository.UpdateStudentRepository(&student) + res, err := s.repositoryUpdate.UpdateStudentRepository(&student) return res, err } diff --git a/services/student/usecase.go b/services/student/usecase.go index 65365f2..a231249 100644 --- a/services/student/usecase.go +++ b/services/student/usecase.go @@ -1,6 +1,7 @@ package student import ( + repositorys "github.com/evermos/trial/go-clean-architecture/repositorys/student" "github.com/restuwahyu13/gin-rest-api/models" repositorys "github.com/restuwahyu13/gin-rest-api/repositorys/student" "github.com/restuwahyu13/gin-rest-api/schemas" @@ -15,9 +16,25 @@ type Service interface { } type service struct { - repository repositorys.RepositoryCreate + repositoryCreate repositorys.RepositoryCreate + repositoryDelete repositorys.RepositoryDelete + repositoryResult repositorys.RepositoryResult + repositoryResults repositorys.RepositoryResults + repositoryUpdate repositorys.RepositoryUpdate } -func NewService(repository repositorys.RepositoryCreate) *serviceCreate { - return &serviceCreate{repository: repository} +func NewService( + repositoryCreate repositorys.RepositoryCreate, + repositoryDelete repositorys.RepositoryDelete, + repositoryResult repositorys.RepositoryResult, + repositoryResults repositorys.RepositoryResults, + repositoryUpdate repositorys.RepositoryUpdate, +) *service { + return &service{ + repositoryCreate: repositoryCreate, + repositoryDelete: repositoryDelete, + repositoryResult: repositoryResult, + repositoryResults: repositoryResults, + repositoryUpdate: repositoryUpdate, + } }