biz

package
v0.0.0-...-57159d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 15 Imported by: 0

README

Biz

Documentation

Index

Constants

View Source
const (
	STATE_KEY_DURATION = time.Second * 300
)
View Source
const (
	TOKEN_KEY = "token"
)

Variables

ProviderSet is biz providers.

Functions

func GetToken

func GetToken(ctx context.Context) *oauth2.Token

GetToken returns token from context

func SetToken

func SetToken(ctx context.Context, token *oauth2.Token) context.Context

SetToken returns context with token

Types

type AuthData

type AuthData struct {
	State  string
	UserId string
}

type AuthRepo

type AuthRepo interface {
	SetState(context.Context, *AuthData, time.Duration) (*AuthData, error)
	CheckState(context.Context, *AuthData) (*AuthData, error)
}

type AuthUsecase

type AuthUsecase struct {
	// contains filtered or unexported fields
}

func NewAuthUsecase

func NewAuthUsecase(repo AuthRepo, logger log.Logger) *AuthUsecase

func (*AuthUsecase) CheckState

func (uc *AuthUsecase) CheckState(ctx context.Context, state string) (int64, error)

func (*AuthUsecase) SetState

func (uc *AuthUsecase) SetState(ctx context.Context, userID int64) (string, error)

type Calendar

type Calendar struct {
	ID       uuid.UUID
	UserID   uuid.UUID
	GoogleID string
	Summary  string
}

func (*Calendar) String

func (c *Calendar) String() string

String is the string representation of the Calendar struct.

type CalendarRepo

type CalendarRepo interface {
	Create(ctx context.Context, calendar *Calendar) error
	Update(ctx context.Context, calendar *Calendar) error
	Delete(ctx context.Context, calendar *Calendar) error
	Get(ctx context.Context, calendar *Calendar) (*Calendar, error)
	List(ctx context.Context, userID uuid.UUID) ([]*Calendar, error)
}

type CalendarUseCase

type CalendarUseCase struct {
	// contains filtered or unexported fields
}

func NewCalendarUseCase

func NewCalendarUseCase(repo CalendarRepo, logger log.Logger) *CalendarUseCase

func (*CalendarUseCase) ListUserCalendars

func (uc *CalendarUseCase) ListUserCalendars(ctx context.Context, userID uuid.UUID) ([]*Calendar, error)

ListUserCalendars List lists calendars from database.

func (*CalendarUseCase) Sync

func (uc *CalendarUseCase) Sync(ctx context.Context, userID uuid.UUID, calendars []*Calendar) error

Sync syncs down calendars. It will take incoming calendars and compare them to the ones in the database. If the calendar exists in the database, it will update it. If it doesn't exist, it will create it. If the calendar exists in the database but not in the incoming calendars, it will delete it.

type ChangeTypeEnum

type ChangeTypeEnum string
const (
	CREATED ChangeTypeEnum = "CREATED"
	UPDATED ChangeTypeEnum = "UPDATED"
	DELETED ChangeTypeEnum = "DELETED"
)

type ChatUseCase

type ChatUseCase struct {
	// contains filtered or unexported fields
}

func NewChatUseCase

func NewChatUseCase(cfg *conf.OpenAI, logger log.Logger, gr GoogleRepo, cr CalendarRepo, er EventRepo) *ChatUseCase

NewChatUseCase .

func (*ChatUseCase) UserChat

func (uc *ChatUseCase) UserChat(ctx context.Context, question string) (string, error)

type Event

type Event struct {
	ID         uuid.UUID `json:"id,omitempty"`
	CalendarID uuid.UUID `json:"calendar_id,omitempty"`
	GoogleID   string    `json:"google_id,omitempty"`
	Summary    string    `json:"title,omitempty"`
	Location   string    `json:"location,omitempty"`
	StartTime  time.Time `json:"start_time,omitempty"`
	EndTime    time.Time `json:"end_time,omitempty"`
	CreatedAt  time.Time `json:"created_at,omitempty"`
	UpdatedAt  time.Time `json:"updated_at,omitempty"`
	IsAllDay   bool      `json:"is_all_day,omitempty"`
}

func (*Event) String

func (e *Event) String() string

String .

type EventHistory

