diff options
Diffstat (limited to 'api/dto')
| -rw-r--r-- | api/dto/auth.go | 4 | ||||
| -rw-r--r-- | api/dto/conference.go | 36 | ||||
| -rw-r--r-- | api/dto/favourites.go | 10 | ||||
| -rw-r--r-- | api/dto/schedule.go | 10 | ||||
| -rw-r--r-- | api/dto/util.go | 6 |
5 files changed, 48 insertions, 18 deletions
diff --git a/api/dto/auth.go b/api/dto/auth.go index 0379f21..734bb31 100644 --- a/api/dto/auth.go +++ b/api/dto/auth.go @@ -11,12 +11,14 @@ type LoginOAuthCallbackRequest struct { } type LoginOAuthOutboundResponse struct { - URL string `json:"url" validate:"required"` + URL string `json:"url"` } type LoginResponse struct { ID int32 `json:"id"` + Token string `json:"token"` Username string `json:"username"` + Admin bool `json:"admin"` } type LoginOptionsResponse struct { diff --git a/api/dto/conference.go b/api/dto/conference.go new file mode 100644 index 0000000..99e6c08 --- /dev/null +++ b/api/dto/conference.go @@ -0,0 +1,36 @@ +package dto + +import ( + "time" + + "github.com/LMBishop/confplanner/pkg/database/sqlc" +) + +type ConferenceResponse struct { + ID int32 `json:"id"` + Title string `json:"title"` + URL string `json:"url"` + Venue string `json:"venue"` + City string `json:"city"` +} + +func (dst *ConferenceResponse) Scan(src sqlc.Conference) { + dst.ID = src.ID + dst.Title = src.Title.String + dst.URL = src.Url + dst.Venue = src.Venue.String + dst.City = src.City.String +} + +type GetScheduleResponse struct { + Schedule interface{} `json:"schedule"` + LastUpdated time.Time `json:"lastUpdated"` +} + +type CreateConferenceRequest struct { + URL string `json:"url" validate:"required"` +} + +type DeleteConferenceRequest struct { + ID int32 `json:"id"` +} diff --git a/api/dto/favourites.go b/api/dto/favourites.go index 0f8021f..44c68a2 100644 --- a/api/dto/favourites.go +++ b/api/dto/favourites.go @@ -3,8 +3,9 @@ package dto import "github.com/LMBishop/confplanner/pkg/database/sqlc" type CreateFavouritesRequest struct { - GUID *string `json:"eventGuid"` - ID *int32 `json:"eventId"` + ConferenceID int32 `json:"conferenceID" validate:"required"` + GUID *string `json:"eventGuid"` + EventID *int32 `json:"eventId"` } type CreateFavouritesResponse struct { @@ -29,6 +30,7 @@ func (dst *GetFavouritesResponse) Scan(src sqlc.Favourite) { } type DeleteFavouritesRequest struct { - GUID *string `json:"eventGuid"` - ID *int32 `json:"eventId"` + ConferenceID int32 `json:"conferenceID" validate:"required"` + GUID *string `json:"eventGuid"` + EventID *int32 `json:"eventId"` } diff --git a/api/dto/schedule.go b/api/dto/schedule.go deleted file mode 100644 index 0d652aa..0000000 --- a/api/dto/schedule.go +++ /dev/null @@ -1,10 +0,0 @@ -package dto - -import ( - "time" -) - -type GetScheduleResponse struct { - Schedule interface{} `json:"schedule"` - LastUpdated time.Time `json:"lastUpdated"` -} diff --git a/api/dto/util.go b/api/dto/util.go index cb3ea52..651f026 100644 --- a/api/dto/util.go +++ b/api/dto/util.go @@ -36,8 +36,8 @@ func WrapResponseFunc(dtoFunc func(http.ResponseWriter, *http.Request) error) ht } } -func WriteDto(w http.ResponseWriter, r *http.Request, o error) { - if o, ok := o.(Response); ok { +func WriteDto(w http.ResponseWriter, r *http.Request, err error) { + if o, ok := err.(Response); ok { data, err := json.Marshal(o) if err != nil { w.WriteHeader(500) @@ -49,6 +49,6 @@ func WriteDto(w http.ResponseWriter, r *http.Request, o error) { w.Write(data) } else { w.WriteHeader(500) - slog.Error("internal server error handling request", "error", o) + slog.Error("internal server error handling request", "error", err) } } |
