Skip to content

Commit ebebc08

Browse files
committed
feat(event): list event pay
1 parent 6a398ec commit ebebc08

5 files changed

Lines changed: 144 additions & 5 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package http
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"strconv"
7+
8+
"github.com/hammer-code/lms-be/domain"
9+
"github.com/hammer-code/lms-be/utils"
10+
"github.com/sirupsen/logrus"
11+
)
12+
13+
func (h Handler) ListEventPay(w http.ResponseWriter, r *http.Request) {
14+
fmt.Println(111)
15+
flterPagination, err := domain.GetPaginationFromCtx(r)
16+
if err != nil {
17+
logrus.Error("failed to get pagination : ", err)
18+
utils.Response(domain.HttpResponse{
19+
Code: 500,
20+
Message: err.Error(),
21+
}, w)
22+
return
23+
}
24+
25+
startDate, _ := utils.ParseDate(r.URL.Query().Get("start_date"))
26+
endDate, _ := utils.ParseDate(r.URL.Query().Get("end_date"))
27+
28+
eventIDs := r.URL.Query().Get("event_id")
29+
30+
var eventID uint
31+
if eventIDs != "" {
32+
eventIDU, err := strconv.ParseUint(eventIDs, 10, 32)
33+
if err != nil {
34+
logrus.Error("failed to convert string to uint: ", err)
35+
utils.Response(domain.HttpResponse{
36+
Code: 500,
37+
Message: err.Error(),
38+
}, w)
39+
return
40+
}
41+
42+
eventID = uint(eventIDU)
43+
}
44+
45+
data, pagination, err := h.usecase.ListEventPay(r.Context(), domain.EventFilter{
46+
ID: eventID,
47+
Status: r.URL.Query().Get("status"),
48+
StartDate: startDate,
49+
EndDate: endDate,
50+
FilterPagination: flterPagination,
51+
})
52+
53+
if err != nil {
54+
logrus.Error("failed to list event : ", err)
55+
utils.Response(domain.HttpResponse{
56+
Code: 500,
57+
Message: err.Error(),
58+
}, w)
59+
return
60+
}
61+
62+
utils.Response(domain.HttpResponse{
63+
Code: 200,
64+
Message: "success",
65+
Data: data,
66+
Pagination: pagination,
67+
}, w)
68+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package repository
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hammer-code/lms-be/domain"
8+
"github.com/sirupsen/logrus"
9+
)
10+
11+
func (repo *repository) ListEventPay(ctx context.Context, filter domain.EventFilter) (tData int, data []domain.EventPay, err error) {
12+
db := repo.db.DB(ctx).Model(&domain.EventPay{})
13+
14+
var totalData int64
15+
16+
if filter.ID != 0 {
17+
db = db.Where("event_id = ?", filter.ID)
18+
}
19+
20+
if filter.Status != "" {
21+
db = db.Where("status = ?", filter.Status)
22+
}
23+
24+
if filter.StartDate.Valid {
25+
db = db.Where("start_date > ?", filter.StartDate)
26+
}
27+
28+
if filter.StartDate.Valid {
29+
db = db.Where("end_date < ?", filter.EndDate)
30+
}
31+
32+
db.Count(&totalData)
33+
34+
fmt.Println(23)
35+
36+
err = db.Limit(filter.FilterPagination.GetLimit()).
37+
Offset(filter.FilterPagination.GetOffset()).
38+
Preload("RegistrationEvent").Find(&data).Error
39+
if err != nil {
40+
logrus.Error("repo.GetEvents: failed to get event pays use generic conditions")
41+
return
42+
}
43+
44+
return int(totalData), data, err
45+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package usecase
2+
3+
import (
4+
"context"
5+
6+
"github.com/hammer-code/lms-be/domain"
7+
"github.com/sirupsen/logrus"
8+
)
9+
10+
func (uc usecase) ListEventPay(ctx context.Context, filter domain.EventFilter) (resp []domain.EventPay, pagination domain.Pagination, err error) {
11+
tData, datas, err := uc.repository.ListEventPay(ctx, filter)
12+
if err != nil {
13+
logrus.Error("failed to list event pay")
14+
return
15+
}
16+
17+
return datas, domain.NewPagination(tData, filter.FilterPagination), err
18+
}

cmd/serve_http.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ func registerHandler(app app.App) *mux.Router {
152152
protectedV1Route.HandleFunc("/events", app.EventHandler.CreateEvent).Methods(http.MethodPost)
153153
protectedV1Route.HandleFunc("/events", app.EventHandler.GetEvents).Methods(http.MethodGet)
154154
protectedV1Route.HandleFunc("/events/registrations", app.EventHandler.ListRegistration).Methods(http.MethodGet)
155+
protectedV1Route.HandleFunc("/events/pays", app.EventHandler.ListEventPay).Methods(http.MethodGet)
155156
protectedV1Route.HandleFunc("/events/{id}", app.EventHandler.GetEventByID).Methods(http.MethodGet)
156157
protectedV1Route.HandleFunc("/images", app.ImageHandler.UploadImage).Methods(http.MethodPost)
158+
// protectedV1Route.HandleFunc("/events/pays", app.EventHandler.GetEvents).Methods(http.MethodPost)
157159

158160
return router
159161
}

domain/event.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type EventRepository interface {
2222
GetEvent(ctx context.Context, eventID uint) (data Event, err error)
2323
GetRegistrationEvent(ctx context.Context, orderNo string) (data RegistrationEvent, err error)
2424
ListRegistration(ctx context.Context, filter EventFilter) (tData int, data []RegistrationEvent, err error)
25+
ListEventPay(ctx context.Context, filter EventFilter) (tData int, data []EventPay, err error)
2526
}
2627

2728
type EventUsecase interface {
@@ -32,6 +33,7 @@ type EventUsecase interface {
3233
GetEventByID(ctx context.Context, id uint) (resp Event, err error)
3334
RegistrationStatus(ctx context.Context, orderNo string) (resp RegisterStatusResponse, err error)
3435
ListRegistration(ctx context.Context, filter EventFilter) (resp []RegistrationEvent, pagination Pagination, err error)
36+
ListEventPay(ctx context.Context, filter EventFilter) (data []EventPay, pagination Pagination, err error)
3537
}
3638

3739
type EventHandler interface {
@@ -42,6 +44,8 @@ type EventHandler interface {
4244
GetEventByID(w http.ResponseWriter, r *http.Request)
4345
RegistrationStatus(w http.ResponseWriter, r *http.Request)
4446
ListRegistration(w http.ResponseWriter, r *http.Request)
47+
ListEventPay(w http.ResponseWriter, r *http.Request)
48+
// ApproveEventPay(w http.ResponseWriter, r *http.Request)
4549
}
4650

4751
type Event struct {
@@ -151,11 +155,13 @@ type EventFilter struct {
151155
}
152156

153157
type EventPay struct {
154-
ID uint `json:"id" gorm:"primarykey"`
155-
RegistrationEventID uint `json:"registration_event_id"`
156-
EventID uint `json:"event_id"`
157-
ImageProofPayment string `json:"image_proof_payment"`
158-
NetAmount float64 `json:"net_amount"`
158+
ID uint `json:"id" gorm:"primarykey"`
159+
RegistrationEventID uint `json:"registration_event_id"`
160+
EventID uint `json:"event_id"`
161+
ImageProofPayment string `json:"image_proof_payment"`
162+
NetAmount float64 `json:"net_amount"`
163+
Status string `json:"status"`
164+
RegistrationEvent RegistrationEvent `json:"registration_event" gorm:"foreignKey:RegistrationEventID"`
159165
}
160166

161167
func (EventPay) TableName() string {

0 commit comments

Comments
 (0)