Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: SMA-84: update modal position to fixed #68

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
717dbad
SMA-84: update modal position to fixed
markpernia Apr 11, 2024
2111c6f
SMA-84: added ParameterObject annotation to pageable
markpernia Apr 11, 2024
4ddeb7b
SMA-84: update index and generate files
markpernia Apr 11, 2024
ce3bfe2
SMA-84: resolve unused setPage by adding load more events button
markpernia Apr 11, 2024
f91bfdf
SMA-89-Remove-String-location-from-EventDTO (#65)
MatejFrnka Apr 12, 2024
6984f61
Sma 90 endpoint api v1 event upcoming events returns 403 no matter wh…
MatejFrnka Apr 12, 2024
4e1eff0
SMA-74: make history view and upcoming match work with the backend (#66)
ivamach Apr 12, 2024
1ac962f
SMA-84: update modal position to fixed
markpernia Apr 11, 2024
bc5e771
SMA-84: added ParameterObject annotation to pageable
markpernia Apr 11, 2024
556d0fc
SMA-84: update index and generate files
markpernia Apr 11, 2024
4fa9955
SMA-84: resolve unused setPage by adding load more events button
markpernia Apr 11, 2024
b5e526b
SMA-84: rebased and update generated file
markpernia Apr 13, 2024
6630b62
SMA-84: resolve conflicts
markpernia Apr 13, 2024
ebb3071
UserDTO from the me endpoint has wrong list of sports (#70)
kz44 Apr 13, 2024
36e0a0c
SMA-87-Add Annotation to the Pageable object (#64)
kz44 Apr 13, 2024
abc4d33
SMA-102: nearby events don t work (#73)
ivamach Apr 13, 2024
40e91c9
SMA-84: update modal position to fixed
markpernia Apr 11, 2024
4943a21
SMA-84: update index and generate files
markpernia Apr 11, 2024
842e9e3
SMA-84: resolve unused setPage by adding load more events button
markpernia Apr 11, 2024
df62f83
SMA-84: added ParameterObject annotation to pageable
markpernia Apr 11, 2024
85e2dc7
SMA-84: resolve conflict
markpernia Apr 13, 2024
7b874d2
SMA-84: resolve conflict
markpernia Apr 13, 2024
481128a
SMA-84: added load more button
markpernia Apr 13, 2024
58ce353
SMA-84: fixed modal alignment to center
markpernia Apr 13, 2024
afd0256
SMA-84: update JoinEvent now elements have space evenly
markpernia Apr 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.sportsmatch.models.Event;
import com.sportsmatch.services.EventService;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -44,7 +45,7 @@ public ResponseEntity<?> deleteEvent(@PathVariable("id") Long id) {
}

@GetMapping("/upcoming-events")
public ResponseEntity<?> getUpcomingEvents(@RequestBody List<Long> sportsIds) {
public ResponseEntity<?> getUpcomingEvents(@RequestParam List<Long> sportsIds) {
List<EventDTO> listOfEvents = eventService.getEventsBySports(sportsIds);
return ResponseEntity.ok().body(listOfEvents);
}
Expand All @@ -56,7 +57,7 @@ public ResponseEntity<?> getUpcomingEvents(@RequestBody List<Long> sportsIds) {
* @return a list of finished EventHistoryDTO of the logged-in user
*/
@GetMapping("/event-history")
public List<EventHistoryDTO> getEventsHistory(final Pageable pageable) {
public List<EventHistoryDTO> getEventsHistory(@ParameterObject final Pageable pageable) {
return eventService.getEventsHistory(pageable);
}

Expand All @@ -69,8 +70,8 @@ public List<EventHistoryDTO> getEventsHistory(final Pageable pageable) {
* @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,
final Pageable pageable) {
public List<EventDTO> getNearbyEvents(@RequestParam RequestEventDTO requestEventDTO,
@ParameterObject final Pageable pageable) {
return eventService.getNearbyEvents(requestEventDTO, pageable);
}

Expand All @@ -83,4 +84,14 @@ public ResponseEntity<?> joinEvent(@PathVariable("id") Long id) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

/**
* This endpoint returns the upcoming matches of the logged-in user.
*
* @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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class EventDTO {
private LocalDateTime dateStart;
@NotNull
private LocalDateTime dateEnd;
@NotBlank
private String location;
@NotNull
private Integer minElo;
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public class SportDTO {
public String emoji;

public String backgroundUImageURL;
public Long id;

public SportDTO(String name, String emoji, String backgroundUImageURL) {
public SportDTO(String name, String emoji, String backgroundUImageURL, Long id) {
this.name = name;
this.emoji = emoji;
this.backgroundUImageURL = backgroundUImageURL;
this.id = id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ public SportDTO toDTO(Sport entity) {
.name(entity.getName())
.emoji(entity.getEmoji())
.backgroundUImageURL(entity.getBackgroundImageURL())
.id(entity.getId())
.build();
}

public Sport toEntity(SportDTO sportDTO) {
return Sport.builder()
.name(sportDTO.getName())
.emoji(sportDTO.getEmoji())
.backgroundImageURL(sportDTO.getBackgroundUImageURL())
.build();
.name(sportDTO.getName())
.emoji(sportDTO.getEmoji())
.backgroundImageURL(sportDTO.getBackgroundUImageURL())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ public interface EventRepository extends JpaRepository<Event, Long> {
/**
* Retrieves events filtered by user and finished status.
*
* @param name the logged user's name to filter events by
* @param now the current time to filter events by
* @param id the logged user's id to filter events by
* @param now the current time to filter events by
* @param pageable pagination information (page, size)
* @return a list of events filtered by user and finished status
*/
// =?1 =?2")
@Query("SELECT ep.event FROM EventPlayer ep WHERE ep.player.name = :name AND ep.event.dateEnd < :now")
@Query("SELECT ep.event FROM EventPlayer ep WHERE ep.player.id = :id AND ep.event.dateEnd < :now")
List<Event> findEventsByUser(
@Param("name") String name,
@Param("now") LocalDateTime now,
Pageable pageable
);
@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);




/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ public void deleteEventFromDatabase(Event eventById) {
*/
public List<EventHistoryDTO> getEventsHistory(final Pageable pageable) {
String loggedUserName = userService.getUserFromContext().getName();
Long loggedUserId = userService.getUserFromContext().getId();

return eventRepository.findEventsByUser(loggedUserName, LocalDateTime.now(), pageable).stream()
return eventRepository.findEventsByUser(loggedUserId, LocalDateTime.now(), pageable).stream()
.map(event -> eventMapper.toDTO(event, loggedUserName, checkScoreMatch(event.getPlayers())))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -201,4 +202,18 @@ public List<EventDTO> getNearbyEvents(RequestEventDTO requestEventDTO, final Pag

return events.stream().map(eventMapper::convertEventToEventDTO).collect(Collectors.toList());
}

/**
* Returns the upcoming matches of the logged-in user.
*
* @return a list of logged-in user's upcoming EventDTOs ordered by date ascending
*/
public List<EventDTO> getUsersUpcomingEvents(Pageable pageable) {
User loggedUser = userService.getUserFromContext();
return eventRepository
.findUpcomingEventsByUser(loggedUser.getId(), LocalDateTime.now(), pageable)
.stream()
.map(eventMapper::convertEventToEventDTO)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.sportsmatch.mappers.SportMapper;
import com.sportsmatch.models.Sport;
import com.sportsmatch.repositories.SportRepository;
import com.sportsmatch.services.SportServiceImp;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -46,8 +45,8 @@ void getAllSportsShouldReturnAllSportsWhenRequired() {
List<Sport> sports = Arrays.asList(sport1, sport2);
Page<Sport> sportsPage = new PageImpl<>(sports, pageable, sports.size());

SportDTO sportDTO1 = new SportDTO("Football", footballEmoji, "urlFootball");
SportDTO sportDTO2 = new SportDTO("Basketball", basketballEmoji, "urlBasketball");
SportDTO sportDTO1 = new SportDTO("Football", footballEmoji, "urlFootball", 1L);
SportDTO sportDTO2 = new SportDTO("Basketball", basketballEmoji, "urlBasketball", 2L);

when(sportMapper.toDTO(sport1)).thenReturn(sportDTO1);
when(sportMapper.toDTO(sport2)).thenReturn(sportDTO2);
Expand Down
51 changes: 48 additions & 3 deletions frontend/sportsmatch-app/src/components/EventHistoryItem.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react'
import { EventHistoryDTO } from '../generated/api'
import '../styles/EventHistoryItem.css'
import Avatar from './Avatar'
Expand All @@ -7,12 +8,44 @@ interface EventHistoryProps {
}

function EventHistoryItem({ eventHistoryDTO }: EventHistoryProps) {
const [eventStatus, setEventStatus] = useState<string>('')

useEffect(() => {
const matchResult =
eventHistoryDTO.userScore! > eventHistoryDTO.opponentScore!
? 'VICTORY'
: eventHistoryDTO.userScore! == eventHistoryDTO.opponentScore!
? 'DRAW'
: 'DEFEAT'
if (
eventHistoryDTO.status?.includes(EventHistoryDTO.status.MATCH) &&
!eventHistoryDTO.status?.includes(EventHistoryDTO.status.MISMATCH)
) {
setEventStatus(matchResult)
} else if (
eventHistoryDTO.status?.includes(
EventHistoryDTO.status.WAITING_FOR_RATING,
)
) {
const result = matchResult + ' (UNCONFIRMED)'
setEventStatus(result)
} else if (
eventHistoryDTO.status?.includes(EventHistoryDTO.status.MISMATCH)
) {
setEventStatus('SCORE MISMATCH')
}
}, [
eventHistoryDTO.opponentScore,
eventHistoryDTO.status,
eventHistoryDTO.userScore,
])

return (
<>
<div className="container-fluid">
<div className={'row'}>
<div className="event-history-item">
<div className="match-status">VICTORY (uncorfirmed)</div>
<div className="match-status">{eventStatus}</div>
<div className="user-side">
<div className="profile">
<div className="user-avatar">
Expand All @@ -21,15 +54,27 @@ function EventHistoryItem({ eventHistoryDTO }: EventHistoryProps) {
<div className="user-name">You</div>
</div>
<div className="user-score score">
<span>{eventHistoryDTO.userScore}</span>
<span>
{eventHistoryDTO.status?.includes(
EventHistoryDTO.status.MISMATCH,
)
? '?'
: eventHistoryDTO.userScore}
</span>
</div>
</div>
<div className="colon">
<span>:</span>
</div>
<div className="opponent-side">
<div className="opponent-score score">
<span>{eventHistoryDTO.opponentScore}</span>
<span>
{eventHistoryDTO.status?.includes(
EventHistoryDTO.status.MISMATCH,
)
? '?'
: eventHistoryDTO.opponentScore}
</span>
</div>
<div className="profile">
<div className="opponent-avatar">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function JoinEventComponent(p: JoinEventProps) {
<p className="text-center">
You want to join <b>{p.event.sport}</b>
{' at ' +
p.event.location +
p.event.placeDTO?.name +
' on ' +
date.toLocaleDateString('en', { month: 'long' }) +
' ' +
Expand Down Expand Up @@ -90,7 +90,7 @@ export default function JoinEventComponent(p: JoinEventProps) {
<div className="col-12">
<p className="join-event-message">
Your rank is too low/high to join <b>{p.event.sport}</b> at{' '}
{p.event.location}
{p.event.placeDTO?.name}
</p>
</div>
</div>
Expand Down
69 changes: 51 additions & 18 deletions frontend/sportsmatch-app/src/components/Match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,42 @@ import {
LuSettings2,
} from 'react-icons/lu'
import { Link } from 'react-router-dom'
import { EventDTO } from '../generated/api/models/EventDTO'
import { useEffect, useState } from 'react'
import { ExSecuredEndpointService, OpenAPI, UserDTO } from '../generated/api'

interface InProgressProps {
event: {
id: number
maxElo: number
minElo: number
dateEnd: string
dateStart: string
location: string
title: string
sport: string
playerOne: string
playerTwo?: string
}
event: EventDTO
}

function InProgress({ event }: InProgressProps) {
const [currentUser, setCurrentUser] = useState<UserDTO>()
useEffect(() => {
OpenAPI.TOKEN = localStorage.getItem('token')!
const fetchUserInfo = async () => {
setCurrentUser(
(await ExSecuredEndpointService.getUserMainPage()) as UserDTO,
)
}
fetchUserInfo()
}, [])

const eventDate = new Date(
parseInt(event.dateStart[0]),
parseInt(event.dateStart[1]),
parseInt(event.dateStart[2]),
)

const eventStartTime = () => {
const hour = event.dateStart[3]
const min = event.dateStart[4] === '0' ? '00' : event.dateStart[4]
return hour + ':' + (min.length === 1 ? min + '0' : min)
}
const eventEndTime = () => {
const hour = event.dateEnd[3]
const min = event.dateEnd[4] === '0' ? '00' : event.dateEnd[4]
return hour + ':' + (min.length === 1 ? min + '0' : min)
}
return (
<>
<div className="container-fluid">
Expand All @@ -37,7 +56,7 @@ function InProgress({ event }: InProgressProps) {
>
<LuSettings2 />
</Link>
{event.playerTwo === null ? (
{event.player2Id === null ? (
<h1>
Matchmaking
<br /> in progress
Expand All @@ -51,25 +70,39 @@ function InProgress({ event }: InProgressProps) {
<ul>
<li>
<LuSwords />{' '}
{event.playerTwo === null
{event.player2Id === null
? 'Awaiting opponent...'
: event.playerTwo}
: event.player1Name === currentUser?.name
? event.player2Name
: event.player1Name}
</li>
<li>
<LuMapPin />
{event.location}
{event.placeDTO?.name}
</li>
<li>
<LuMedal />
{event.minElo} - {event.maxElo}
</li>
<li>
<LuCalendarCheck />
{event.dateStart}
{eventDate.getDay() +
'.' +
eventDate.getMonth() +
'.' +
eventDate.getFullYear() +
', ' +
eventStartTime()}
</li>
<li>
<LuCalendarX />
{event.dateEnd}
{eventDate.getDay() +
'.' +
eventDate.getMonth() +
'.' +
eventDate.getFullYear() +
', ' +
eventEndTime()}
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default function RateGameComponent(p: Props) {
{myEvent.dateEnd[3]}:{myEvent.dateEnd[4]}
</span>
<br />
<span>{myEvent.location}</span>{' '}
<span>{myEvent.placeDTO?.name}</span>{' '}
</>
) : (
<div></div>
Expand Down
Loading
Loading