From d50d7a272bf09c904bf1cf2599b4102af322618c Mon Sep 17 00:00:00 2001 From: Tomas Sanchez Date: Thu, 20 Apr 2023 23:46:16 -0300 Subject: [PATCH] chore: release 0.1.0 - remove unused files - remove (some) unused functions - reorganize project structure --- README.md | 1 + .../grupo3/meetings/api/DTO/AttendeeDTO.java | 5 - .../com/grupo3/meetings/api/DTO/EventDTO.java | 77 ------ .../meetings/api/DTO/NewGuestInEventDTO.java | 18 -- .../grupo3/meetings/api/DTO/OptionDTO.java | 44 --- .../meetings/api/DTO/VoteOptionDTO.java | 35 --- .../grupo3/meetings/api/EventController.java | 236 ++++++++-------- .../com/grupo3/meetings/api/FooController.kt | 37 --- .../grupo3/meetings/api/UsersController.kt | 81 +++--- .../com/grupo3/meetings/domain/Event.java | 247 ----------------- .../com/grupo3/meetings/domain/Option.java | 87 ------ .../grupo3/meetings/domain/Statistics.java | 4 - .../java/com/grupo3/meetings/domain/User.java | 20 -- .../meetings/domain/dto/AttendeeDTO.java | 5 + .../grupo3/meetings/domain/dto/EventDTO.java | 69 +++++ .../domain/dto/NewGuestInEventDTO.java | 21 ++ .../grupo3/meetings/domain/dto/OptionDTO.java | 41 +++ .../domain => domain/dto}/UpdateUserParams.kt | 2 +- .../com/grupo3/meetings/domain/dto/UserDTO.kt | 3 + .../meetings/domain/dto/VoteOptionDTO.java | 35 +++ .../grupo3/meetings/domain/models/Event.java | 261 ++++++++++++++++++ .../grupo3/meetings/domain/models/Option.java | 77 ++++++ .../meetings/domain/models/Statistics.java | 5 + .../com/grupo3/meetings/domain/models/User.kt | 6 + .../event/OptionNotFoundException.java | 15 +- .../meetings/repository/EventRepository.java | 128 ++++----- .../repository/InMemoryUserRepository.kt | 41 +++ .../meetings/repository/UserRepository.java | 20 -- .../meetings/repository/UserRepository.kt | 16 ++ .../grupo3/meetings/service/EventService.java | 176 ++++++------ .../service/user/BcryptHashService.kt | 19 ++ .../meetings/service/user/HashService.kt | 9 + .../meetings/service/user/UserService.kt | 54 ++++ .../meetings/users/core/actions/CreateUser.kt | 15 - .../users/core/actions/GetAllUsers.kt | 17 -- .../users/core/actions/GetUserById.kt | 18 -- .../meetings/users/core/actions/UpdateUser.kt | 16 -- .../meetings/users/core/domain/HashService.kt | 10 - .../grupo3/meetings/users/core/domain/User.kt | 4 - .../meetings/users/core/domain/UserDTO.kt | 3 - .../users/core/domain/UserRepository.kt | 13 - .../meetings/users/core/domain/UserService.kt | 47 ---- .../users/infrastructure/BcryptHashService.kt | 18 -- .../infrastructure/InMemoryUserRepository.kt | 42 --- .../controller/EventControllerTest.java | 102 ++----- .../grupo3/meetings/controller/eventos.json | 3 - .../grupo3/meetings/domain/EventTests.java | 257 ++++++++--------- .../grupo3/meetings/domain/OptionTests.java | 92 +++--- .../meetings/domain/UserControllerTests.java | 194 +++++++------ .../repository/InMemoryUserRepositoryTest.kt | 55 ++++ .../meetings/service/UserServiceTest.kt | 104 +++++++ .../users/core/domain/UserServiceTest.kt | 97 ------- .../InMemoryUserRepositoryTest.kt | 55 ---- 53 files changed, 1445 insertions(+), 1612 deletions(-) delete mode 100644 rest/src/main/java/com/grupo3/meetings/api/DTO/AttendeeDTO.java delete mode 100644 rest/src/main/java/com/grupo3/meetings/api/DTO/EventDTO.java delete mode 100644 rest/src/main/java/com/grupo3/meetings/api/DTO/NewGuestInEventDTO.java delete mode 100644 rest/src/main/java/com/grupo3/meetings/api/DTO/OptionDTO.java delete mode 100644 rest/src/main/java/com/grupo3/meetings/api/DTO/VoteOptionDTO.java delete mode 100644 rest/src/main/java/com/grupo3/meetings/api/FooController.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/domain/Event.java delete mode 100644 rest/src/main/java/com/grupo3/meetings/domain/Option.java delete mode 100644 rest/src/main/java/com/grupo3/meetings/domain/Statistics.java delete mode 100644 rest/src/main/java/com/grupo3/meetings/domain/User.java create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/dto/AttendeeDTO.java create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/dto/EventDTO.java create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/dto/NewGuestInEventDTO.java create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/dto/OptionDTO.java rename rest/src/main/java/com/grupo3/meetings/{users/core/domain => domain/dto}/UpdateUserParams.kt (53%) create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/dto/UserDTO.kt create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/dto/VoteOptionDTO.java create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/models/Event.java create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/models/Option.java create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/models/Statistics.java create mode 100644 rest/src/main/java/com/grupo3/meetings/domain/models/User.kt create mode 100644 rest/src/main/java/com/grupo3/meetings/repository/InMemoryUserRepository.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/repository/UserRepository.java create mode 100644 rest/src/main/java/com/grupo3/meetings/repository/UserRepository.kt create mode 100644 rest/src/main/java/com/grupo3/meetings/service/user/BcryptHashService.kt create mode 100644 rest/src/main/java/com/grupo3/meetings/service/user/HashService.kt create mode 100644 rest/src/main/java/com/grupo3/meetings/service/user/UserService.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/actions/CreateUser.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/actions/GetAllUsers.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/actions/GetUserById.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/actions/UpdateUser.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/domain/HashService.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/domain/User.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/domain/UserDTO.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/domain/UserRepository.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/core/domain/UserService.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/infrastructure/BcryptHashService.kt delete mode 100644 rest/src/main/java/com/grupo3/meetings/users/infrastructure/InMemoryUserRepository.kt delete mode 100644 rest/src/test/java/com/grupo3/meetings/controller/eventos.json create mode 100644 rest/src/test/java/com/grupo3/meetings/repository/InMemoryUserRepositoryTest.kt create mode 100644 rest/src/test/java/com/grupo3/meetings/service/UserServiceTest.kt delete mode 100644 rest/src/test/java/com/grupo3/meetings/users/core/domain/UserServiceTest.kt delete mode 100644 rest/src/test/java/com/grupo3/meetings/users/infrastructure/InMemoryUserRepositoryTest.kt diff --git a/README.md b/README.md index 8c57844..32c87ed 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![REST API Build](https://github.com/tomasanchez/grupo-3-tacs/actions/workflows/rest.yml/badge.svg)](https://github.com/tomasanchez/grupo-3-tacs/actions/workflows/rest.yml) [![REST Image Build](https://github.com/tomasanchez/grupo-3-tacs/actions/workflows/rest-image.yml/badge.svg)](https://github.com/tomasanchez/grupo-3-tacs/actions/workflows/rest-image.yml) +[![WEB Image Build](https://github.com/tomasanchez/grupo-3-tacs/actions/workflows/web-image.yml/badge.svg)](https://github.com/tomasanchez/grupo-3-tacs/actions/workflows/web-image.yml) Meetings is an application developed by `Group-3` during the course Advanced Technologies in Software Construction, as was taught during first semester of 2023. diff --git a/rest/src/main/java/com/grupo3/meetings/api/DTO/AttendeeDTO.java b/rest/src/main/java/com/grupo3/meetings/api/DTO/AttendeeDTO.java deleted file mode 100644 index d21f19a..0000000 --- a/rest/src/main/java/com/grupo3/meetings/api/DTO/AttendeeDTO.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.grupo3.meetings.api.DTO; - -public class AttendeeDTO { - -} diff --git a/rest/src/main/java/com/grupo3/meetings/api/DTO/EventDTO.java b/rest/src/main/java/com/grupo3/meetings/api/DTO/EventDTO.java deleted file mode 100644 index 2ef0a81..0000000 --- a/rest/src/main/java/com/grupo3/meetings/api/DTO/EventDTO.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.grupo3.meetings.api.DTO; - - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class EventDTO { - - private String nombreDeEvento; - private String descripcion; - private String ubicacion; - private String username; - List options; - - public EventDTO(String nombreDeEvento, String descripcion, String ubicacion, String userAdmin, List options) { - this.nombreDeEvento = nombreDeEvento; - this.descripcion = descripcion; - this.ubicacion = ubicacion; - this.username = userAdmin; - this.options= options; -// this.guests= new HashSet<>(); - } - - public EventDTO(String reunionDeDiscord) { - this.nombreDeEvento = reunionDeDiscord; - } - - public String getNombreDeEvento() { - return nombreDeEvento; - } - - public void setNombreDeEvento(String nombreDeEvento) { - this.nombreDeEvento = nombreDeEvento; - } - - public String getDescripcion() { - return descripcion; - } - - public void setDescripcion(String descripcion) { - this.descripcion = descripcion; - } - - public String getUbicacion() { - return ubicacion; - } - - public void setUbicacion(String ubicacion) { - this.ubicacion = ubicacion; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - - public List getOptions() { - return options; - } - - public void setOptions(List options) { - this.options = options; - } - -// public Set getGuests() { -// return guests; -// } -// -// public void setGuests(Set guests) { -// this.guests = guests; -// } -} diff --git a/rest/src/main/java/com/grupo3/meetings/api/DTO/NewGuestInEventDTO.java b/rest/src/main/java/com/grupo3/meetings/api/DTO/NewGuestInEventDTO.java deleted file mode 100644 index c3c65c6..0000000 --- a/rest/src/main/java/com/grupo3/meetings/api/DTO/NewGuestInEventDTO.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.grupo3.meetings.api.DTO; - -public class NewGuestInEventDTO { - private String guest; - public NewGuestInEventDTO() { - } - - public NewGuestInEventDTO(String guest) { - this.guest = guest; - } - public String getGuest() { - return guest; - } - - public void setGuest(String guest) { - this.guest = guest; - } -} diff --git a/rest/src/main/java/com/grupo3/meetings/api/DTO/OptionDTO.java b/rest/src/main/java/com/grupo3/meetings/api/DTO/OptionDTO.java deleted file mode 100644 index 742436e..0000000 --- a/rest/src/main/java/com/grupo3/meetings/api/DTO/OptionDTO.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.grupo3.meetings.api.DTO; - -import com.grupo3.meetings.domain.Option; - -import java.time.DayOfWeek; -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; - -public class OptionDTO { -// private DayOfWeek day; - private LocalDate date; - private LocalTime time; -// private Set votes; - - public OptionDTO(LocalDate day, LocalTime time) { - this.time = time; - this.date = day; -// this.votes = new HashSet<>(); - } - public LocalTime getTime() { - return time; - } - - public void setTime(LocalTime time) { - this.time = time; - } - - - public LocalDate getDate() { - return date; - } - - public void setDate(LocalDate date) { - this.date = date; - } - - public Option toOptionForEvent() { - return new Option(this.date, this.time); - } - -} diff --git a/rest/src/main/java/com/grupo3/meetings/api/DTO/VoteOptionDTO.java b/rest/src/main/java/com/grupo3/meetings/api/DTO/VoteOptionDTO.java deleted file mode 100644 index 8eaf560..0000000 --- a/rest/src/main/java/com/grupo3/meetings/api/DTO/VoteOptionDTO.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.grupo3.meetings.api.DTO; - -import com.grupo3.meetings.domain.Option; - -public class VoteOptionDTO { - private String username; - private OptionDTO option; - - public VoteOptionDTO() { - } - public VoteOptionDTO(String username, OptionDTO option) { - this.username = username; - this.option = option; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public OptionDTO getOption() { - return option; - } - - public void setOption(OptionDTO option) { - this.option = option; - } - - public String getUserId() { - return this.username; - } -} diff --git a/rest/src/main/java/com/grupo3/meetings/api/EventController.java b/rest/src/main/java/com/grupo3/meetings/api/EventController.java index f2f9db9..c677996 100644 --- a/rest/src/main/java/com/grupo3/meetings/api/EventController.java +++ b/rest/src/main/java/com/grupo3/meetings/api/EventController.java @@ -1,148 +1,136 @@ package com.grupo3.meetings.api; -import com.grupo3.meetings.api.DTO.EventDTO; -import com.grupo3.meetings.api.DTO.NewGuestInEventDTO; -import com.grupo3.meetings.api.DTO.VoteOptionDTO; -import com.grupo3.meetings.domain.Event; -import com.grupo3.meetings.domain.Option; -import com.grupo3.meetings.domain.Statistics; -import com.grupo3.meetings.exceptions.event.*; +import com.grupo3.meetings.domain.dto.EventDTO; +import com.grupo3.meetings.domain.dto.NewGuestInEventDTO; +import com.grupo3.meetings.domain.dto.VoteOptionDTO; +import com.grupo3.meetings.domain.models.Event; +import com.grupo3.meetings.domain.models.Option; +import com.grupo3.meetings.domain.models.Statistics; +import com.grupo3.meetings.exceptions.event.EventNotFoundException; +import com.grupo3.meetings.exceptions.event.OptionNotFoundException; +import com.grupo3.meetings.exceptions.event.UnauthorizedUserException; import com.grupo3.meetings.service.EventService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; +import java.util.NoSuchElementException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.NoSuchElementException; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController -//@RequestMapping("/api/events") -@RequestMapping(value = {"/api/events", "api/events/"}) +@RequestMapping(value = {"api/v1/events/"}) @Tag(name = "Events", description = "API URLs Events") public class EventController { - @Autowired - private EventService eventService; + @Autowired + private EventService eventService; - @Operation(summary = "Create Event", description = "Creates a new event with the specified options") - @PostMapping("") - public ResponseEntity createEvent(@RequestBody EventDTO eventDTO) { - Event event = eventService.createEvent(eventDTO); - return ResponseEntity.status(HttpStatus.CREATED).body(event); - } + @Operation(summary = "Create Event", description = "Creates a new event with the specified options") + @PostMapping("") + public ResponseEntity createEvent(@RequestBody EventDTO eventDTO) { + Event event = eventService.createEvent(eventDTO); + return ResponseEntity.status(HttpStatus.CREATED).body(event); + } - @Operation(summary = "Get Event", description = "Returns the specified event with its associated availability options and votes") - @GetMapping("/{eventId}") - public ResponseEntity getEvent(@PathVariable Long eventId) { - Event event = eventService.getEvent(eventId); - if (event == null) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Event with id " + eventId + " does not exist"); - } - return ResponseEntity.ok(event); + @Operation(summary = "Get Event", description = "Returns the specified event with its associated availability options and votes") + @GetMapping("/{eventId}") + public ResponseEntity getEvent(@PathVariable Long eventId) { + Event event = eventService.getEvent(eventId); + if (event == null) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body("Event with id " + eventId + " does not exist"); } - - @Operation(summary = "Update Event", description = "Updates the specified event with new information") - @PatchMapping("/{eventId}") - public ResponseEntity updateEvent(@PathVariable Long eventId, @RequestBody EventDTO eventDTO) { - try { - Event event = eventService.updateEvent(eventId, eventDTO); - return ResponseEntity.ok(event); - } catch (EventNotFoundException e) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Event with id " + eventId + " does not exist"); - } catch (UnauthorizedUserException e) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); - } + return ResponseEntity.ok(event); + } + + @Operation(summary = "Update Event", description = "Updates the specified event with new information") + @PatchMapping("/{eventId}") + public ResponseEntity updateEvent(@PathVariable Long eventId, @RequestBody EventDTO eventDTO) { + try { + Event event = eventService.updateEvent(eventId, eventDTO); + return ResponseEntity.ok(event); + } catch (EventNotFoundException e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body("Event with id " + eventId + " does not exist"); + } catch (UnauthorizedUserException e) { + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); } - - @Operation(summary = "Get All Events", description = "Returns a list of all events created") - @GetMapping("") - public ResponseEntity> getAllEvents() { - List events = eventService.getAllEvents(); - return ResponseEntity.ok(events); + } + + @Operation(summary = "Get All Events", description = "Returns a list of all events created") + @GetMapping("") + public ResponseEntity> getAllEvents() { + List events = eventService.getAllEvents(); + return ResponseEntity.ok(events); + } + + @Operation(summary = "Add Option to Event", description = "Adds a new option to the specified event") + @PostMapping("/{eventId}/options") + public ResponseEntity addOption( + @PathVariable String eventId, + @RequestBody VoteOptionDTO optionRequest + ) { + try { + Option option = new Option(optionRequest); + Event evento = eventService.addOptionForUser(eventId, option, optionRequest.getUserId()); + + return ResponseEntity.ok(evento); + } catch (NoSuchElementException e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body("Event with id " + eventId + " does not exist"); + } catch (EventNotFoundException e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage()); + } catch (IllegalArgumentException e) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); } - - @Operation(summary = "Add Option to Event", description = "Adds a new option to the specified event") - @PostMapping("/{eventId}/options") - public ResponseEntity addOption( - @PathVariable String eventId, - @RequestBody VoteOptionDTO optionRequest - ) { - try { - Option option = new Option(optionRequest); - Event evento = eventService.addOptionForUser(eventId, option, optionRequest.getUserId()); - - return ResponseEntity.ok(evento); - } catch (NoSuchElementException e) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Event with id " + eventId + " does not exist"); - } catch (EventNotFoundException e) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage()); - } catch (IllegalArgumentException e) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); - } - } - - - @Operation(summary = "Close Event Voting", description = "Closes the voting period for the specified event (if the event was created by the authenticated user)") - @PutMapping("/{eventId}") - public ResponseEntity closeEventVoting(@PathVariable Long eventId) { - try { - Event event = eventService.closeEventVoting(eventId); - return ResponseEntity.ok(event); - } catch (EventNotFoundException e) { - return ResponseEntity.notFound().build(); - } catch (UnauthorizedUserException e) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); - } + } + + + @Operation(summary = "Close Event Voting", description = "Closes the voting period for the specified event (if the event was created by the authenticated user)") + @PutMapping("/{eventId}") + public ResponseEntity closeEventVoting(@PathVariable Long eventId) { + try { + Event event = eventService.closeEventVoting(eventId); + return ResponseEntity.ok(event); + } catch (EventNotFoundException e) { + return ResponseEntity.notFound().build(); + } catch (UnauthorizedUserException e) { + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); } - - @Operation(summary = "Get Statistics", description = "Returns statistics on the number of events and votes cast in the last 2 hours") - @GetMapping("/statistics") - public ResponseEntity getStatistics() { - Statistics statistics = eventService.getStatistics(); - return ResponseEntity.ok(statistics); - } - -// @Operation(summary = "Add Attendee and Vote", description = "Adds an attendee to the specified event with the specified availability options and votes for them") -// @PostMapping("/{eventId}/attendees") -// public ResponseEntity addAttendeeAndVote(@PathVariable String eventId, @RequestBody VoteOptionDTO attendeeAndVoteDTO) { -// if (validateEventExists(eventId)) { -// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Event " + eventId + " not found"); -// } -// -// Event event = eventService.addAttendeeAndVote(eventId, attendeeAndVoteDTO); -// return ResponseEntity.status(HttpStatus.CREATED).body(event); -// } -// -// -// private boolean validateEventExists(String eventId) { -// return eventService.existsById(eventId); -// } - - @Operation(summary = "Vote on an Event", description = "Allows a user to vote on a specified event") - @PostMapping("/{eventId}/attendees") - public ResponseEntity voteOnEvent(@PathVariable Long eventId, @RequestBody NewGuestInEventDTO voteOptionDTO) { - try { - Event event = eventService.voteOnEvent(eventId, voteOptionDTO); - return ResponseEntity.ok(event); - } catch (EventNotFoundException e) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Event with id " + eventId + " does not exist"); - } -// catch (UserNotFoundException e) { -// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User with id " + userId + " does not exist"); -// } - catch (OptionNotFoundException e) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid option selected"); - } -// catch (DuplicateVoteException e) { -// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("User has already voted on this event"); -// } catch (VotingClosedException e) { -// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Voting period for this event has ended"); -// } + } + + @Operation(summary = "Get Statistics", description = "Returns statistics on the number of events and votes cast in the last 2 hours") + @GetMapping("/statistics") + public ResponseEntity getStatistics() { + Statistics statistics = eventService.getStatistics(); + return ResponseEntity.ok(statistics); + } + + + @Operation(summary = "Vote on an Event", description = "Allows a user to vote on a specified event") + @PostMapping("/{eventId}/attendees") + public ResponseEntity voteOnEvent(@PathVariable Long eventId, + @RequestBody NewGuestInEventDTO voteOptionDTO) { + try { + Event event = eventService.voteOnEvent(eventId, voteOptionDTO); + return ResponseEntity.ok(event); + } catch (EventNotFoundException e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body("Event with id " + eventId + " does not exist"); + } catch (OptionNotFoundException e) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid option selected"); } + } } diff --git a/rest/src/main/java/com/grupo3/meetings/api/FooController.kt b/rest/src/main/java/com/grupo3/meetings/api/FooController.kt deleted file mode 100644 index 6b022b8..0000000 --- a/rest/src/main/java/com/grupo3/meetings/api/FooController.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.grupo3.meetings.api - -import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController - -data class Foo(val id: Long, val name: String) - - -@RestController -@RequestMapping("/api/v1/foo") -@Tag(name = "Foo", description = "The Foo API") -class FooController { - - companion object { - private val log = org.slf4j.LoggerFactory.getLogger(FooController::class.java) - } - - @Operation(summary = "Find All Foo", - description = "Gets all foo resources in the system",) - @GetMapping - fun getAllFoo(): List{ - log.debug("Requested Foo list") - return listOf(Foo(1, "foo"), Foo(2, "foo")) - } - - @Operation(summary = "Foo by ID", - description = "Gets a single Foo resource by its unique ID") - @GetMapping("/{id}") - fun getFoo(@PathVariable id: Long): Foo { - log.debug("Requested Foo with id: $id") - return Foo(id, "foo") - } -} diff --git a/rest/src/main/java/com/grupo3/meetings/api/UsersController.kt b/rest/src/main/java/com/grupo3/meetings/api/UsersController.kt index 9c5827c..60cd727 100644 --- a/rest/src/main/java/com/grupo3/meetings/api/UsersController.kt +++ b/rest/src/main/java/com/grupo3/meetings/api/UsersController.kt @@ -1,49 +1,56 @@ package com.grupo3.meetings.api -import com.grupo3.meetings.users.core.domain.* +import com.grupo3.meetings.domain.dto.UpdateUserParams +import com.grupo3.meetings.domain.dto.UserDTO +import com.grupo3.meetings.domain.models.User +import com.grupo3.meetings.domain.models.UserId +import com.grupo3.meetings.service.user.UserService import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.beans.factory.annotation.Autowired -import org.springframework.web.bind.annotation.DeleteMapping -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PatchMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* + @RestController @RequestMapping("/api/v1/users") @Tag(name = "Users", description = "The Users API") -class UsersController ( - @Autowired - private val service: UserService -){ - @Operation (summary = "Creates a User", - description = "Creates a new user in the system",) - @PostMapping - fun createUser(@RequestBody userDTO: UserDTO): User{ - return service.create(userDTO) - } +class UsersController( + @Autowired + private val service: UserService +) { + + @Operation( + summary = "Creates a User", + description = "Creates a new user in the system", + ) + @PostMapping + fun createUser(@RequestBody userDTO: UserDTO): User { + return service.create(userDTO) + } - @Operation(summary = "Find All Users", - description = "Gets all users in the system",) - @GetMapping - fun getAllUsers(): List{ - return service.getAll() - } + @Operation( + summary = "Find All Users", + description = "Gets all users in the system", + ) + @GetMapping + fun getAllUsers(): List { + return service.getAll() + } - @Operation(summary = "Find User by Id", - description = "Get user by Id",) - @GetMapping("/{id}") - fun getUserById(@PathVariable id: UserId): User?{ - return service.getById(id) - } + @Operation( + summary = "Find User by Id", + description = "Get user by Id", + ) + @GetMapping("/{id}") + fun getUserById(@PathVariable id: UserId): User { + return service.getById(id) + } - @Operation (summary = "Updates a User", - description = "Updates a user in the system",) - @PatchMapping("/{id}") - fun updateUser(@PathVariable id: UserId, @RequestBody userParams: UpdateUserParams): User? { - return service.update(id, userParams) - } + @Operation( + summary = "Updates a User", + description = "Updates a user in the system", + ) + @PatchMapping("/{id}") + fun updateUser(@PathVariable id: UserId, @RequestBody userParams: UpdateUserParams): User? { + return service.update(id, userParams) + } } \ No newline at end of file diff --git a/rest/src/main/java/com/grupo3/meetings/domain/Event.java b/rest/src/main/java/com/grupo3/meetings/domain/Event.java deleted file mode 100644 index 22244b8..0000000 --- a/rest/src/main/java/com/grupo3/meetings/domain/Event.java +++ /dev/null @@ -1,247 +0,0 @@ -package com.grupo3.meetings.domain; - -import com.grupo3.meetings.api.DTO.EventDTO; -import com.grupo3.meetings.api.DTO.OptionDTO; -import com.grupo3.meetings.exceptions.event.EventIsClosedException; -import com.grupo3.meetings.exceptions.event.UserNotAdministratorException; -import com.grupo3.meetings.exceptions.option.NoOptionVotedException; -import com.grupo3.meetings.exceptions.event.UserNotInGuestListException; -import com.grupo3.meetings.exceptions.option.OptionDoesntExistException; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.*; -import java.util.stream.Collectors; - -@Getter @Setter @NoArgsConstructor -public class Event { - private String id; - private String title; - private String description; - private String location; - private User administrator; - private Set listOfGuests; - private Option votedOption; - private Set