Skip to content

Commit afed01e

Browse files
committed
feat: adjust filtering based on constant type
1 parent 622815b commit afed01e

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

app/events/delivery/http/event.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88

99
"github.com/gorilla/mux"
10+
"github.com/hammer-code/lms-be/constants"
1011
"github.com/hammer-code/lms-be/domain"
1112
"github.com/hammer-code/lms-be/pkg/ngelog"
1213
"github.com/hammer-code/lms-be/utils"
@@ -268,7 +269,7 @@ func (h Handler) List(w http.ResponseWriter, r *http.Request) {
268269

269270
data, pagination, err := h.usecase.GetEvents(r.Context(), domain.EventFilter{
270271
Title: r.URL.Query().Get("title"),
271-
Type: r.URL.Query().Get("type"),
272+
Type: constants.EventType(r.URL.Query().Get("type")),
272273
Status: r.URL.Query().Get("status"),
273274
StartDate: startDate,
274275
EndDate: endDate,
@@ -323,7 +324,7 @@ func (h Handler) GetEvents(w http.ResponseWriter, r *http.Request) {
323324
endDate, _ := utils.ParseDate(r.URL.Query().Get("end_date"))
324325
data, pagination, err := h.usecase.GetEvents(r.Context(), domain.EventFilter{
325326
Title: r.URL.Query().Get("title"),
326-
Type: r.URL.Query().Get("type"),
327+
Type: constants.EventType(r.URL.Query().Get("type")),
327328
Status: r.URL.Query().Get("status"),
328329
StartDate: startDate,
329330
EndDate: endDate,

app/events/delivery/http/list_registration.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package http
33
import (
44
"net/http"
55

6+
"github.com/hammer-code/lms-be/constants"
67
"github.com/hammer-code/lms-be/domain"
78
"github.com/hammer-code/lms-be/pkg/ngelog"
89
"github.com/hammer-code/lms-be/utils"
@@ -20,6 +21,7 @@ import (
2021
// @Param start_date query string false "string"
2122
// @Param end_date query string false "string"
2223
// @Param status query string false "string"
24+
// @Param type query string false "string"
2325
// @Failure 400 {object} domain.HttpResponse
2426
// @Failure 500 {object} domain.HttpResponse
2527
// @Success 200 {object} []domain.RegistrationEvent
@@ -39,6 +41,7 @@ func (h Handler) ListRegistration(w http.ResponseWriter, r *http.Request) {
3941

4042
data, pagination, err := h.usecase.ListRegistration(r.Context(), domain.EventFilter{
4143
Status: r.URL.Query().Get("status"),
44+
Type: constants.EventType(r.URL.Query().Get("type")),
4245
StartDate: startDate,
4346
EndDate: endDate,
4447
FilterPagination: flterPagination,

app/events/repository/list_registration.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ func (repo *repository) ListRegistration(ctx context.Context, filter domain.Even
1616
db = db.Where("registration_events.status = ?", filter.Status)
1717
}
1818

19+
if filter.Type != "" {
20+
db = db.Joins("JOIN events ON events.id = registration_events.event_id").
21+
Where("events.type = ?", filter.Type)
22+
}
23+
1924
if filter.StartDate.Valid {
2025
db = db.Where("registration_events.created_at >= ?", filter.StartDate)
2126
}

domain/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ type UpdateEvenPayload struct {
186186
type EventFilter struct {
187187
ID uint
188188
Title string
189-
Type string
189+
Type constants.EventType
190190
Status string
191191
StartDate null.Time
192192
EndDate null.Time

0 commit comments

Comments
 (0)