Skip to content

Commit

Permalink
Merge branch 'main' into db-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Jun 12, 2024
2 parents bc08587 + 53cc070 commit 411a664
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 662 deletions.
10 changes: 5 additions & 5 deletions backend/entities/events/previews/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/google/uuid"
)

type common struct {
type Common struct {
ID uuid.UUID `json:"id"`
Title string `json:"title"`
Name string `json:"name"`
EventType models.EventType `json:"event_type"`
Location string `json:"location"`
Link string `json:"link"`
Expand All @@ -18,13 +18,13 @@ type common struct {
}

type EventStub struct {
common
Common
Host uuid.UUID `json:"host"`
}

func (es *EventStub) Into(tags []models.Tag, hostName string, hostLogo string) *EventPreview {
return &EventPreview{
common: es.common,
Common: es.Common,
Tags: tags,
HostName: hostName,
HostLogo: hostLogo,
Expand All @@ -36,7 +36,7 @@ func (es EventStub) TableName() string {
}

type EventPreview struct {
common
Common
Tags []models.Tag `json:"tags"`
HostName string `json:"host_name"`
HostLogo string `json:"host_logo"`
Expand Down
8 changes: 3 additions & 5 deletions backend/entities/events/previews/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func GetEventPreivews(db *gorm.DB, pageInfo *fiberpaginate.PageInfo) ([]EventPreview, error) {
db = cache.SetUseCache(db, true)

var events []EventStub
if err := db.Scopes(utilities.IntoScope(*pageInfo, db)).Find(&events).Error; err != nil {
return nil, err
Expand All @@ -25,10 +25,7 @@ func GetEventPreivews(db *gorm.DB, pageInfo *fiberpaginate.PageInfo) ([]EventPre
}

func GetEventPreviewsByTime(db *gorm.DB, pageInfo *fiberpaginate.PageInfo, startTime *time.Time, endTime *time.Time) ([]EventPreview, error) {
db = cache.SetUseCache(db, true)

var events []EventStub
query := db.Model(&events)
query := cache.SetUseCache(db, true).Model(&events)

if startTime != nil && endTime != nil {
query = query.Where("start_time >= ? AND end_time <= ?", *startTime, *endTime)
Expand All @@ -38,6 +35,7 @@ func GetEventPreviewsByTime(db *gorm.DB, pageInfo *fiberpaginate.PageInfo, start
query = query.Scopes(utilities.IntoScope(*pageInfo, db))
}

var events []EventStub
if err := query.Find(&events).Error; err != nil {
return nil, err
}
Expand Down
9 changes: 9 additions & 0 deletions backend/entities/events/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ import (
func GetEvents(db *gorm.DB, pageInfo fiberpaginate.PageInfo) ([]models.Event, error) {
var events []models.Event

if err := db.Scopes(utilities.IntoScope(pageInfo, db)).Find(&events).Error; err != nil {
return nil, err
}

return events, nil
}

func GetEvent(db *gorm.DB, eventID uuid.UUID, preloads ...transactions.OptionalQuery) (*models.Event, error) {
db = cache.SetUseCache(db, true)

var event models.Event
if err := db.Scopes(utilities.IntoScope(pageInfo, db)).Find(&events).Error; err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@generatesac/lib",
"version": "0.0.13",
"version": "0.0.164",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions frontend/lib/src/api/eventApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { Club, clubSchema } from "../types/club";
import {
CreateEventRequestBody,
Event,
EventPreview,
UpdateEventRequestBody,
eventPreviewSchema,
eventSchema,
} from "../types/event";
import { PaginationQueryParams } from "../types/root";
Expand All @@ -25,9 +27,23 @@ export const eventApi = baseApi.injectEndpoints({
? result.map((event) => ({ type: "Event", id: event.id }))
: ["Event"],
transformResponse: (response) => {
console.log('here!!!!')
return z.array(eventSchema).parse(response);
},
}),
eventsPreview: builder.query<EventPreview[], PaginationQueryParams>({
query: (queryParams) => ({
url: handleQueryParams(`${EVENT_API_BASE_URL}/previews`, queryParams),
method: "GET",
}),
providesTags: (result) =>
result
? result.map((event) => ({ type: "Event", id: event.id }))
: ["Event"],
transformResponse: (response) => {
return z.array(eventPreviewSchema).parse(response);
},
}),
event: builder.query<Event, string>({
query: (id) => ({
url: `${EVENT_API_BASE_URL}/${id}/`,
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/src/types/club.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const createClubTagsRequestBodySchema = z.object({
const clubSchemaIntermediate = z.object({
name: z.string().max(255),
preview: z.string().max(255),
description: z.string().max(255),
description: z.string(),
num_members: z.number(),
is_recruiting: z.boolean(),
application_link: z.string().max(255),
Expand Down
20 changes: 19 additions & 1 deletion frontend/lib/src/types/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from "zod";

import { rootModelSchema } from "./root";
import { tagSchema } from "./tag";

/**
* TODO: Re-Write After BE Fixes
Expand Down Expand Up @@ -35,7 +36,7 @@ const updateEventRequestBodySchema = z.object({
const eventSchemaIntermediate = z.object({
name: z.string().max(255),
preview: z.string().max(255),
description: z.string().max(255),
description: z.string(),
start_time: z.string(),
end_time: z.string(),
location: z.string().max(255),
Expand All @@ -48,7 +49,23 @@ const eventSchemaIntermediate = z.object({
host: z.string().uuid(),
});

const eventPreviewSchemaIntermediate = z.object({
id: z.string().uuid(),
name: z.string().max(255),
event_type: eventTypeEnum,
location: z.string().max(255),
link: z.string().max(255).optional(),

start_time: z.string(),
end_time: z.string(),

tags: tagSchema.array(),
host_name: z.string().max(255),
host_logo: z.string().max(255).optional(),
});

export const eventSchema = eventSchemaIntermediate.merge(rootModelSchema);
export const eventPreviewSchema = eventPreviewSchemaIntermediate

// Types:
export type CreateEventRequestBody = z.infer<
Expand All @@ -58,3 +75,4 @@ export type UpdateEventRequestBody = z.infer<
typeof updateEventRequestBodySchema
>;
export type Event = z.infer<typeof eventSchema>;
export type EventPreview = z.infer<typeof eventPreviewSchema>;
207 changes: 0 additions & 207 deletions frontend/mobile/app/(design-system)/components/Editor/editor.tsx

This file was deleted.

80 changes: 0 additions & 80 deletions frontend/mobile/app/(design-system)/components/Editor/font.ts

This file was deleted.

Loading

0 comments on commit 411a664

Please sign in to comment.