-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PR] Feat : 내커리어 활동 태그 생성/조회/삭제 API 추가
Merge pull request #13 from kkijuk/mvp/career
- Loading branch information
Showing
17 changed files
with
414 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../exception/CareerValidationException.java → .../exception/CareerValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/umc/kkijuk/server/common/domian/exception/InvalidTagNameException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package umc.kkijuk.server.common.domian.exception; | ||
|
||
public class InvalidTagNameException extends RuntimeException{ | ||
public InvalidTagNameException(String message) { | ||
super(message); | ||
|
||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/umc/kkijuk/server/tag/controller/TagController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package umc.kkijuk.server.tag.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
import umc.kkijuk.server.tag.controller.response.TagResponse; | ||
import umc.kkijuk.server.tag.domain.Tag; | ||
import umc.kkijuk.server.tag.dto.TagRequestDto; | ||
import umc.kkijuk.server.tag.dto.TagResponseDto; | ||
import umc.kkijuk.server.tag.dto.converter.TagConverter; | ||
import umc.kkijuk.server.tag.service.TagService; | ||
|
||
@io.swagger.v3.oas.annotations.tags.Tag(name="tag",description = "태그 관련 API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/career") | ||
public class TagController { | ||
|
||
private final TagService tagService; | ||
|
||
@PostMapping("/tag") | ||
@Operation(summary = "태그 추가 API", description = "태그 - 태그를 생성하는 API") | ||
public TagResponse<TagResponseDto.ResultTagDto> create(@RequestBody @Valid TagRequestDto.CreateTagDto request) { | ||
Tag createTag = tagService.createTag(request); | ||
return TagResponse.success(HttpStatus.OK,"태그를 성공적으로 생성했습니다.", TagConverter.toTagResult(createTag)); | ||
} | ||
@GetMapping("/tag") | ||
@Operation(summary = "태그 조회 API", description = "태그 - 태그 조회하는 API") | ||
public TagResponse<TagResponseDto.ResultTagDtoList> read() { | ||
return TagResponse.success(HttpStatus.OK, "모든 태그를 성공적으로 조회했습니다.", tagService.findAllTags()); | ||
} | ||
@DeleteMapping("/tag/{tagId}") | ||
@Operation(summary = "태그 삭제 API",description = "태그 - 태그를 삭제하는 API") | ||
@Parameter(name = "tagId",description = "태그 Id, path variable 입니다. 존재하는 태그 Id 값을 넘겨 주세요.",example = "1") | ||
public TagResponse<Object> delete(@PathVariable Long tagId) { | ||
tagService.delete(tagId); | ||
return TagResponse.success(HttpStatus.OK, "태그 삭제가 성공적으로 이루어졌습니다.", null); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/umc/kkijuk/server/tag/controller/response/TagResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package umc.kkijuk.server.tag.controller.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Builder | ||
@Getter | ||
public class TagResponse<T> { | ||
private int status; | ||
private String message; | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private T data; | ||
|
||
public TagResponse(final int status,final String message,T data){ | ||
this.status = status; | ||
this.message = message; | ||
this.data = data; | ||
} | ||
public static <T> TagResponse<T> success(HttpStatus status, String message, T data){ | ||
return new TagResponse<>(status.value(),message,data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package umc.kkijuk.server.tag.domain; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Tag { | ||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name="tag_id") | ||
private Long id; | ||
@NotNull | ||
@Column(name="tag_name", length = 30) | ||
private String name; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/umc/kkijuk/server/tag/dto/TagRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package umc.kkijuk.server.tag.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
|
||
public class TagRequestDto { | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class CreateTagDto{ | ||
@Size(max = 30) | ||
@Schema(description = "태그 이름", example = "역량 키워드", type="string") | ||
String tagName; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/umc/kkijuk/server/tag/dto/TagResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package umc.kkijuk.server.tag.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
public class TagResponseDto { | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class ResultTagDto{ | ||
@Schema(description = "생성된 활동 태그 Id", example = "1", type = "Long") | ||
private Long id; | ||
@Schema(description = "생성된 활동 태그 이름", example = "핵심 역량", type = "String") | ||
private String tagName; | ||
} | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class ResultTagDtoList{ | ||
@Schema(description = "활동 태그들의 개수",example = "3") | ||
private int count; | ||
@Schema(description = "활동 태그들 리스트") | ||
private List<ResultTagDto> tagList; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/umc/kkijuk/server/tag/dto/converter/TagConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package umc.kkijuk.server.tag.dto.converter; | ||
|
||
import umc.kkijuk.server.tag.domain.Tag; | ||
import umc.kkijuk.server.tag.dto.TagRequestDto; | ||
import umc.kkijuk.server.tag.dto.TagResponseDto; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class TagConverter { | ||
public static Tag toTag(TagRequestDto.CreateTagDto request) { | ||
return Tag.builder() | ||
.name(request.getTagName()) | ||
.build(); | ||
} | ||
public static TagResponseDto.ResultTagDto toTagResult(Tag hashTag) { | ||
return TagResponseDto.ResultTagDto.builder() | ||
.id(hashTag.getId()) | ||
.tagName(hashTag.getName()) | ||
.build(); | ||
} | ||
|
||
public static TagResponseDto.ResultTagDtoList toResultTagDtoList(List<Tag> tagList) { | ||
return TagResponseDto.ResultTagDtoList.builder() | ||
.count(tagList.size()) | ||
.tagList(tagList.stream().map( | ||
value -> TagResponseDto.ResultTagDto.builder() | ||
.tagName(value.getName()) | ||
.id(value.getId()) | ||
.build() | ||
).collect(Collectors.toList())) | ||
.build(); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/umc/kkijuk/server/tag/repository/TagRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package umc.kkijuk.server.tag.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import umc.kkijuk.server.tag.domain.Tag; | ||
|
||
import java.util.List; | ||
|
||
public interface TagRepository extends JpaRepository<Tag,Long> { | ||
boolean existsByName(String name); | ||
List<Tag> findAll(); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/umc/kkijuk/server/tag/service/TagService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package umc.kkijuk.server.tag.service; | ||
|
||
import umc.kkijuk.server.tag.domain.Tag; | ||
import umc.kkijuk.server.tag.dto.TagRequestDto; | ||
import umc.kkijuk.server.tag.dto.TagResponseDto; | ||
|
||
|
||
public interface TagService { | ||
Tag createTag(TagRequestDto.CreateTagDto request); | ||
TagResponseDto.ResultTagDtoList findAllTags(); | ||
void delete(Long tagId); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/umc/kkijuk/server/tag/service/TagServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package umc.kkijuk.server.tag.service; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import umc.kkijuk.server.common.domian.exception.InvalidTagNameException; | ||
import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException; | ||
import umc.kkijuk.server.common.domian.response.ErrorResponse; | ||
import umc.kkijuk.server.tag.domain.Tag; | ||
import umc.kkijuk.server.tag.dto.TagRequestDto; | ||
import umc.kkijuk.server.tag.dto.TagResponseDto; | ||
import umc.kkijuk.server.tag.dto.converter.TagConverter; | ||
import umc.kkijuk.server.tag.repository.TagRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class TagServiceImpl implements TagService { | ||
private final TagRepository tagRepository; | ||
@Override | ||
@Transactional | ||
public Tag createTag(TagRequestDto.CreateTagDto request) { | ||
String tagName = request.getTagName(); | ||
if (tagName==null || tagName.trim().isEmpty() || tagRepository.existsByName(tagName)) { | ||
throw new InvalidTagNameException("태그 이름은 비워둘 수 없으며, 이미 존재하는 이름은 사용할 수 없습니다."); | ||
} | ||
Tag hashTag = TagConverter.toTag(request); | ||
return tagRepository.save(hashTag); | ||
} | ||
@Override | ||
public TagResponseDto.ResultTagDtoList findAllTags() { | ||
return TagConverter.toResultTagDtoList(tagRepository.findAll()); | ||
} | ||
@Override | ||
@Transactional | ||
public void delete(Long tagId) { | ||
Tag deleteTag = tagRepository.findById(tagId).orElseThrow(() -> new ResourceNotFoundException("Tag", tagId)); | ||
tagRepository.delete(deleteTag); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.