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

Sma 36 implement the host event page #69

Merged
merged 39 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2241a40
changes in sports and locations
Johna91 Mar 26, 2024
3485181
created HostEventComponent
Johna91 Mar 30, 2024
079eaea
solved problem with choosing options
Johna91 Mar 30, 2024
86a9324
used EventsController for submit
Johna91 Mar 30, 2024
7f52dbe
all data for EventDTO working
Johna91 Apr 7, 2024
1873f6c
Merge branch 'develop' into SMA-36_Implement_the_host_event_page
Johna91 Apr 7, 2024
63a8b8a
created HostEventDTO
Johna91 Apr 9, 2024
e8c6244
created HostEventDTO
Johna91 Apr 9, 2024
75c9cee
created HostEventDTO
Johna91 Apr 9, 2024
5896851
edited HostEventDTO
Johna91 Apr 9, 2024
1cd8e99
edit HostEventDTO in frontend - not working correctly yet
Johna91 Apr 9, 2024
c3a7059
Changes by matfr
Johna91 Apr 11, 2024
72e5637
SMA-36: finishing touches
MatejFrnka Apr 11, 2024
12d76c9
SMA-36: finishing touches
MatejFrnka Apr 11, 2024
fe7d5e1
SMA-69: removed comment
MatejFrnka Apr 11, 2024
8f96234
changes in sports and locations
Johna91 Mar 26, 2024
3f3f7d1
created HostEventComponent
Johna91 Mar 30, 2024
9717699
solved problem with choosing options
Johna91 Mar 30, 2024
d6c930b
used EventsController for submit
Johna91 Mar 30, 2024
e4f89d6
all data for EventDTO working
Johna91 Apr 7, 2024
29dc6c0
created HostEventDTO
Johna91 Apr 9, 2024
d458bbf
created HostEventDTO
Johna91 Apr 9, 2024
f219a6e
created HostEventDTO
Johna91 Apr 9, 2024
59abc35
edited HostEventDTO
Johna91 Apr 9, 2024
97e79b2
edit HostEventDTO in frontend - not working correctly yet
Johna91 Apr 9, 2024
2fe2c0b
Changes by matfr
Johna91 Apr 11, 2024
24bcf32
SMA-36: finishing touches
MatejFrnka Apr 11, 2024
8540bce
SMA-36: finishing touches
MatejFrnka Apr 11, 2024
e8c7b98
SMA-69: removed comment
MatejFrnka Apr 11, 2024
7908a2d
fixed check problems
Johna91 Apr 11, 2024
3f03774
Merge remote-tracking branch 'origin/SMA-36_Implement_the_host_event_…
Johna91 Apr 11, 2024
cc598ab
fixed check problems
Johna91 Apr 13, 2024
95c482c
SMA-36: merge
MatejFrnka Apr 13, 2024
ff59812
SMA-36: regenerated client
MatejFrnka Apr 13, 2024
ce20d3d
SMA-36: frontend updates
MatejFrnka Apr 13, 2024
2af6fa9
fixed check problems
Johna91 Apr 13, 2024
ce21629
SMA-36: merge conflict
MatejFrnka Apr 13, 2024
66104b5
Merge branch 'develop' into SMA-36_Implement_the_host_event_page
MatejFrnka Apr 15, 2024
9fdfba6
SMA-36: build errors fixed
MatejFrnka Apr 15, 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 @@ -29,6 +29,7 @@ public class SportsmatchApplication implements CommandLineRunner {
private final EventRepository eventRepository;
private final PasswordEncoder passwordEncoder;
private final InitProperties initProperties;

private final RatingRepository ratingRepository;
private final UserEventRatingRepository userEventRatingRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sportsmatch.dtos.EventDTO;
import com.sportsmatch.dtos.EventHistoryDTO;
import com.sportsmatch.dtos.HostEventDTO;
import com.sportsmatch.dtos.RequestEventDTO;
import com.sportsmatch.models.Event;
import com.sportsmatch.services.EventService;
Expand Down Expand Up @@ -31,8 +32,8 @@ public ResponseEntity<?> getEvent(@PathVariable("id") Long id) {
}

@PostMapping("")
public ResponseEntity<?> addEvent(@RequestBody @Valid EventDTO eventDTO) {
Event newEvent = eventService.createEvent(eventDTO);
public ResponseEntity<?> addEvent(@RequestBody @Valid HostEventDTO hostEventDTO) {
Event newEvent = eventService.createEvent(hostEventDTO);
return ResponseEntity.status(HttpStatus.CREATED)
.body(eventService.getEventDTObyEventId(newEvent.getId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public class EventDTO {
private String player1Name;
private String player2Name;

@NotNull
private PlaceDTO placeDTO;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sportsmatch.dtos;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class HostEventDTO {

@NotNull
private LocalDateTime dateStart;
@NotNull
private LocalDateTime dateEnd;
@NotNull
private Integer minElo;
@NotNull
private Integer maxElo;
@NotBlank
private String title;
@NotBlank
private String sport;
@NotNull
private Long locationId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@AllArgsConstructor
public class PlaceDTO {

private Long id;

@NotBlank
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sportsmatch.dtos.EventDTO;
import com.sportsmatch.dtos.EventHistoryDTO;
import com.sportsmatch.dtos.HostEventDTO;
import com.sportsmatch.models.Event;
import com.sportsmatch.models.EventPlayer;
import com.sportsmatch.models.EventStatusOptions;
Expand Down Expand Up @@ -44,9 +45,9 @@ public EventDTO convertEventToEventDTO(Event event) {
return eventDTO;
}

public Event convertEventDTOtoEvent(EventDTO eventDTO) {
public Event convertHostEventDTOtoEvent(HostEventDTO hostEventDTO) {
modelMapper.typeMap(EventDTO.class, Event.class).addMappings(e -> e.skip(Event::setId));
return modelMapper.map(eventDTO, Event.class);
return modelMapper.map(hostEventDTO, Event.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class PlaceMapper {
*/
public PlaceDTO toDTO(Place entity) {
return PlaceDTO.builder()
.id(entity.getId())
.name(entity.getName())
.address(entity.getAddress())
.latitude(entity.getLatitude())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import com.sportsmatch.dtos.EventDTO;
import com.sportsmatch.dtos.EventHistoryDTO;
import com.sportsmatch.dtos.HostEventDTO;
import com.sportsmatch.dtos.RequestEventDTO;
import com.sportsmatch.mappers.EventMapper;
import com.sportsmatch.models.Event;
import com.sportsmatch.models.EventPlayer;
import com.sportsmatch.models.EventStatusOptions;
import com.sportsmatch.models.Place;
import com.sportsmatch.models.User;
import com.sportsmatch.repositories.EventPlayerRepository;
import com.sportsmatch.repositories.EventRepository;
import com.sportsmatch.repositories.PlaceRepository;
import com.sportsmatch.repositories.SportRepository;
import com.sportsmatch.repositories.UserRepository;
import lombok.AllArgsConstructor;
Expand All @@ -31,7 +34,7 @@ public class EventService {
private final UserRepository userRepository;
private final SportRepository sportRepository;
private final EventPlayerRepository eventPlayerRepository;

private final PlaceRepository placeRepository;

public Event getEventById(Long id) {
return eventRepository
Expand Down Expand Up @@ -79,23 +82,18 @@ public EventPlayer addPlayerToEvent(Long playerId, Long eventId) {
return eventPlayerRepository.save(eventPlayer);
}

public Event createEvent(EventDTO eventDTO) {
Event newEvent = eventMapper.convertEventDTOtoEvent(eventDTO);
public Event createEvent(HostEventDTO hostEventDTO) {
User user = userService.getUserFromContext();
Event newEvent = eventMapper.convertHostEventDTOtoEvent(hostEventDTO);
Place place = placeRepository.findById(hostEventDTO.getLocationId()).orElseThrow();
newEvent.setPlace(place);
newEvent.setSport(
sportRepository
.findSportByName(eventDTO.getSport())
.findSportByName(hostEventDTO.getSport())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST)));
newEvent = eventRepository.save(newEvent);

Set<EventPlayer> players = new HashSet<>();
if (eventDTO.getPlayer1Id() != null) {
players.add(addPlayerToEvent(eventDTO.getPlayer1Id(), newEvent.getId()));
}
if (eventDTO.getPlayer2Id() != null) {
players.add(addPlayerToEvent(eventDTO.getPlayer2Id(), newEvent.getId()));
}

newEvent.setPlayers(players);
EventPlayer userPlayer = new EventPlayer(null, null, user, newEvent);
eventPlayerRepository.save(userPlayer);
return newEvent;
}

Expand All @@ -107,7 +105,8 @@ public void deleteEventFromDatabase(Event eventById) {
* Retrieves the event history of the logged-in user.
*
* @param pageable contains the pagination information (page, size)
* @return a list of EventHistoryDTOs representing the logged-in user's event history
* @return a list of EventHistoryDTOs representing the logged-in user's event history$ ../gradlew
* clean checkStyleMain -info
*/
public List<EventHistoryDTO> getEventsHistory(final Pageable pageable) {
String loggedUserName = userService.getUserFromContext().getName();
Expand All @@ -122,12 +121,10 @@ public List<EventHistoryDTO> getEventsHistory(final Pageable pageable) {
* Returns the checked status of the match (check the score is matching or missing).
*
* @param players who entered the event (2 playerEvent)
* @return the status of the match
* There is 4 option:
* - Invalid Player -> if one of the player don't present.
* - Waiting for ratings -> if one of the players doesn't response with the score information.
* - Match -> when both player submitted their result and it is match.
* - Mismatch -> when both players have submitted their result, and it isn't a match.
* @return the status of the match There is 4 option: - Invalid Player -> if one of the player
* don't present. - Waiting for ratings -> if one of the players doesn't response with the
* score information. - Match -> when both player submitted their result and it is match. -
* Mismatch -> when both players have submitted their result, and it isn't a match.
*/
public EventStatusOptions checkScoreMatch(Set<EventPlayer> players) {

Expand Down Expand Up @@ -187,18 +184,26 @@ public void joinEvent(Long id) throws Exception {
}

/**
* Finds events near the provided location and filters them based on optional sport names filters, returning a page of event data transfer objects (DTOs).
* Finds events near the provided location and filters them based on optional sport names filters,
* returning a page of event data transfer objects (DTOs).
*
* @param requestEventDTO containing the request parameters for filtering events.
* @param pageable containing page and size
* @return a list of EventDTO representing Events entity and filtered by sport names is given, and coordinate.
* @param pageable containing page and size
* @return a list of EventDTO representing Events entity and filtered by sport names is given, and
* coordinate.
*/
public List<EventDTO> getNearbyEvents(RequestEventDTO requestEventDTO, final Pageable pageable) {

// Convert the given sportNames to lowercase because of the native custom query
List<String> sportNamesWithLowerCase = requestEventDTO.getSportsName().stream().map(String::toLowerCase).toList();

List<Event> events = eventRepository.findNearbyEvents(requestEventDTO.getLongitude(), requestEventDTO.getLatitude(), sportNamesWithLowerCase, pageable);
List<String> sportNamesWithLowerCase =
requestEventDTO.getSportsName().stream().map(String::toLowerCase).toList();

List<Event> events =
eventRepository.findNearbyEvents(
requestEventDTO.getLongitude(),
requestEventDTO.getLatitude(),
sportNamesWithLowerCase,
pageable);

return events.stream().map(eventMapper::convertEventToEventDTO).collect(Collectors.toList());
}
Expand Down
112 changes: 112 additions & 0 deletions frontend/sportsmatch-app/package-lock.json

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

Loading
Loading