Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update merge student bussiness logic into one file #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions services/student/service.create.go

This file was deleted.

28 changes: 0 additions & 28 deletions services/student/service.delete.go

This file was deleted.

56 changes: 56 additions & 0 deletions services/student/service.go
Original file line number Diff line number Diff line change
@@ -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.repositoryResult.ResultStudentRepository(&student)
return res, err
}

func (s *service) ResultsStudentService() (*[]model.ModelStudent, schemas.SchemaDatabaseError) {

res, err := s.repositoryResults.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.repositoryDelete.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.repositoryCreate.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.repositoryUpdate.UpdateStudentRepository(&student)
return res, err
}
28 changes: 0 additions & 28 deletions services/student/service.result.go

This file was deleted.

26 changes: 0 additions & 26 deletions services/student/service.results.go

This file was deleted.

32 changes: 0 additions & 32 deletions services/student/service.update.go

This file was deleted.

40 changes: 40 additions & 0 deletions services/student/usecase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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"
)

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 {
repositoryCreate repositorys.RepositoryCreate
repositoryDelete repositorys.RepositoryDelete
repositoryResult repositorys.RepositoryResult
repositoryResults repositorys.RepositoryResults
repositoryUpdate repositorys.RepositoryUpdate
}

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,
}
}