Skip to content

Commit

Permalink
SMA-36: merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejFrnka committed Apr 13, 2024
2 parents 2af6fa9 + 36e0a0c commit ce21629
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ResponseEntity<?> deleteEvent(@PathVariable("id") Long id) {
}

@GetMapping("/upcoming-events")
public ResponseEntity<?> getUpcomingEvents(@RequestParam List<Long> sportsIds) {
public ResponseEntity<?> getUpcomingEvents(@RequestBody List<Long> sportsIds) {
List<EventDTO> listOfEvents = eventService.getEventsBySports(sportsIds);
return ResponseEntity.ok().body(listOfEvents);
}
Expand All @@ -71,8 +71,8 @@ public List<EventHistoryDTO> getEventsHistory(@ParameterObject final Pageable pa
* @return a list of Events sorted by distance from the given location. User can filter by sports.
*/
@GetMapping("/nearby")
public List<EventDTO> getNearbyEvents(@RequestParam RequestEventDTO requestEventDTO,
final Pageable pageable) {
public List<EventDTO> getNearbyEvents(@RequestBody RequestEventDTO requestEventDTO,
@ParameterObject final Pageable pageable) {
return eventService.getNearbyEvents(requestEventDTO, pageable);
}

Expand All @@ -92,7 +92,7 @@ public ResponseEntity<?> joinEvent(@PathVariable("id") Long id) {
* @return a list of logged-in user's upcoming EventDTOs ordered by date ascending
*/
@GetMapping("/upcoming-matches")
public List<EventDTO> getUpcomingMatches(@ParameterObject final Pageable pageable) {
return eventService.getUsersUpcomingEvents(pageable);
public List<EventDTO> getUpcomingMatches() {
return eventService.getUsersUpcomingEvents();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sportsmatch.dtos.SportDTO;
import com.sportsmatch.services.SportService;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -24,7 +25,7 @@ public class SportController {
* @return paginated list of SportDTO
*/
@GetMapping("/all")
public List<SportDTO> getSports(final Pageable pageable) {
public List<SportDTO> getSports(@ParameterObject final Pageable pageable) {
return sportService.getAllSports(pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ List<Event> findEventsByUser(
@Param("id") Long id, @Param("now") LocalDateTime now, Pageable pageable);

@Query("SELECT ep.event FROM EventPlayer ep WHERE ep.player.id = :id AND ep.event.dateStart > :now ORDER BY ep.event.dateEnd ASC")
List<Event> findUpcomingEventsByUser(@Param("id") Long id, @Param("now") LocalDateTime now, Pageable pageable);
List<Event> findUpcomingEventsByUser(@Param("id") Long id, @Param("now") LocalDateTime now);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ public List<EventDTO> getNearbyEvents(RequestEventDTO requestEventDTO, final Pag
*
* @return a list of logged-in user's upcoming EventDTOs ordered by date ascending
*/
public List<EventDTO> getUsersUpcomingEvents(Pageable pageable) {
public List<EventDTO> getUsersUpcomingEvents() {
User loggedUser = userService.getUserFromContext();
return eventRepository
.findUpcomingEventsByUser(loggedUser.getId(), LocalDateTime.now(), pageable)
.findUpcomingEventsByUser(loggedUser.getId(), LocalDateTime.now())
.stream()
.map(eventMapper::convertEventToEventDTO)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.sportsmatch.services;

import com.sportsmatch.dtos.SportDTO;
import com.sportsmatch.dtos.UserDTO;
import com.sportsmatch.dtos.UserInfoDTO;
import com.sportsmatch.mappers.SportMapper;
import com.sportsmatch.mappers.UserMapper;
import com.sportsmatch.models.*;
import com.sportsmatch.repositories.SportRepository;
import com.sportsmatch.repositories.UserRepository;
import com.sportsmatch.dtos.SportDTO;
import com.sportsmatch.dtos.UserInfoDTO;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -16,13 +16,11 @@
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -69,16 +67,21 @@ public UserDTO getUserById(Long id) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}

Set<SportUser> sportUsers = user.get().getSportUsers();

List<SportDTO> userSports = sportUsers.stream()
.map(SportUser::getSport)
.map(sportMapper::toDTO)
.toList();

List<EventPlayer> events = new ArrayList<>(user.get().getEventsPlayed());
List<SportDTO> sports = new ArrayList<>();
for (EventPlayer e : events) {
rankService.updatePlayersRanks(e.getEvent());
sports.add(sportMapper.toDTO(e.getEvent().getSport()));
}

return UserDTO.builder()
.name(user.get().getName())
.sports(sports)
.sports(userSports)
.elo(user.get().getRank())
.win(user.get().getWin())
.loss(user.get().getLoss())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void getUserById() {
Sport sport = new Sport();
sport.setId(1L);
sport.setName("Tennis");
sport.setEmoji("🎾");
sport.setEmoji("");
sport.setBackgroundImageURL("./assets/sport-component-tennis.png");

// SportUser
Expand All @@ -125,17 +125,16 @@ void getUserById() {
sports.add(sportDTO);

// Event
Event event = mock(Event.class);
Event event = new Event();
event.setSport(sport);

EventPlayer eventPlayer = mock(EventPlayer.class);

when(eventPlayer.getEvent()).thenReturn(event);
when(eventPlayer.getEvent().getSport()).thenReturn(sport);
// EventPlayer (no need to mock)
EventPlayer eventPlayer = new EventPlayer();
eventPlayer.setEvent(event); // Set the event directly

user.getEventsPlayed().add(eventPlayer);

doNothing().when(rankService).updatePlayersRanks(event);
// No need to mock eventPlayer.getEvent()

UserDTO expectedUserDTO =
UserDTO.builder().name(user.getName()).elo(user.getRank()).sports(sports).build();
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 @@ -11,7 +11,6 @@ export type { AuthRequestDTO } from './models/AuthRequestDTO';
export type { EventDTO } from './models/EventDTO';
export { EventHistoryDTO } from './models/EventHistoryDTO';
export type { HostEventDTO } from './models/HostEventDTO';
export type { Pageable } from './models/Pageable';
export type { PlaceDTO } from './models/PlaceDTO';
export type { RatingDTO } from './models/RatingDTO';
export type { RequestEventDTO } from './models/RequestEventDTO';
Expand Down
10 changes: 0 additions & 10 deletions frontend/sportsmatch-app/src/generated/api/models/Pageable.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
/* eslint-disable */
import type { EventDTO } from '../models/EventDTO';
import type { EventHistoryDTO } from '../models/EventHistoryDTO';
import type { HostEventDTO } from '../models/HostEventDTO';
import type { Pageable } from '../models/Pageable';
import type { RequestEventDTO } from '../models/RequestEventDTO';
import type { HostEventDTO } from '../models/HostEventDTO';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
Expand Down Expand Up @@ -114,20 +113,26 @@ export class EventsControllerService {
}
/**
* @param requestEventDto
* @param pageable
* @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,
pageable: Pageable,
page?: number,
size: number = 20,
sort?: Array<string>,
): CancelablePromise<Array<EventDTO>> {
return __request(OpenAPI, {
method: 'GET',
url: '/api/v1/event/nearby',
query: {
'requestEventDTO': requestEventDto,
'pageable': pageable,
'page': page,
'size': size,
'sort': sort,
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { Pageable } from '../models/Pageable';
import type { SportDTO } from '../models/SportDTO';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class SportControllerService {
/**
* @param pageable
* @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 SportDTO OK
* @throws ApiError
*/
public static getSports(
pageable: Pageable,
page?: number,
size: number = 20,
sort?: Array<string>,
): CancelablePromise<Array<SportDTO>> {
return __request(OpenAPI, {
method: 'GET',
url: '/api/v1/sports/all',
query: {
'pageable': pageable,
'page': page,
'size': size,
'sort': sort,
},
});
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/sportsmatch-app/src/pages/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export default function MainPage() {
}
const response = await EventsControllerService.getNearbyEvents(
requestEventDTO,
{},
0,
20,
undefined,
)
if (!Array.isArray(response)) {
throw new Error('Failed to fetch event data')
Expand Down

0 comments on commit ce21629

Please sign in to comment.