Skip to content

Commit 50a5cba

Browse files
authored
Merge pull request #27 from hammercode-dev/BE-15/add-endpoint-get-admin-events
Be 15/add endpoint get admin events
2 parents 931532b + 58f5021 commit 50a5cba

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

app/events/usecase/get_event_general.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ func (uc usecase) GetEventByID(ctx context.Context, id uint) (resp domain.EventD
1818
baseURL := config.GetConfig().BaseURL
1919

2020
event.Image = fmt.Sprintf("%s/api/v1/public/storage/images/%s", baseURL, event.Image)
21-
return resp, err
21+
22+
return event.ToDTO(), err
2223
}

app/events/usecase/update_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func (uc usecase) UpdateEvent(ctx context.Context, id uint, payload domain.Updat
3636
Price: payload.Price,
3737
ReservationStartDate: payload.ReservationStartDate,
3838
ReservationEndDate: payload.ReservationEndDate,
39+
SessionType: payload.SessionType,
3940
UpdatedAt: null.TimeFrom(time.Now()),
4041
})
4142
if err != nil {

app/users/repository/find_users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (repo *repository) FindByEmail(ctx context.Context, email string) (user dom
1717
}
1818

1919
func (repo *repository) FindById(ctx context.Context, id int8) (user domain.User, err error) {
20-
err = repo.db.DB(ctx).Select("id", "username", "email", "role", "fullname", "date_of_birth", "gender", "phone_number", "address", "github", "linkedin", "personal_web").Where("id = ?", id).Take(&user).Error
20+
err = repo.db.DB(ctx).Select("id", "username", "email", "role", "fullname", "date_of_birth", "gender", "phone_number", "address", "github_url", "linkedin_url", "personal_web_url").Where("id = ?", id).Take(&user).Error
2121
if err != nil {
2222
logrus.Error("repo.FindById: failed to find user")
2323
return

cmd/serve_http.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ func registerHandler(app app.App) *mux.Router {
170170
protectedV1Route.HandleFunc("/update", app.UserHandler.UpdateProfileUser).Methods(http.MethodPut)
171171
protectedV1Route.HandleFunc("/delete", app.UserHandler.DeleteUser).Methods(http.MethodDelete)
172172

173-
protectedV1Route.HandleFunc("/events", app.EventHandler.CreateEvent).Methods(http.MethodPost)
173+
// protectedV1Route.HandleFunc("/events", app.EventHandler.CreateEvent).Methods(http.MethodPost)
174+
protectedV1Route.HandleFunc("/events", app.EventHandler.GetEvents).Methods(http.MethodGet)
174175
protectedV1Route.HandleFunc("/events/registrations", app.EventHandler.RegisterEvent).Methods(http.MethodPost)
175176
protectedV1Route.HandleFunc("/events/registrations", app.EventHandler.ListRegistration).Methods(http.MethodGet)
176177
protectedV1Route.HandleFunc("/events/pays", app.EventHandler.ListEventPay).Methods(http.MethodGet)
@@ -188,11 +189,12 @@ func registerHandler(app app.App) *mux.Router {
188189
protectedV1Route.HandleFunc("/blogs/{id}", app.BlogPostHandler.UpdateBlogPost).Methods(http.MethodPatch)
189190
protectedV1Route.HandleFunc("/blogs/{id}", app.BlogPostHandler.DeleteBlogPost).Methods(http.MethodDelete)
190191

191-
protectedV1AdminRoute.HandleFunc("/events", app.EventHandler.CreateEvent).Methods(http.MethodPost)
192-
protectedV1Route.HandleFunc("/events", app.EventHandler.GetEvents).Methods(http.MethodGet)
192+
// Admin Route
193+
protectedV1AdminRoute.HandleFunc("/events", app.EventHandler.GetEvents).Methods(http.MethodGet)
194+
protectedV1AdminRoute.HandleFunc("/events/{id}", app.EventHandler.UpdateEvent).Methods(http.MethodPut)
193195
protectedV1AdminRoute.HandleFunc("/events/{id}", app.EventHandler.DeleteEvent).Methods(http.MethodDelete)
196+
protectedV1AdminRoute.HandleFunc("/events", app.EventHandler.CreateEvent).Methods(http.MethodPost)
194197
protectedV1AdminRoute.HandleFunc("/events/{id}", app.EventHandler.GetDetail).Methods(http.MethodGet)
195-
196198
protectedV1AdminRoute.HandleFunc("/users", app.UserHandler.GetUsers).Methods(http.MethodGet)
197199

198200
return router

domain/event.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type EventHandler interface {
5858
ListRegistration(w http.ResponseWriter, r *http.Request)
5959
ListEventPay(w http.ResponseWriter, r *http.Request)
6060
PayProcess(w http.ResponseWriter, r *http.Request)
61+
UpdateEvent(w http.ResponseWriter, r *http.Request)
6162
}
6263

6364
type Event struct {
@@ -87,6 +88,7 @@ type Event struct {
8788
UpdatedAt null.Time `json:"-"`
8889
DeletedAt null.Time `json:"-"`
8990
AdditionalLink string `json:"additional_link"`
91+
SessionType string `json:"session_type"`
9092
}
9193

9294
func (Event) TableName() string {
@@ -133,6 +135,7 @@ type CreateEventPayload struct {
133135
ReservationStartDate null.Time `json:"reservation_start_date"`
134136
ReservationEndDate null.Time `json:"reservation_end_date"`
135137
AdditionalLink string `json:"additional_link"`
138+
SessionType string `json:"session_type"`
136139
}
137140

138141
type UpdateEventPayload struct {
@@ -155,6 +158,7 @@ type UpdateEventPayload struct {
155158
ReservationStartDate null.Time `json:"reservation_start_date"`
156159
ReservationEndDate null.Time `json:"reseveration_end_date"`
157160
AdditionalLink string `json:"additional_link"`
161+
SessionType string `json:"session_type"`
158162
}
159163

160164
type EventDTO struct {
@@ -165,10 +169,12 @@ type EventDTO struct {
165169
ImageEvent string `json:"image_event"`
166170
DateEvent null.Time `json:"date_event"`
167171
Type constants.EventType `json:"type"`
172+
Price float64 `json:"price"`
168173
Location string `json:"location"`
169174
Duration string `json:"duration"`
170175
Capacity int `json:"capacity"`
171176
RegistrationLink string `json:"registration_link"`
177+
SessionType string `json:"session_type"`
172178
}
173179

174180
type UpdateEvenPayload struct {
@@ -281,6 +287,8 @@ func (e Event) ToDTO() EventDTO {
281287
Location: e.Location,
282288
Duration: e.Duration,
283289
Capacity: e.Capacity,
290+
Price: e.Price,
284291
RegistrationLink: e.RegistrationLink,
292+
SessionType: e.SessionType,
285293
}
286294
}

0 commit comments

Comments
 (0)