Skip to content

Commit

Permalink
new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Alder Whiteford authored and Alder Whiteford committed May 16, 2024
1 parent 83013f8 commit 682256a
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 267 deletions.
5 changes: 5 additions & 0 deletions backend/config/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
m "github.com/garrettladley/mattress"
)

type CalendarSettings struct {
GoogleClientSettings *GoogleClientSettings
OutlookClientSettings *OutlookClientSettings
}

type GoogleClientSettings struct {
ClientID *m.Secret[string]
ClientSecret *m.Secret[string]
Expand Down
1 change: 1 addition & 0 deletions backend/config/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func readLocal(v *viper.Viper, path string, useDevDotEnv bool) (*Settings, error
}

if useDevDotEnv {
fmt.Printf("%s/.env.dev", path)
err = godotenv.Load(fmt.Sprintf("%s/.env.dev", path))
} else {
err = godotenv.Load(fmt.Sprintf("%s/.env.template", path))
Expand Down
46 changes: 36 additions & 10 deletions backend/entities/calendar/base/controller.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package base

import (
"github.com/GenerateNU/sac/backend/entities/models"
"github.com/GenerateNU/sac/backend/errors"
"errors"

"github.com/GenerateNU/sac/backend/integrations/calendar"
"github.com/GenerateNU/sac/backend/types"
"github.com/gofiber/fiber/v2"
)
Expand All @@ -18,23 +19,48 @@ func NewCalendarController(serviceSettings types.ServiceParams) *CalendarControl
func (cal *CalendarController) Authorize(c *fiber.Ctx) error {
// Extract the calendar type from the query params:
calendarType := c.Query("type")
if calendarType == "" {
calendar, err := cal.parseCalendarType(calendarType)
if err != nil {
return err
}

return nil
}
// Call the respective authorize method:
authUrl := calendar.Authorize()

func (cal * CalendarController) Token(c *fiber.Ctx) error {
// Extract the token from the body:
var tokenBody models.CalendarTokenRequest
return c.Redirect(authUrl, fiber.StatusFound)
}

if err := c.BodyParser(&tokenBody); err != nil {
return errors.FailedToParseRequestBody.FiberError(c)
func (cal *CalendarController) Token(c *fiber.Ctx) error {
// Extract the calendar type from the query params:
calendarType := c.Query("type")
calendar, err := cal.parseCalendarType(calendarType)
if err != nil {
return err
}

// Extract the grant_type from the query params:
grantType := c.Query("grant_type")

// Extract the calendar type from the query params:
calendarToken := c.Get("x-calendar-auth-code")

// Call the respective token method:
calendar.Token(grantType, &calendarToken)

return nil
}

func (cal *CalendarController) parseCalendarType(calendarType string) (calendar.CalendarClientInterface, error) {
switch calendarType {
case "google":
return cal.serviceSettings.Integrations.Calendar.Google, nil
case "outlook":
return cal.serviceSettings.Integrations.Calendar.Outlook, nil
default:
return nil, errors.New("invalid calendar type")
}
}




2 changes: 1 addition & 1 deletion backend/entities/calendar/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ func Calendar(params types.RouteParams) {
// api/v1/calendar/*
calendar := params.Router.Group("/calendar")

calendar.Post("/authorize", calendarController.Authorize)
calendar.Get("/authorize", calendarController.Authorize)
calendar.Post("/token", calendarController.Token)
}
6 changes: 3 additions & 3 deletions backend/entities/models/calendar.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package models

type CalendarTokenRequest struct {
Code *string `json:"code" validate:"required"`
}
type CalendarAuthorizationResponse struct {
AuthorizationURL string `json:"authorization_url"`
}
10 changes: 0 additions & 10 deletions backend/errors/calendar.go

This file was deleted.

21 changes: 1 addition & 20 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/spf13/viper v1.18.2
github.com/swaggo/swag v1.16.3
golang.org/x/crypto v0.23.0
golang.org/x/oauth2 v0.20.0
golang.org/x/text v0.15.0
gorm.io/driver/postgres v1.5.7
gorm.io/gorm v1.25.10
Expand All @@ -41,32 +42,12 @@ require (
)

require (
cloud.google.com/go/auth v0.4.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/lib/pq v1.10.9 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
google.golang.org/api v0.180.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)

require (
Expand Down
Loading

0 comments on commit 682256a

Please sign in to comment.