Skip to content

Commit

Permalink
780 endpoint fetch event by id (#792)
Browse files Browse the repository at this point in the history
* Resolve issue with search functionality when role filter is applied

* Implemented new unit tests for AdminMemberView to cover Role-based filtering

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* codegen

* Created endpoint to fetch event by id.

* Implemented tests for fetch event by id endpoint.

* Fixed getEventById response.

* codegen
  • Loading branch information
AzizPatel786 authored Oct 6, 2024
1 parent 856b9eb commit ea46d39
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 2 deletions.
23 changes: 23 additions & 0 deletions client/src/models/__generated__/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions server/src/middleware/__generated__/routes.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions server/src/middleware/__generated__/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions server/src/middleware/tests/EventController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,21 @@ describe("EventController endpoint tests", () => {
})
})
})

describe("GET /events/:id", () => {
it("should return the event details for a valid event ID", async () => {
const { id: id1 } = await eventService.createEvent(event1)
const res = await request.get(`/events/${id1}`).send()
expect(res.status).toEqual(200)
expect(res.body.data).toBeDefined()
expect(res.body.data.title).toEqual("UASC New event")
expect(res.body.data.location).toEqual("UASC")
})

it("should return 404 if the event does not exist", async () => {
const res = await request.get("/events/random-event").send()
expect(res.status).toEqual(404)
expect(res.body.error).toEqual("Event not found.")
})
})
})
27 changes: 25 additions & 2 deletions server/src/service-layer/controllers/EventController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import EventService from "data-layer/services/EventService"
import { EventSignupBody } from "service-layer/request-models/EventRequests"
import {
EventSignupResponse,
GetAllEventsResponse
GetAllEventsResponse,
GetEventResponse
} from "service-layer/response-models/EventResponse"
import {
Body,
Controller,
Get,
Path,
Post,
Query,
Route,
Request,
Route,
SuccessResponse
} from "tsoa"
import express from "express"
Expand Down Expand Up @@ -137,4 +139,25 @@ export class EventController extends Controller {
req.res?.end()
})
}

@Get("{id}")
@SuccessResponse("200", "Successfully fetched the event")
public async getEventById(@Path() id: string): Promise<GetEventResponse> {
try {
const eventService = new EventService()
const event = await eventService.getEventById(id)

if (!event) {
this.setStatus(404)
return { error: "Event not found." }
}

return { data: event }
} catch (e) {
this.setStatus(500)
return {
error: "Something went wrong when fetching the event, please try again"
}
}
}
}
4 changes: 4 additions & 0 deletions server/src/service-layer/response-models/EventResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export interface GetAllEventsResponse
CursorPaginatedResponse {
data?: Event[]
}

export interface GetEventResponse extends CommonResponse {
data?: Event
}

0 comments on commit ea46d39

Please sign in to comment.