-
Notifications
You must be signed in to change notification settings - Fork 0
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
39 changed files
with
1,299 additions
and
77 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 |
---|---|---|
|
@@ -3,3 +3,5 @@ lms-be | |
tmp | ||
|
||
main | ||
|
||
uploads |
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,48 @@ | ||
package http | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/hammer-code/lms-be/utils" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (h Handler) CreateEvent(w http.ResponseWriter, r *http.Request) { | ||
bodyBytes, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
logrus.Error("failed to read body : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
|
||
var payload domain.CreateEvenPayload | ||
if err := json.Unmarshal(bodyBytes, &payload); err != nil { | ||
logrus.Error("failed to unmarshal : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
err = h.usecase.CreateEvent(r.Context(), payload) | ||
if err != nil { | ||
logrus.Error("failed to Create event : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
|
||
utils.Response(domain.HttpResponse{ | ||
Code: 201, | ||
Message: "success", | ||
Data: nil, | ||
}, w) | ||
} |
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,23 @@ | ||
package http | ||
|
||
import ( | ||
"github.com/hammer-code/lms-be/domain" | ||
) | ||
|
||
type Handler struct { | ||
usecase domain.EventUsecase | ||
} | ||
|
||
var ( | ||
handlr *Handler | ||
) | ||
|
||
func NewHandler(usecase domain.EventUsecase) domain.EventHandler { | ||
if handlr == nil { | ||
handlr = &Handler{ | ||
usecase: usecase, | ||
} | ||
} | ||
|
||
return *handlr | ||
} |
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,41 @@ | ||
package http | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/hammer-code/lms-be/utils" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (h Handler) GetEvents(w http.ResponseWriter, r *http.Request) { | ||
flterPagination, err := domain.GetPaginationFromCtx(r) | ||
|
||
startDate, _ := utils.ParseDate(r.URL.Query().Get("start_date")) | ||
endDate, _ := utils.ParseDate(r.URL.Query().Get("end_date")) | ||
|
||
data, pagination, err := h.usecase.GetEvents(r.Context(), domain.EventFilter{ | ||
Title: r.URL.Query().Get("title"), | ||
Type: r.URL.Query().Get("type"), | ||
Status: r.URL.Query().Get("status"), | ||
StartDate: startDate, | ||
EndDate: endDate, | ||
FilterPagination: flterPagination, | ||
}) | ||
|
||
if err != nil { | ||
logrus.Error("failed to get event : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
|
||
utils.Response(domain.HttpResponse{ | ||
Code: 200, | ||
Message: "success", | ||
Data: data, | ||
Pagination: pagination, | ||
}, w) | ||
} |
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,48 @@ | ||
package http | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/hammer-code/lms-be/utils" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (h Handler) PayEvent(w http.ResponseWriter, r *http.Request) { | ||
bodyBytes, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
logrus.Error("failed to read body : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
|
||
var payload domain.EventPayPayload | ||
if err := json.Unmarshal(bodyBytes, &payload); err != nil { | ||
logrus.Error("failed to unmarshal : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
err = h.usecase.CreatePayEvent(r.Context(), payload) | ||
if err != nil { | ||
logrus.Error("failed to Create pay event : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
|
||
utils.Response(domain.HttpResponse{ | ||
Code: 201, | ||
Message: "success", | ||
Data: nil, | ||
}, w) | ||
} |
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,48 @@ | ||
package http | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/hammer-code/lms-be/utils" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (h Handler) RegisterEvent(w http.ResponseWriter, r *http.Request) { | ||
bodyBytes, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
logrus.Error("failed to read body : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
|
||
var payload domain.RegisterEventPayload | ||
if err := json.Unmarshal(bodyBytes, &payload); err != nil { | ||
logrus.Error("failed to unmarshal : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
data, err := h.usecase.CreateRegisterEvent(r.Context(), payload) | ||
if err != nil { | ||
logrus.Error("failed to Create event : ", err) | ||
utils.Response(domain.HttpResponse{ | ||
Code: 500, | ||
Message: err.Error(), | ||
}, w) | ||
return | ||
} | ||
|
||
utils.Response(domain.HttpResponse{ | ||
Code: 201, | ||
Message: "success", | ||
Data: data, | ||
}, w) | ||
} |
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,21 @@ | ||
package events | ||
|
||
import ( | ||
handler_http "github.com/hammer-code/lms-be/app/events/delivery/http" | ||
repository "github.com/hammer-code/lms-be/app/events/repository" | ||
usecase "github.com/hammer-code/lms-be/app/events/usecase" | ||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/hammer-code/lms-be/pkg/db" | ||
) | ||
|
||
func InitRepository(db db.DatabaseTransaction) domain.EventRepository { | ||
return repository.NewRepository(db) | ||
} | ||
|
||
func InitUsecase(repository domain.EventRepository, imageRepository domain.ImageRepository, dbTX db.DatabaseTransaction) domain.EventUsecase { | ||
return usecase.NewUsecase(repository, imageRepository, dbTX) | ||
} | ||
|
||
func InitHandler(uc domain.EventUsecase) domain.EventHandler { | ||
return handler_http.NewHandler(uc) | ||
} |
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,17 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (r repository) CreateEvent(ctx context.Context, event domain.Event) (uint, error) { | ||
err := repo.db.DB(ctx).Create(&event).Error | ||
if err != nil { | ||
logrus.Error("failed to create event") | ||
return 0, err | ||
} | ||
return event.ID, nil | ||
} |
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,17 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (r repository) CreateEventSpeaker(ctx context.Context, data domain.EventSpeaker) (uint, error) { | ||
err := repo.db.DB(ctx).Create(&data).Error | ||
if err != nil { | ||
logrus.Error("failed to create event tag") | ||
return 0, err | ||
} | ||
return data.ID, nil | ||
} |
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,17 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (r repository) CreateEventTag(ctx context.Context, data domain.EventTag) (uint, error) { | ||
err := repo.db.DB(ctx).Create(&data).Error | ||
if err != nil { | ||
logrus.Error("failed to create event tag") | ||
return 0, err | ||
} | ||
return data.ID, nil | ||
} |
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,17 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (r repository) CreatePayEvent(ctx context.Context, event domain.EventPay) (uint, error) { | ||
err := repo.db.DB(ctx).Create(&event).Error | ||
if err != nil { | ||
logrus.Error("failed to create event") | ||
return 0, err | ||
} | ||
return event.ID, nil | ||
} |
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,17 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hammer-code/lms-be/domain" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (r repository) CreateRegisterEvent(ctx context.Context, event domain.RegistrationEvent) (uint, error) { | ||
err := repo.db.DB(ctx).Create(&event).Error | ||
if err != nil { | ||
logrus.Error("failed to create event") | ||
return 0, err | ||
} | ||
return event.ID, nil | ||
} |
Oops, something went wrong.