Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/custom-annotations-and-exception…
Browse files Browse the repository at this point in the history
…-handling' into custom-annotations-and-exception-handling

# Conflicts:
#	src/main/java/com/linkurlshorter/urlshortener/link/LinkInfoResponse.java
#	src/main/java/com/linkurlshorter/urlshortener/link/LinkService.java
  • Loading branch information
Vlasosik committed Apr 18, 2024
2 parents b722f9a + 26f3c18 commit 88731af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import lombok.NoArgsConstructor;

import java.util.List;

/**
* Data transfer object (DTO) for representing a response containing link information.
* This class encapsulates a list of {@link LinkInfoDto} objects representing link information,
* along with an optional error message.
* Represents a response containing information about a link.
* This class provides various properties related to a link, such as its ID, long link,
* short link, creation time, expiration time, usage statistics, and status.
* Instances of this class can be created using the provided builder pattern.
*
* @author Artem Poliakov
* @version 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public Link save(Link link) {
* @throws NullLinkPropertyException If the 'link' parameter is null.
* @throws DeletedLinkException If the link has been marked as deleted.
*/

public Link update(Link link) {
if (Objects.isNull(link)) {
throw new NullLinkPropertyException();
Expand Down Expand Up @@ -88,19 +89,20 @@ public Link findByShortLink(String shortLink) {
return link;
}

public List<Link> findAllByUserId(UUID userId){
if(Objects.isNull(userId)){
public List<Link> findAllByUser(User user) {
if (Objects.isNull(user)) {
throw new NullLinkPropertyException();
}
return linkRepository.findAllByUserId(userId);
}

public List<LinkStatisticsDto> getLinkUsageStatsByUserId(UUID userId){
if(Objects.isNull(userId)){
public List<LinkStatisticsDto> getLinkUsageStatsByUserId(UUID userId) {
if (Objects.isNull(userId)) {
throw new NullLinkPropertyException();
}
return linkRepository.getLinkUsageStatsForUser(userId);
}

/**
* Marks a link entity as deleted by its short link.
*
Expand All @@ -124,23 +126,6 @@ public void deleteById(UUID id) { //TODO: needs test
}
linkRepository.deleteById(id);
}
/**
* Searches for a unique existing link by a short link.
* If an active link is found for the specified short link, returns that link.
*
* @param shortLink A string representing the short link to be searched.
* @return The active link found for the specified short link.
* @throws NoLinkFoundByShortLinkException If no link was found by the short link.
* @throws NullLinkPropertyException If the found link does not have the ACTIVE status.
*/
public Link findByExistUniqueLink(String shortLink) {
Link existingLink = linkRepository.findByShortLink(shortLink).orElseThrow(NoLinkFoundByShortLinkException::new);
if (existingLink.getStatus() == LinkStatus.ACTIVE) {
return existingLink;
} else {
throw new NullLinkPropertyException();
}
}

/**
* Searches for a unique existing link by a short link.
Expand Down Expand Up @@ -173,3 +158,4 @@ private void throwIfDeleted(Link link) {
}
}
}

0 comments on commit 88731af

Please sign in to comment.