CRUD Events and React interaction
This commit is contained in:
@@ -97,11 +97,11 @@ func Verify(ctx context.Context, email, password string) (*User, error) {
|
||||
type Event struct {
|
||||
bun.BaseModel `bun:"table:events"`
|
||||
|
||||
EventID uuid.UUID `bun:"type:uuid,pk,default:gen_random_uuid()" json:"eventID"`
|
||||
EventID uuid.UUID `bun:"event_id,type:uuid,pk,default:gen_random_uuid()" json:"id"`
|
||||
CreationDate time.Time `bun:"creation_date,notnull,default:current_timestamp" json:"creationDate"`
|
||||
ScheduleStart time.Time `bun:"schedule_start,notnull" json:"scheduleStart"`
|
||||
ScheduleEnd time.Time `bun:"schedule_end,notnull" json:"scheduleEnd"`
|
||||
Status Status `bun:"status,notnull,default:Inactive" json:"status"`
|
||||
ScheduleStart time.Time `bun:"schedule_start,notnull" json:"start"`
|
||||
ScheduleEnd time.Time `bun:"schedule_end,notnull" json:"end"`
|
||||
Status Status `bun:"status,notnull,default:'Inactive'" json:"status"`
|
||||
}
|
||||
|
||||
type EventToUser struct {
|
||||
|
||||
@@ -13,7 +13,7 @@ func HandleDeleteEvent(w http.ResponseWriter, r *http.Request) {
|
||||
var event core.Event
|
||||
res, err := core.DB.NewDelete().
|
||||
Model(&event).
|
||||
Where("id = ?", uuid).
|
||||
Where("event_id = ?", uuid).
|
||||
Returning("*").
|
||||
Exec(context.Background())
|
||||
if err != nil {
|
||||
@@ -24,10 +24,9 @@ func HandleDeleteEvent(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
log.Println(res)
|
||||
|
||||
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "Event deleted.",
|
||||
}.Respond(w, http.StatusOK)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,14 +10,6 @@ import (
|
||||
)
|
||||
|
||||
func HandleCreateBlog(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: "Method is not allowed",
|
||||
}.Respond(w, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
|
||||
@@ -18,18 +18,19 @@ func HandleCreateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
}.Respond(w, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = core.DB.NewInsert().Model(&event).Exec(context.Background())
|
||||
|
||||
_, err = core.DB.NewInsert().Model(&event).Exec(context.Background())
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusNotAcceptable)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "Event created",
|
||||
Data: event,
|
||||
Data: event,
|
||||
}.Respond(w, http.StatusCreated)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func HandleUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
event_uuid := r.PathValue("event_uuid")
|
||||
event.EventID, err = uuid.FromBytes([]byte(event_uuid))
|
||||
event.EventID, err = uuid.Parse(event_uuid)
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
@@ -44,7 +44,7 @@ func HandleUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
_, err = core.DB.NewUpdate().
|
||||
Model(event).
|
||||
Model(&event).
|
||||
OmitZero().
|
||||
WherePK().
|
||||
Exec(context.Background())
|
||||
@@ -62,4 +62,3 @@ func HandleUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
Data: event,
|
||||
}.Respond(w, http.StatusOK)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@ import (
|
||||
)
|
||||
|
||||
type UpdateShortcodeArgs struct {
|
||||
Code *string `json:"code"` // The shortcode value
|
||||
Type *core.ShortcodeType `json:"type"`
|
||||
Value *string `json:"value"`
|
||||
MediaID *uuid.UUID `json:"media_id"` // Nullable reference to another table's ID
|
||||
ID *int64 `json:"id,omitempty"`
|
||||
Code *string `json:"code,omitempty"` // The shortcode value
|
||||
Type *core.ShortcodeType `bun:"shortcode_type" json:"type,omitempty"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
MediaID *uuid.UUID `json:"media_id,omitempty"` // Nullable reference to another table's ID
|
||||
}
|
||||
|
||||
func HandleUpdateShortcode(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -51,7 +52,7 @@ func HandleUpdateShortcode(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
code := r.PathValue("shortcode")
|
||||
_, err = updateQuery.
|
||||
Where("code = ?", code).
|
||||
Where("id = ? OR code = ?", updateArgs.ID, code).
|
||||
Returning("*").
|
||||
Exec(context.Background())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user