type EventHistory struct {
	ID         uuid.UUID      `json:"history_id,omitempty"`
	EventID    uuid.UUID      `json:"event_id,omitempty"`
	CalendarID uuid.UUID      `json:"calendar_id,omitempty"`
	ChangeType ChangeTypeEnum `json:"change_type_enum,omitempty"`
	ChangeTime time.Time      `json:"change_time,omitempty"`
	PrevEvent  Event          `json:"prev_event"`
	NewEvent   Event          `json:"new_event"`
}

type EventHistoryRepo

type EventHistoryRepo interface {
	ListCalendarEventHistory(ctx context.Context, calendarID uuid.UUID) ([]*EventHistory, error)
	DeleteCalendarEventHistory(ctx context.Context, calendarID uuid.UUID) error
}

type EventHistoryUseCase

type EventHistoryUseCase struct {
	// contains filtered or unexported fields
}

func NewEventHistoryUseCase

func NewEventHistoryUseCase(repo EventHistoryRepo, logger log.Logger) *EventHistoryUseCase

func (*EventHistoryUseCase) DeleteCalendarEventHistory

func (uc *EventHistoryUseCase) DeleteCalendarEventHistory(ctx context.Context, calendarID uuid.UUID) error

func (*EventHistoryUseCase) ListCalendarEventHistory

func (uc *EventHistoryUseCase) ListCalendarEventHistory(ctx context.Context, calendarID uuid.UUID) ([]*EventHistory, error)

type EventRepo

type EventRepo interface {
	Get(ctx context.Context, event *Event) (*Event, error)
	Create(ctx context.Context, event *Event) (*Event, error)
	Update(ctx context.Context, event *Event) (*Event, error)
	Delete(ctx context.Context, event *Event) error
	List(ctx context.Context, calendarID uuid.UUID) ([]*Event, error)
}

EventRepo .

type EventUseCase

type EventUseCase struct {
	// contains filtered or unexported fields
}

func NewEventUseCase

func NewEventUseCase(repo EventRepo, logger log.Logger) *EventUseCase

func (*EventUseCase) Create

func (uc *EventUseCase) Create(ctx context.Context, event *Event) (*Event, error)

Create creates a new event

func (*EventUseCase) Delete

func (uc *EventUseCase) Delete(ctx context.Context, event *Event) error

Delete deletes an event

func (*EventUseCase) Get

func (uc *EventUseCase) Get(ctx context.Context, event *Event) (*Event, error)

Get gets an event from db

func (*EventUseCase) List

func (uc *EventUseCase) List(ctx context.Context, calendarID uuid.UUID) ([]*Event, error)

List lists events from db

func (*EventUseCase) Sync

func (uc *EventUseCase) Sync(ctx context.Context, calendarID uuid.UUID, events []*Event) error

Sync syncs down database events with incoming events from Google calendar

  • if event exists in db and not in Google, delete it
  • if event exists in db and in Google, update it
  • if event not in db and in Google, create it

func (*EventUseCase) Update

func (uc *EventUseCase) Update(ctx context.Context, event *Event) (*Event, error)

Update updates an event

type GoogleListEventsOption

type GoogleListEventsOption struct {
	TimeMin           string
	TimeMax           string
	UpdatedMin        string
	MaxResults        int64
	OrderByUpdateTime bool
}

GoogleListEventsOption is the option for list events

func (*GoogleListEventsOption) ListEventsCallWithOpts

ListEventsCallWithOpts returns a call to list events

func (*GoogleListEventsOption) ListEventsInstancesCallWithOpts

func (o *GoogleListEventsOption) ListEventsInstancesCallWithOpts(call *calendarAPI.EventsInstancesCall) *calendarAPI.EventsInstancesCall

ListEventsInstancesCallWithOpts returns a call to list events instances

type GoogleRepo

