Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added .github/.DS_Store
Binary file not shown.
Empty file added Pfp-frontend-refactor.MD
Empty file.
2 changes: 1 addition & 1 deletion backend/internal/handler/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (h *S3Handler) GetUploadURL(c *fiber.Ctx) error {
// @Tags s3
// @Accept json
// @Produce json
// @Param key path string true "File key (full path after /presigned-url/)"
// @Param key path string true "File key (full path after /presigned-get-url/)"
// @Success 200 {string} string "Presigned URL"
// @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/handler/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func TestUsersHandler_UpdateProfilePicture(t *testing.T) {
},
}

app := fiber.New()
app := fiber.New(fiber.Config{ErrorHandler: errs.ErrorHandler})
h := NewUsersHandler(mock, &mockS3Storage{})
app.Put("/users/:userId/profile-picture", h.UpdateProfilePicture)

Expand Down
7 changes: 2 additions & 5 deletions backend/internal/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import (

"github.com/generate/selfserve/internal/service/clerk"
notificationssvc "github.com/generate/selfserve/internal/service/notifications"
"github.com/generate/selfserve/internal/storage/redis"

s3storage "github.com/generate/selfserve/internal/service/s3"
opensearchstorage "github.com/generate/selfserve/internal/service/storage/opensearch"
storage "github.com/generate/selfserve/internal/service/storage/postgres"
"github.com/generate/selfserve/internal/storage/redis"
"github.com/generate/selfserve/internal/validation"
"github.com/goccy/go-json"
"github.com/gofiber/fiber/v2"
Expand All @@ -44,8 +43,6 @@ type App struct {
func InitApp(cfg *config.Config) (*App, error) {
validation.Init()

// Init DB/repository(ies)

repo, err := storage.NewRepository(cfg.DB)
if err != nil {
return nil, err
Expand All @@ -68,7 +65,7 @@ func InitApp(cfg *config.Config) (*App, error) {
app := setupApp()
setupClerk(cfg)

if err = setupRoutes(app, repo, genkitInstance, cfg, s3Store, openSearchRepos); err != nil { //nolint:wsl
if err = setupRoutes(app, repo, genkitInstance, cfg, s3Store, openSearchRepos); err != nil {
if e := repo.Close(); e != nil {
return nil, errors.Join(err, e)
}
Expand Down
1 change: 1 addition & 0 deletions backend/internal/service/storage/postgres/repo_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type S3Storage interface {
GeneratePresignedGetURL(ctx context.Context, in models.PresignedURLInput) (string, error)
DeleteFile(ctx context.Context, key string) error
}

type RoomsRepository interface {
FindRoomsWithOptionalGuestBookingsByFloor(ctx context.Context, filter *models.FilterRoomsRequest, hotelID string, cursorRoomNumber int) ([]*models.RoomWithOptionalGuestBooking, error)
FindAllFloors(ctx context.Context, hotelID string) ([]int, error)
Expand Down
86 changes: 86 additions & 0 deletions backend/internal/service/storage/postgres/s3/s3storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package s3

import (
"context"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
awsConfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/generate/selfserve/config"
)

type Storage struct {
Client *s3.Client
BucketName string
URL *s3.PresignClient
}

func NewS3Storage(cfg config.S3) (*Storage, error) {
// Create AWS config with your credentials
awsCfg, err := awsConfig.LoadDefaultConfig(context.Background(),
awsConfig.WithRegion(cfg.Region),
awsConfig.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
cfg.AccessKeyID,
cfg.SecretAccessKey,
"",
)),
)
if err != nil {
return nil, err
}

// Create S3 client
client := s3.NewFromConfig(awsCfg)

return &Storage{
Client: client,
BucketName: cfg.BucketName,
URL: s3.NewPresignClient(client),
}, nil
}

func (s *Storage) GeneratePresignedURL(ctx context.Context, key string, expiration time.Duration) (string, error) {

presignedURL, err := s.URL.PresignPutObject(ctx, &s3.PutObjectInput{
Bucket: aws.String(s.BucketName),
Key: aws.String(key),
}, func(opts *s3.PresignOptions) {
opts.Expires = expiration
},
)

if err != nil {
return "", err
}

return presignedURL.URL, nil
}

func (s *Storage) GeneratePresignedGetURL(ctx context.Context, key string, expiration time.Duration) (string, error) {
presignedURL, err := s.URL.PresignGetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(s.BucketName),
Key: aws.String(key),
}, func(opts *s3.PresignOptions) { opts.Expires = expiration },
)
if err != nil {
return "", err
}
return presignedURL.URL, nil
}


func (s *Storage) DeleteFile(ctx context.Context, key string) (error) {
_, err := s.Client.DeleteObject(ctx, &s3.DeleteObjectInput{
Bucket: aws.String(s.BucketName),
Key: aws.String(key),
})
if err != nil {
return err
}

return nil
}


21 changes: 21 additions & 0 deletions clients/web/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Route as SignInRouteImport } from './routes/sign-in'
import { Route as NoOrgRouteImport } from './routes/no-org'
import { Route as ProtectedRouteImport } from './routes/_protected'
import { Route as IndexRouteImport } from './routes/index'
import { Route as FlowsPfpRouteImport } from './routes/flows.pfp'
import { Route as ProtectedTestApiRouteImport } from './routes/_protected/test-api'
import { Route as ProtectedSettingsRouteImport } from './routes/_protected/settings'
import { Route as ProtectedRoomsRouteImport } from './routes/_protected/rooms'
Expand Down Expand Up @@ -47,6 +48,11 @@ const IndexRoute = IndexRouteImport.update({
path: '/',
getParentRoute: () => rootRouteImport,
} as any)
const FlowsPfpRoute = FlowsPfpRouteImport.update({
id: '/flows/pfp',
path: '/flows/pfp',
getParentRoute: () => rootRouteImport,
} as any)
const ProtectedTestApiRoute = ProtectedTestApiRouteImport.update({
id: '/test-api',
path: '/test-api',
Expand Down Expand Up @@ -98,6 +104,7 @@ export interface FileRoutesByFullPath {
'/rooms': typeof ProtectedRoomsRouteWithChildren
'/settings': typeof ProtectedSettingsRoute
'/test-api': typeof ProtectedTestApiRoute
'/flows/pfp': typeof FlowsPfpRoute
'/guests/$guestId': typeof ProtectedGuestsGuestIdRoute
'/guests/': typeof ProtectedGuestsIndexRoute
'/rooms/': typeof ProtectedRoomsIndexRoute
Expand All @@ -111,6 +118,7 @@ export interface FileRoutesByTo {
'/profile': typeof ProtectedProfileRoute
'/settings': typeof ProtectedSettingsRoute
'/test-api': typeof ProtectedTestApiRoute
'/flows/pfp': typeof FlowsPfpRoute
'/guests/$guestId': typeof ProtectedGuestsGuestIdRoute
'/guests': typeof ProtectedGuestsIndexRoute
'/rooms': typeof ProtectedRoomsIndexRoute
Expand All @@ -127,6 +135,7 @@ export interface FileRoutesById {
'/_protected/rooms': typeof ProtectedRoomsRouteWithChildren
'/_protected/settings': typeof ProtectedSettingsRoute
'/_protected/test-api': typeof ProtectedTestApiRoute
'/flows/pfp': typeof FlowsPfpRoute
'/_protected/guests/$guestId': typeof ProtectedGuestsGuestIdRoute
'/_protected/guests/': typeof ProtectedGuestsIndexRoute
'/_protected/rooms/': typeof ProtectedRoomsIndexRoute
Expand All @@ -143,6 +152,7 @@ export interface FileRouteTypes {
| '/rooms'
| '/settings'
| '/test-api'
| '/flows/pfp'
| '/guests/$guestId'
| '/guests/'
| '/rooms/'
Expand All @@ -156,6 +166,7 @@ export interface FileRouteTypes {
| '/profile'
| '/settings'
| '/test-api'
| '/flows/pfp'
| '/guests/$guestId'
| '/guests'
| '/rooms'
Expand All @@ -171,6 +182,7 @@ export interface FileRouteTypes {
| '/_protected/rooms'
| '/_protected/settings'
| '/_protected/test-api'
| '/flows/pfp'
| '/_protected/guests/$guestId'
| '/_protected/guests/'
| '/_protected/rooms/'
Expand All @@ -182,6 +194,7 @@ export interface RootRouteChildren {
NoOrgRoute: typeof NoOrgRoute
SignInRoute: typeof SignInRoute
SignUpRoute: typeof SignUpRoute
FlowsPfpRoute: typeof FlowsPfpRoute
}

declare module '@tanstack/react-router' {
Expand Down Expand Up @@ -221,6 +234,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof IndexRouteImport
parentRoute: typeof rootRouteImport
}
'/flows/pfp': {
id: '/flows/pfp'
path: '/flows/pfp'
fullPath: '/flows/pfp'
preLoaderRoute: typeof FlowsPfpRouteImport
parentRoute: typeof rootRouteImport
}
'/_protected/test-api': {
id: '/_protected/test-api'
path: '/test-api'
Expand Down Expand Up @@ -322,6 +342,7 @@ const rootRouteChildren: RootRouteChildren = {
NoOrgRoute: NoOrgRoute,
SignInRoute: SignInRoute,
SignUpRoute: SignUpRoute,
FlowsPfpRoute: FlowsPfpRoute,
}
export const routeTree = rootRouteImport
._addFileChildren(rootRouteChildren)
Expand Down
Loading
Loading