From c15de8d1b02d9f15d3bba2ad95ee1305ce7347bd Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 18 Mar 2024 16:07:18 +0300 Subject: [PATCH] update isDomainNameReserved endpoint, add new dto --- .../minanames/controller/DomainController.java | 12 ++++++++++-- .../staketab/minanames/dto/ReservedDomainDTO.java | 15 +++++++++++++++ .../service/abstraction/DomainService.java | 3 ++- .../minanames/service/impl/DomainServiceImpl.java | 13 +++++++++++-- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/staketab/minanames/dto/ReservedDomainDTO.java diff --git a/src/main/java/com/staketab/minanames/controller/DomainController.java b/src/main/java/com/staketab/minanames/controller/DomainController.java index eb9e5a8..25a6407 100644 --- a/src/main/java/com/staketab/minanames/controller/DomainController.java +++ b/src/main/java/com/staketab/minanames/controller/DomainController.java @@ -2,6 +2,7 @@ import com.staketab.minanames.dto.DomainReservationDTO; import com.staketab.minanames.dto.DomainUpdateDTO; +import com.staketab.minanames.dto.ReservedDomainDTO; import com.staketab.minanames.dto.request.BaseRequest; import com.staketab.minanames.dto.request.SearchParams; import com.staketab.minanames.dto.request.sort.DomainsSortColumn; @@ -16,7 +17,14 @@ import org.springdoc.core.annotations.ParameterObject; import org.springframework.data.domain.Page; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +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.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.NoSuchElementException; @@ -84,7 +92,7 @@ public ResponseEntity update(@RequestBody DomainUpdateDTO domainUp } @GetMapping("/{domainName}/reserved") - public ResponseEntity isDomainNameReserved(@PathVariable String domainName) { + public ResponseEntity isDomainNameReserved(@PathVariable String domainName) { return ok(domainService.isNameReserved(domainName)); } diff --git a/src/main/java/com/staketab/minanames/dto/ReservedDomainDTO.java b/src/main/java/com/staketab/minanames/dto/ReservedDomainDTO.java new file mode 100644 index 0000000..c27af76 --- /dev/null +++ b/src/main/java/com/staketab/minanames/dto/ReservedDomainDTO.java @@ -0,0 +1,15 @@ +package com.staketab.minanames.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ReservedDomainDTO { + + private String id; +} diff --git a/src/main/java/com/staketab/minanames/service/abstraction/DomainService.java b/src/main/java/com/staketab/minanames/service/abstraction/DomainService.java index 927e977..6570909 100644 --- a/src/main/java/com/staketab/minanames/service/abstraction/DomainService.java +++ b/src/main/java/com/staketab/minanames/service/abstraction/DomainService.java @@ -2,6 +2,7 @@ import com.staketab.minanames.dto.DomainReservationDTO; import com.staketab.minanames.dto.DomainUpdateDTO; +import com.staketab.minanames.dto.ReservedDomainDTO; import com.staketab.minanames.dto.request.BaseRequest; import com.staketab.minanames.dto.request.SearchParams; import com.staketab.minanames.entity.DomainEntity; @@ -15,7 +16,7 @@ public interface DomainService { DomainEntity create(DomainReservationDTO domainRequest); Optional retrieve(String id); DomainEntity update(DomainUpdateDTO domainUpdateDTO); - String isNameReserved(String name); + ReservedDomainDTO isNameReserved(String name); Boolean setDefaultDomain(String id); void removeReservedDomains(); } diff --git a/src/main/java/com/staketab/minanames/service/impl/DomainServiceImpl.java b/src/main/java/com/staketab/minanames/service/impl/DomainServiceImpl.java index 2e96fca..d5a8c3e 100644 --- a/src/main/java/com/staketab/minanames/service/impl/DomainServiceImpl.java +++ b/src/main/java/com/staketab/minanames/service/impl/DomainServiceImpl.java @@ -2,6 +2,7 @@ import com.staketab.minanames.dto.DomainReservationDTO; import com.staketab.minanames.dto.DomainUpdateDTO; +import com.staketab.minanames.dto.ReservedDomainDTO; import com.staketab.minanames.dto.request.BaseRequest; import com.staketab.minanames.dto.request.SearchParams; import com.staketab.minanames.entity.DomainEntity; @@ -64,8 +65,10 @@ public DomainEntity update(DomainUpdateDTO domainUpdateDTO) { } @Override - public String isNameReserved(String name) { - return domainRepository.findDomainEntityByDomainName(name).map(DomainEntity::getId).orElse(null); + public ReservedDomainDTO isNameReserved(String name) { + return domainRepository.findDomainEntityByDomainName(name) + .map(this::mapToReservedDomainDTO) + .orElseGet(ReservedDomainDTO::new); } @Override @@ -80,4 +83,10 @@ public void removeReservedDomains() { long currentTimestamp = Timestamp.valueOf(localDateTime).getTime(); domainRepository.deleteAllByReservationTimestampLessThan(currentTimestamp); } + + private ReservedDomainDTO mapToReservedDomainDTO(DomainEntity domainEntity) { + return ReservedDomainDTO.builder() + .id(domainEntity.getId()) + .build(); + } }