type GoogleRepo interface {
	AuthCodeURL(state string) string
	TokenExchange(ctx context.Context, code string) (*oauth2.Token, error)
	TokenSource(ctx context.Context, refreshToken string) (*oauth2.Token, error)
	UserInfo(ctx context.Context, token *oauth2.Token) (*User, error)
	ListUserCalendars(ctx context.Context, token *oauth2.Token) ([]*Calendar, error)
	CreateNewCalendar(ctx context.Context, token *oauth2.Token, calendarName string) (*Calendar, error)
	CreateCalendarEvent(ctx context.Context, token *oauth2.Token, event *Event, calendarID string) (*Event, error)
	UpdateCalendarEvent(ctx context.Context, token *oauth2.Token, event *Event, calendarID string) (*Event, error)
	GetCalendarEvent(ctx context.Context, token *oauth2.Token, event *Event, calendarID string) (*Event, error)
	DeleteCalendarEvent(ctx context.Context, token *oauth2.Token, event *Event, calendarID string) error
	ListCalendarEvents(ctx context.Context, token *oauth2.Token, calendarID string, opts *GoogleListEventsOption) ([]*Event, error)
}

type GoogleUseCase

type GoogleUseCase struct {
	// contains filtered or unexported fields
}

func NewGoogleUseCase

func NewGoogleUseCase(repo GoogleRepo, logger log.Logger) *GoogleUseCase

func (*GoogleUseCase) AuthCodeURL

func (uc *GoogleUseCase) AuthCodeURL(state string) string

AuthCodeURL returns the URL to OAuth 2.0 provider's consent page

func (*GoogleUseCase) ListCalendarEvents

func (uc *GoogleUseCase) ListCalendarEvents(ctx context.Context, token *oauth2.Token, calendarID string, opts *GoogleListEventsOption) ([]*Event, error)

ListCalendarEvents lists calendar events with options

func (*GoogleUseCase) ListUserCalendars

func (uc *GoogleUseCase) ListUserCalendars(ctx context.Context, token *oauth2.Token) ([]*Calendar, error)

ListUserCalendars lists user calendars

func (*GoogleUseCase) TokenExchange

func (uc *GoogleUseCase) TokenExchange(ctx context.Context, code string) (*oauth2.Token, error)

TokenExchange exchanges an authorization code for a token

func (*GoogleUseCase) TokenSource

func (uc *GoogleUseCase) TokenSource(ctx context.Context, refreshToken string) (*oauth2.Token, error)

TokenSource returns a token source

func (*GoogleUseCase) UserInfo

func (uc *GoogleUseCase) UserInfo(ctx context.Context, token *oauth2.Token) (*User, error)

UserInfo creates user in database

type OpenAIUseCase

type OpenAIUseCase struct {
	// contains filtered or unexported fields
}

func NewOpenAIUseCase

func NewOpenAIUseCase(cfg *conf.OpenAI, logger log.Logger, gr GoogleRepo) *OpenAIUseCase

NewOpenAIUseCase .

func (*OpenAIUseCase) GenerateCalendarEvents

func (uc *OpenAIUseCase) GenerateCalendarEvents(ctx context.Context, calendar *Calendar, events []*Event) error

type User

type User struct {
	ID           uuid.UUID `json:"id"`
	GoogleID     string    `json:"google_id"`
	TGID         string    `json:"tgid"`
	Name         string    `json:"name"`
	Email        string    `json:"email"`
	RefreshToken string    `json:"refresh_token"`
}

type UserRepo

type UserRepo interface {
	Create(ctx context.Context, user *User) error
	Get(ctx context.Context, user *User) (*User, error)
	List(ctx context.Context) ([]*User, error)
}

type UserUseCase

type UserUseCase struct {
	// contains filtered or unexported fields
}

func NewUserUseCase

func NewUserUseCase(repo UserRepo, logger log.Logger) *UserUseCase

func (*UserUseCase) Create

func (uc *UserUseCase) Create(ctx context.Context, user *User) error

Create creates user in database

func (*UserUseCase) Get

func (uc *UserUseCase) Get(ctx context.Context, user *User) (*User, error)

Get gets user from database

func (*UserUseCase) GetUserByID

func (uc *UserUseCase) GetUserByID(ctx context.Context, id string) (*User, error)

GetUserByID gets user from database by ID string

func (*UserUseCase) GetUserByTGID

func (uc *UserUseCase) GetUserByTGID(ctx context.Context, tgid string) (*User, error)

GetUserByTGID gets user from database by TGID string

func (*UserUseCase) List

func (uc *UserUseCase) List(ctx context.Context) ([]*User, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL