@PermitAll public class StoryService extends Object
| Constructor and Description |
|---|
StoryService() |
| Modifier and Type | Method and Description |
|---|---|
es.uvigo.esei.microstories.domain.entities.Story |
addReadingLogEntryForA_Story_aux(es.uvigo.esei.microstories.domain.entities.Story story,
Date date) |
void |
addReadingLogEntryForA_Story(Long id)
Adds a new reading log entry for a specific story.
|
Long |
countAllPublishedStories()
Counts the total number of published stories.
|
Long |
countStoriesByFilter(es.uvigo.esei.microstories.domain.types.GenreType genre,
es.uvigo.esei.microstories.domain.types.ThemeType theme,
Date initialDate,
Date finalDate)
Counts the number of stories matching the given filters.
|
Long |
countStoriesByText(String text)
Counts the number of stories matching the given text in either title or content.
|
Long |
countStoriesByUser(String username) |
StoryResponseDto |
createStory(StoryCreateDto storyDto)
Creates a new story for the authenticated CREATOR user.
|
void |
deleteStory(Long id)
Deletes an existing story owned by the authenticated CREATOR user.
|
List<StoryResponseDto> |
getRecentStories(int limit) |
List<StoryResponseDto> |
getStoriesByFilter(es.uvigo.esei.microstories.domain.types.GenreType genre,
es.uvigo.esei.microstories.domain.types.ThemeType theme,
Date initialDate,
Date finalDate,
int page,
int size)
Retrieves stories based on the specified filters with pagination support.
|
List<StoryResponseDto> |
getStoriesByUser_aux(String username,
int page,
int size) |
List<StoryResponseDto> |
getStoriesByUser(String username,
int page,
int size)
Retrieves a paginated list of stories authored by a specific user.
|
StoryResponseDto |
getStoryById(Long id) |
Map<es.uvigo.esei.microstories.domain.types.GenreType,List<StoryResponseDto>> |
getTop2ReadStoriesLastMonthByGenre()
Retrieves the top 2 most read stories from last month grouped by genre.
|
List<StoryResponseDto> |
searchStoriesByText(String text,
int page,
int size)
Busca relatos cuyo título o contenido contenga el texto indicado.
|
StoryResponseDto |
updateStory(Long id,
StoryCreateDto storyDto)
Updates an existing unpublished story owned by the authenticated CREATOR user.
|
public List<StoryResponseDto> getRecentStories(int limit)
public StoryResponseDto getStoryById(Long id)
public List<StoryResponseDto> searchStoriesByText(String text, int page, int size)
text - el texto a buscar en el título o contenido de los relatospage - el número de página (0-based index)size - el número de relatos por páginaStoryResponseDto que coinciden con el texto de búsquedaIllegalArgumentException - si el texto está vacío, page es negativo o size es menor que 1public Long countStoriesByText(String text)
text - the text to search for in the title or content of the storiesIllegalArgumentException - if the search text is emptypublic Long countAllPublishedStories()
public Long countStoriesByFilter(es.uvigo.esei.microstories.domain.types.GenreType genre, es.uvigo.esei.microstories.domain.types.ThemeType theme, Date initialDate, Date finalDate)
genre - the genre to filter by, or null to not filter by genretheme - the theme to filter by, or null to not filter by themeinitialDate - the start of the publication date range (inclusive), or null if not filtering by datefinalDate - the end of the publication date range (inclusive), or null if not filtering by dateIllegalArgumentException - if only one of initialDate or finalDate is provided,
or if initialDate is after finalDatepublic List<StoryResponseDto> getStoriesByFilter(es.uvigo.esei.microstories.domain.types.GenreType genre, es.uvigo.esei.microstories.domain.types.ThemeType theme, Date initialDate, Date finalDate, int page, int size)
This method allows filtering stories by genre, theme, and/or publication date range. When filtering by date, both initial and final dates must be provided together.
genre - the genre to filter by, or null to not filter by genretheme - the theme to filter by, or null to not filter by themeinitialDate - the start of the publication date range (inclusive), or null if not filtering by datefinalDate - the end of the publication date range (inclusive), or null if not filtering by datepage - the page number (0-based index)size - the number of items per page (must be greater than 0)StoryResponseDto objects matching the specified filtersIllegalArgumentException - if only one of initialDate or finalDate is provided,
or if initialDate is after finalDate,
or if page is negative, or size is less than 1public Map<es.uvigo.esei.microstories.domain.types.GenreType,List<StoryResponseDto>> getTop2ReadStoriesLastMonthByGenre()
Stories are ranked by the number of views they received during the previous calendar month. For each genre, up to 2 stories are returned, ordered by view count (descending) and then by publication date (descending).
public void addReadingLogEntryForA_Story(Long id)
This method retrieves a story by its identifier and records a new reading
event associated with the current date and time. If the story does not exist,
an EntityNotFoundException is thrown. The updated story, including
the newly added reading log entry, is then merged back into the persistence
context and flushed to the database.
id - The unique identifier of the story for which a reading log entry
should be added. Must not be null.EntityNotFoundException - if no story exists with the provided id.public es.uvigo.esei.microstories.domain.entities.Story addReadingLogEntryForA_Story_aux(es.uvigo.esei.microstories.domain.entities.Story story,
Date date)
public List<StoryResponseDto> getStoriesByUser(String username, int page, int size)
This method fetches stories written by the given username, ordered by
publication date in descending order (newest first). Pagination is applied
based on the provided page number and page size. If either page or
size is less than 1, an IllegalArgumentException is thrown.
The resulting list of Story entities is transformed into
StoryResponseDto objects before being returned.
username - the username of the author whose stories are to be retrieved;
must not be null.page - the page number to retrieve (1-based index); must be >= 1.size - the number of stories per page; must be >= 1.StoryResponseDto objects representing the stories
authored by the specified user, limited and ordered according to the
pagination parameters.IllegalArgumentException - if page < 1 or size < 1.public List<StoryResponseDto> getStoriesByUser_aux(String username, int page, int size)
@RolesAllowed(value="CREATOR") public StoryResponseDto createStory(StoryCreateDto storyDto)
Draft stories are initially created without a publication date.
storyDto - the story dataStoryResponseDto representing the newly created story.UnauthorizedAccessException - if the user is not authenticated or not a CREATORIllegalArgumentException - if validation fails (e.g., invalid title, too many themes)@RolesAllowed(value="CREATOR") public StoryResponseDto updateStory(Long id, StoryCreateDto storyDto)
id - the unique identifier of the story to update; must not be null.storyDto - the updated story data.StoryResponseDto representing the updated story.UnauthorizedAccessException - if the user is not authenticated, not a CREATOR, or not the authorEntityNotFoundException - if no story exists with the given IDIllegalArgumentException - if the story is published or validation fails@RolesAllowed(value="CREATOR") public void deleteStory(Long id)
id - the unique identifier of the story to delete; must not be null.UnauthorizedAccessException - if the user is not authenticated, not a CREATOR, or not the authorEntityNotFoundException - if no story exists with the given IDCopyright © 2025. All rights reserved.