Skip to content

Commit

Permalink
SMA-102: nearby events don t work (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivamach authored Apr 13, 2024
1 parent 36e0a0c commit abc4d33
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,18 @@ public List<EventHistoryDTO> getEventsHistory(@ParameterObject final Pageable pa
return eventService.getEventsHistory(pageable);
}


/**
* This endpoint returns list of Events sorted by distance from the given location. User can filter by sports.
* This endpoint returns list of Events sorted by distance from the given location. User can
* filter by sports.
*
* @param requestEventDTO it contains longitude and latitude and a list of sports for filter if given
* @param pageable it contains the page and size for pagination
* @param requestEventDTO it contains longitude and latitude and a list of sports for filter if
* given
* @param pageable it contains the page and size for pagination
* @return a list of Events sorted by distance from the given location. User can filter by sports.
*/
@GetMapping("/nearby")
public List<EventDTO> getNearbyEvents(@RequestBody RequestEventDTO requestEventDTO,
@ParameterObject final Pageable pageable) {
public List<EventDTO> getNearbyEvents(
@ParameterObject RequestEventDTO requestEventDTO, @ParameterObject final Pageable pageable) {
return eventService.getNearbyEvents(requestEventDTO, pageable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
@AllArgsConstructor
public class Event {

@Id
@GeneratedValue
private Long id;
@Id @GeneratedValue private Long id;

@Column(name = "date_start")
private LocalDateTime dateStart;
Expand All @@ -34,6 +32,7 @@ public class Event {

private String title;

@Column(name = "is_rank_updated")
private Boolean isRanksUpdated = false;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
Expand All @@ -42,8 +41,7 @@ public class Event {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
private Set<UserEventRating> ratings = new HashSet<>();

@ManyToOne
private Sport sport;
@ManyToOne private Sport sport;

@ManyToOne
@JoinColumn(name = "place_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ List<Event> findEventsByUser(
* @return list of events filtered by sport names if given, and order by distance from the user's given location
*/
@Query(nativeQuery = true, value =
"SELECT e.id, e.date_start, e.date_end, e.min_elo, e.max_elo, e.title, e.sport_id, e.place_id "
"SELECT e.id, e.date_start, e.date_end, e.min_elo, e.max_elo, e.title, e.is_rank_updated, e.sport_id, e.place_id "
+ "FROM events e "
+ "JOIN sports s ON e.sport_id = s.id "
+ "JOIN places p ON e.place_id = p.id "
Expand Down
1 change: 0 additions & 1 deletion frontend/sportsmatch-app/src/generated/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type { EventDTO } from './models/EventDTO';
export { EventHistoryDTO } from './models/EventHistoryDTO';
export type { PlaceDTO } from './models/PlaceDTO';
export type { RatingDTO } from './models/RatingDTO';
export type { RequestEventDTO } from './models/RequestEventDTO';
export type { SportDTO } from './models/SportDTO';
export type { UserDTO } from './models/UserDTO';
export type { UserInfoDTO } from './models/UserInfoDTO';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/* eslint-disable */
import type { EventDTO } from '../models/EventDTO';
import type { EventHistoryDTO } from '../models/EventHistoryDTO';
import type { RequestEventDTO } from '../models/RequestEventDTO';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
Expand Down Expand Up @@ -99,15 +98,19 @@ export class EventsControllerService {
});
}
/**
* @param requestEventDto
* @param sportsName
* @param longitude
* @param latitude
* @param page Zero-based page index (0..N)
* @param size The size of the page to be returned
* @param sort Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.
* @returns EventDTO OK
* @throws ApiError
*/
public static getNearbyEvents(
requestEventDto: RequestEventDTO,
sportsName?: Array<string>,
longitude?: number,
latitude?: number,
page?: number,
size: number = 20,
sort?: Array<string>,
Expand All @@ -116,7 +119,9 @@ export class EventsControllerService {
method: 'GET',
url: '/api/v1/event/nearby',
query: {
'requestEventDTO': requestEventDto,
'sportsName': sportsName,
'longitude': longitude,
'latitude': latitude,
'page': page,
'size': size,
'sort': sort,
Expand Down
12 changes: 4 additions & 8 deletions frontend/sportsmatch-app/src/pages/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
EventsControllerService,
ExSecuredEndpointService,
OpenAPI,
RequestEventDTO,
SportDTO,
} from '../generated/api'
import useModal from '../hooks/UseModal'
Expand Down Expand Up @@ -52,16 +51,13 @@ export default function MainPage() {

useEffect(() => {
const fetchData = async () => {
OpenAPI.TOKEN = localStorage.getItem('token')!
try {
const requestEventDTO: RequestEventDTO = {
sportsName: selectedSports,
}
const response = await EventsControllerService.getNearbyEvents(
requestEventDTO,
selectedSports,
0,
0,
0,
20,
undefined,
5,
)
if (!Array.isArray(response)) {
throw new Error('Failed to fetch event data')
Expand Down

0 comments on commit abc4d33

Please sign in to comment.