add repositories and fixed services

This commit is contained in:
Fran Jurmanović
2022-10-07 23:48:35 +02:00
parent 82e97fc97f
commit ec863d55b3
36 changed files with 703 additions and 497 deletions

View File

@@ -14,7 +14,7 @@ type SubscriptionTypeService struct {
func NewSubscriptionTypeService(repository *repository.SubscriptionTypeRepository) *SubscriptionTypeService {
return &SubscriptionTypeService{
repository,
repository: repository,
}
}
@@ -30,14 +30,9 @@ Inserts new row to subscription type table.
*model.SubscriptionType: Created row from database.
*model.Exception: Exception payload.
*/
func (as *SubscriptionTypeService) New(ctx context.Context, body *model.NewSubscriptionTypeBody) (*model.SubscriptionType, *model.Exception) {
tm := new(model.SubscriptionType)
func (as *SubscriptionTypeService) New(ctx context.Context, tm *model.SubscriptionType) (*model.SubscriptionType, *model.Exception) {
exceptionReturn := new(model.Exception)
tm.Init()
tm.Name = body.Name
tm.Type = body.Type
response, err := as.repository.New(ctx, tm)
if err != nil {
exceptionReturn.StatusCode = 400
@@ -61,14 +56,10 @@ Gets all rows from subscription type table.
*[]model.SubscriptionType: List of subscription type objects.
*model.Exception: Exception payload.
*/
func (as *SubscriptionTypeService) GetAll(ctx context.Context, embed string) (*[]model.SubscriptionType, *model.Exception) {
wm := new([]model.SubscriptionType)
func (as *SubscriptionTypeService) GetAll(ctx context.Context, flt *filter.SubscriptionTypeFilter) (*[]model.SubscriptionType, *model.Exception) {
exceptionReturn := new(model.Exception)
flt := filter.NewSubscriptionTypeFilter(model.Params{
Embed: embed,
})
response, err := as.repository.GetAll(ctx, flt, wm)
response, err := as.repository.GetAll(ctx, flt)
if err != nil {
exceptionReturn.StatusCode = 400
exceptionReturn.ErrorCode = "400135"