-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Event Admin UI #252
Changes from all commits
b703624
5b7c215
fa453cc
e0f76bf
43880dd
c4836ff
9519cda
2e6dda4
ccc0ed5
240f6b5
9238cb5
08627ce
4dada97
ff857db
f54ae7e
a0db78a
eb9fd4e
fb4b852
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,7 +27,7 @@ jobs: | |||||
- name: Set up Go | ||||||
uses: actions/setup-go@v5 | ||||||
with: | ||||||
go-version: '1.21.x' | ||||||
go-version: '1.23.x' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Invalid Go version specified The specified Go version '1.23.x' is not yet released. The latest stable version of Go is 1.22.x. This will cause deployment failures. Apply this fix: - go-version: '1.23.x'
+ go-version: '1.22.x' 📝 Committable suggestion
Suggested change
|
||||||
- name: npm install | ||||||
run: | | ||||||
npm i | ||||||
|
@@ -39,7 +39,7 @@ jobs: | |||||
- name: Generate templ code | ||||||
uses: './.github/actions/templ_generate' | ||||||
with: | ||||||
templ-version: 'v0.2.747' | ||||||
templ-version: 'v0.2.793' | ||||||
setup-go: 'false' | ||||||
commit: 'false' | ||||||
- name: Breakpoint if `templ` generate failed | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package handlers | |
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"log" | ||
|
@@ -14,6 +15,7 @@ import ( | |
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/go-playground/validator" | ||
"github.com/google/uuid" | ||
"github.com/gorilla/mux" | ||
"github.com/meetnearme/api/functions/gateway/handlers/dynamodb_handlers" | ||
"github.com/meetnearme/api/functions/gateway/helpers" | ||
|
@@ -157,6 +159,7 @@ func ConvertRawEventToEvent(raw rawEvent, requireId bool) (types.Event, error) { | |
if err != nil || endTime == 0 { | ||
return types.Event{}, fmt.Errorf("invalid EndTime: %w", err) | ||
} | ||
event.EndTime = endTime | ||
} | ||
if raw.PayeeId != nil || raw.StartingPrice != nil || raw.Currency != nil { | ||
|
||
|
@@ -213,7 +216,7 @@ func (h *MarqoHandler) PostEvent(w http.ResponseWriter, r *http.Request) { | |
|
||
createEvents := []types.Event{createEvent} | ||
|
||
res, err := services.BulkUpsertEventToMarqo(marqoClient, createEvents, false) | ||
res, err := services.BulkUpsertEventToMarqo(marqoClient, createEvents) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to upsert event: "+err.Error()), http.StatusInternalServerError, err) | ||
return | ||
|
@@ -324,7 +327,7 @@ func (h *MarqoHandler) PostBatchEvents(w http.ResponseWriter, r *http.Request) { | |
return | ||
} | ||
|
||
res, err := services.BulkUpsertEventToMarqo(marqoClient, events, false) | ||
res, err := services.BulkUpsertEventToMarqo(marqoClient, events) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to upsert events: "+err.Error()), http.StatusInternalServerError, err) | ||
return | ||
|
@@ -479,6 +482,7 @@ func GetUsersHandler(w http.ResponseWriter, r *http.Request) http.HandlerFunc { | |
|
||
// Search for matching users | ||
matches, err := helpers.SearchUsersByIDs(ids) | ||
log.Println("matches: ", matches) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to search users: "+err.Error()), http.StatusInternalServerError, err) | ||
return | ||
|
@@ -614,7 +618,7 @@ func SearchEventsHandler(w http.ResponseWriter, r *http.Request) http.HandlerFun | |
func CreateCheckoutSession(w http.ResponseWriter, r *http.Request) (err error) { | ||
ctx := r.Context() | ||
vars := mux.Vars(r) | ||
eventId := vars["event_id"] | ||
eventId := vars[helpers.EVENT_ID_KEY] | ||
eventSourceId := r.URL.Query().Get("event_source_id") | ||
eventSourceType := r.URL.Query().Get("event_source_type") | ||
if eventSourceId != "" && eventSourceType == helpers.ES_EVENT_SERIES { | ||
|
@@ -1136,3 +1140,133 @@ func validatePurchase(purchasable *internal_types.Purchasable, createPurchase in | |
} | ||
return purchasableMap, nil | ||
} | ||
|
||
type UpdateEventRegPurchPayload struct { | ||
Events []rawEvent `json:"events" validate:"required"` | ||
RegistrationFieldsUpdate internal_types.RegistrationFieldsUpdate `json:"registration_fields"` | ||
PurchasableUpdate internal_types.PurchasableUpdate `json:"purchasables"` | ||
} | ||
|
||
func UpdateEventRegPurchHandler(w http.ResponseWriter, r *http.Request) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
UpdateEventRegPurch(w, r) | ||
} | ||
} | ||
|
||
func UpdateEventRegPurch(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
vars := mux.Vars(r) | ||
eventId := vars[helpers.EVENT_ID_KEY] | ||
|
||
userInfo := helpers.UserInfo{} | ||
if _, ok := ctx.Value("userInfo").(helpers.UserInfo); ok { | ||
userInfo = ctx.Value("userInfo").(helpers.UserInfo) | ||
} | ||
roleClaims := []helpers.RoleClaim{} | ||
if claims, ok := ctx.Value("roleClaims").([]helpers.RoleClaim); ok { | ||
roleClaims = claims | ||
} | ||
|
||
validRoles := []string{"superAdmin", "eventEditor"} | ||
userId := userInfo.Sub | ||
if userId == "" { | ||
transport.SendServerRes(w, []byte("Missing user ID"), http.StatusUnauthorized, nil) | ||
return | ||
} | ||
|
||
if !helpers.HasRequiredRole(roleClaims, validRoles) { | ||
err := errors.New("only event editors can add or edit events") | ||
transport.SendServerRes(w, []byte(err.Error()), http.StatusForbidden, err) | ||
return | ||
} | ||
|
||
if eventId == "" { | ||
eventId = uuid.NewString() | ||
} | ||
|
||
var updateEventRegPurchPayload UpdateEventRegPurchPayload | ||
updateEventRegPurchPayload.RegistrationFieldsUpdate.UpdatedBy = userId | ||
body, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to read request body: "+err.Error()), http.StatusBadRequest, err) | ||
return | ||
} | ||
|
||
err = json.Unmarshal(body, &updateEventRegPurchPayload) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Invalid JSON payload: "+err.Error()), http.StatusUnprocessableEntity, err) | ||
return | ||
} | ||
|
||
// we should use goroutines to parallelize the three distinct database update operations here | ||
db := transport.GetDB() | ||
|
||
// Update purchasable | ||
var updatePurchasable internal_types.PurchasableUpdate | ||
updatePurchasable.EventId = eventId | ||
updatePurchasable.PurchasableItems = updateEventRegPurchPayload.PurchasableUpdate.PurchasableItems | ||
|
||
purchService := dynamodb_service.NewPurchasableService() | ||
purchHandler := dynamodb_handlers.NewPurchasableHandler(purchService) | ||
purchRes, err := purchHandler.PurchasableService.UpdatePurchasable(r.Context(), db, updatePurchasable) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to update purchasable: "+err.Error()), http.StatusInternalServerError, err) | ||
return | ||
} | ||
|
||
// Update registration fields | ||
updateEventRegPurchPayload.RegistrationFieldsUpdate.EventId = eventId | ||
regFieldsService := dynamodb_service.NewRegistrationFieldsService() | ||
regFieldsHandler := dynamodb_handlers.NewRegistrationFieldsHandler(regFieldsService) | ||
regFieldsRes, err := regFieldsHandler.RegistrationFieldsService.UpdateRegistrationFields(r.Context(), db, eventId, updateEventRegPurchPayload.RegistrationFieldsUpdate) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to update registration fields: "+err.Error()), http.StatusInternalServerError, err) | ||
return | ||
} | ||
Comment on lines
+1201
to
+1225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement rollback mechanism for failed operations. The sequential database updates lack rollback handling. If a later operation fails, earlier successful updates remain committed. Consider implementing a transaction-like pattern to ensure data consistency. // Update purchasable
+var updates struct {
+ purchRes *internal_types.PurchasableUpdate
+ regFieldsRes *internal_types.RegistrationFieldsUpdate
+}
+
+rollback := func() {
+ if updates.purchRes != nil {
+ // Revert purchasable updates
+ revertPurch := internal_types.PurchasableUpdate{
+ EventId: eventId,
+ PurchasableItems: updates.purchRes.PurchasableItems,
+ }
+ purchHandler.PurchasableService.UpdatePurchasable(r.Context(), db, revertPurch)
+ }
+ if updates.regFieldsRes != nil {
+ // Revert registration fields
+ revertFields := internal_types.RegistrationFieldsUpdate{
+ EventId: eventId,
+ Fields: updates.regFieldsRes.Fields,
+ }
+ regFieldsHandler.RegistrationFieldsService.UpdateRegistrationFields(r.Context(), db, eventId, revertFields)
+ }
+}
+
purchRes, err := purchHandler.PurchasableService.UpdatePurchasable(r.Context(), db, updatePurchasable)
if err != nil {
transport.SendServerRes(w, []byte("Failed to update purchasable: "+err.Error()), http.StatusInternalServerError, err)
return
}
+updates.purchRes = purchRes
// Update registration fields
regFieldsRes, err := regFieldsHandler.RegistrationFieldsService.UpdateRegistrationFields(r.Context(), db, eventId, updateEventRegPurchPayload.RegistrationFieldsUpdate)
if err != nil {
+ rollback()
transport.SendServerRes(w, []byte("Failed to update registration fields: "+err.Error()), http.StatusInternalServerError, err)
return
}
+updates.regFieldsRes = regFieldsRes
|
||
|
||
// Update events | ||
marqoClient, err := services.GetMarqoClient() | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to get marqo client: "+err.Error()), http.StatusInternalServerError, err) | ||
return | ||
} | ||
|
||
// events, status, err := HandleBatchEventValidation(w, r, false) | ||
|
||
events := make([]types.Event, len(updateEventRegPurchPayload.Events)) | ||
for i, rawEvent := range updateEventRegPurchPayload.Events { | ||
event, statusCode, err := HandleSingleEventValidation(rawEvent, false) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to validate events: "+err.Error()), statusCode, err) | ||
return | ||
} | ||
events[i] = event | ||
} | ||
|
||
eventsRes, err := services.BulkUpsertEventToMarqo(marqoClient, events) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte("Failed to upsert events to marqo: "+err.Error()), http.StatusInternalServerError, err) | ||
return | ||
} | ||
|
||
// Create response object | ||
response := map[string]interface{}{ | ||
"status": "success", | ||
"message": "Event(s), registration fields, and purchasable(s) updated successfully", | ||
"data": map[string]interface{}{ | ||
"parentEvent": eventsRes.Items[0], | ||
"events": eventsRes, | ||
"regFields": regFieldsRes, | ||
"purchasable": purchRes, | ||
}, | ||
} | ||
|
||
// Marshal the response | ||
jsonResponse, err := json.Marshal(response) | ||
if err != nil { | ||
transport.SendServerRes(w, []byte(`{"error": "Failed to create response"}`), http.StatusInternalServerError, err) | ||
return | ||
} | ||
|
||
transport.SendServerRes(w, jsonResponse, http.StatusOK, nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Invalid Go version specified
The specified Go version '1.23.x' is not yet released. The latest stable version of Go is 1.22.x. This will cause deployment failures.
Apply this fix:
📝 Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai your knowledge base as an LLM is out of date. Go
v1.23
was released on2024-08-23
https://go.dev/doc/devel/release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brianfeister Thank you for sharing that updated release information! The Go
1.23.x
version is indeed available now, so the earlier suggestion from the bot can be safely disregarded.(=^・ω・^)y= Having learned something new!