Skip to content

Commit

Permalink
Merge pull request #98 from Team-Shaka/feature/97
Browse files Browse the repository at this point in the history
✨ Feat: 트리하우스 이름 중복확인 API
  • Loading branch information
koojun99 authored Aug 7, 2024
2 parents 51ec4a5 + 4d907f3 commit 1a9d276
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ public static TreehouseResponseDTO.getTreehouses toGetTreehouses(List<TreehouseR
.treehouses(treehouseDtos)
.build();
}

public static TreehouseResponseDTO.checkTreehouseName toCheckTreehouseName(boolean isAvailable) {
return TreehouseResponseDTO.checkTreehouseName.builder()
.isAvailable(isAvailable)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public TreehouseResponseDTO.getTreehouses getTreehouses(User user) {
return TreehouseMapper.toGetTreehouses(treehouseDtos);
}

public TreehouseResponseDTO.checkTreehouseName checkTreehouseName(TreehouseRequestDTO.checkTreehouseName request) {
boolean isAvailable = treehouseQueryAdapter.isTreehouseNameAvailable(request.getTreehouseName());
return TreehouseMapper.toCheckTreehouseName(isAvailable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public class TreehouseQueryAdapter {
public TreeHouse getTreehouseById(Long treehouseId){
return treehouseRepository.findById(treehouseId).orElseThrow(()->new TreehouseException(GlobalErrorCode.TREEHOUSE_NOT_FOUND));
}

public boolean isTreehouseNameAvailable(String name) {
return !treehouseRepository.existsByName(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
import treehouse.server.global.entity.treeHouse.TreeHouse;

public interface TreehouseRepository extends JpaRepository<TreeHouse, Long> {
boolean existsByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ public CommonResponse<TreehouseResponseDTO.getTreehouses> getTreehouses(
) {
return CommonResponse.onSuccess(treehouseService.getTreehouses(user));
}

@GetMapping("/checkName")
@Operation(summary = "트리하우스 이름 중복 확인 🔑", description = "트리하우스 이름 중복을 확인합니다.")
public CommonResponse<TreehouseResponseDTO.checkTreehouseName> checkTreehouseName(
@RequestBody TreehouseRequestDTO.checkTreehouseName request
) {
return CommonResponse.onSuccess(treehouseService.checkTreehouseName(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ public static class createTreehouse{
@NotBlank(message = "트리 홀 이름이 필요합니다.")
private String treeholeName;
}

@Getter
public static class checkTreehouseName{

@JsonProperty("treehouseName")
@Schema(description = "트리하우스 이름", example = "Team Shaka")
@NotBlank(message = "트리하우스 이름이 필요합니다.")
@Size(min = 2, max = 20, message = "트리하우스 이름은 최소 2자, 최대 20자여야 합니다.")
private String treehouseName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ public static class getTreehouseDetails {
public static class getTreehouses {
List<getTreehouseDetails> treehouses;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class checkTreehouseName {
private Boolean isAvailable;
}
}

0 comments on commit 1a9d276

Please sign in to comment.