Skip to content

Commit

Permalink
[feat] 태그 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
dongseoki committed Nov 12, 2023
1 parent c06edcb commit 4c4cf60
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.bside.bside_311.controller;

import com.bside.bside_311.dto.SearchTagResponseDto;
import com.bside.bside_311.dto.UserSignupRequestDto;
import com.bside.bside_311.dto.UserSignupResponseDto;
import com.bside.bside_311.entity.User;
import com.bside.bside_311.service.TagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/tag")
@Tag(name = "태그", description = "태그 API")
public class TagController {
private final TagService tagService;

@Operation(summary = "[o]태그 조회", description = "태그 조회 API")
@GetMapping()
@ResponseStatus(HttpStatus.OK)
public SearchTagResponseDto searchTag(
@RequestParam(name="page", defaultValue ="0")
@Schema(description = "검색 키워드 기본값 빈값", example = "")
String searchKeyword)
{
return SearchTagResponseDto.of(tagService.searchTag(searchKeyword));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.bside.bside_311.dto;

import com.bside.bside_311.entity.Tag;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@AllArgsConstructor
public class SearchTagResponseDto {
private List<TagReponseDto> list;
private Long totalCount;

public static SearchTagResponseDto of(List<Tag> tags) {
List<TagReponseDto> list =
tags.stream().map(TagReponseDto::of)
.collect(java.util.stream.Collectors.toList());
return new SearchTagResponseDto(list, (long) list.size());
}

}
23 changes: 23 additions & 0 deletions server/src/main/java/com/bside/bside_311/dto/TagReponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bside.bside_311.dto;

import com.bside.bside_311.entity.Tag;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter

@AllArgsConstructor
public class TagReponseDto {
private String name;
private LocalDateTime createdDate;

public static TagReponseDto of(Tag tag) {
return new TagReponseDto(tag.getName(), tag.getCreatedDate());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface TagRepository extends JpaRepository<Tag, Long> {
List<Tag> findByPostTagsInAndDelYnIs(List<PostTag> postTags, YesOrNo delYn);

List<Tag> findByAlcoholTagsInAndDelYnIs(List<AlcoholTag> alcoholTags, YesOrNo n);

List<Tag> findByNameContainingAndDelYnIs(String searchKeyword, YesOrNo n);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public List<Tag> addOrSetTags(List<String> tagStrList) {

return tags;
}

public List<Tag> searchTag(String searchKeyword) {
return tagRepository.findByNameContainingAndDelYnIs(searchKeyword, YesOrNo.N);
}
}


0 comments on commit 4c4cf60

Please sign in to comment.