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-22: Add endpoint that returns upcoming events #21

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
@@ -1,7 +1,6 @@
package com.sportsmatch.controllers;

import com.sportsmatch.models.User;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -12,7 +11,6 @@
public class APIController {

@GetMapping("/hello")
@Tag(name = "ex.secured endpoint")
public String hello(Authentication authentication) {
User user = (User) authentication.getPrincipal();
return "Welcome " + user.getName() + " to Secured Endpoint ";
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, for this one these parts should be kept because I rename the endpoint from authenticate to login so its consistent for our use. so these part should be kept. the annotations are for the swagger

  @PostMapping("/login")
  @Tag(name = "Login")
  @Operation(
      summary = "Login user",
      description = "Login a user by providing their email and username.")
  public ResponseEntity<?> login(

Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ public ResponseEntity<?> register(
}
}

@PostMapping("/login")
@Tag(name = "Login")
@Operation(
summary = "Login user",
description = "Login a user by providing their email and username.")
public ResponseEntity<?> login(
@PostMapping("/authenticate")
public ResponseEntity<?> authenticate(
@RequestBody @Valid AuthRequestDTO authRequestDTO, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseEntity.badRequest().body(validationService.getAllErrors(bindingResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/event")
public class EventsController {
Expand Down Expand Up @@ -37,4 +39,10 @@ public ResponseEntity<?> deleteEvent(@PathVariable("id") Long id) {
eventService.deleteEventFromDatabase(eventById);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

@GetMapping("/upcoming-events")
public ResponseEntity<?> getUpcomingEvents(@RequestBody List<Long> sportsIds) {
List<EventDTO> listOfEvents = eventService.getEventsBySports(sportsIds);
return ResponseEntity.ok().body(listOfEvents);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.sportsmatch.repositories;

import com.sportsmatch.models.Event;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface EventRepository extends JpaRepository<Event, Long> {

Optional<Event> findEventById(Long id);

List<Event> findAllBySportIdIn(List<Long> sportId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public List<EventDTO> getAllEvents() {
return eventDTOList;
}

public List<EventDTO> getEventsBySports(List<Long> sportsIds) {
List<EventDTO> eventDTOList = new ArrayList<>();
List<Event> eventListBySport = eventRepository.findAllBySportIdIn(sportsIds);
for (Event event : eventListBySport) {
eventDTOList.add(getEventDTObyEventId(event.getId()));
}
return eventDTOList;
}

public EventPlayer addPlayerToEvent(Long playerId, Long eventId) {
EventPlayer eventPlayer = new EventPlayer();
eventPlayer.setPlayer(
Expand Down
Loading