Skip to content

Commit 3c27362

Browse files
authored
Merge pull request #103 from HaruHan-Mail/develop
Develop -> Main
2 parents 3e66e11 + 0ff729e commit 3c27362

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/main/java/com/haruhan/common/error/StatusCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public enum StatusCode {
1515
INVALID_VERIFICATION_CODE(400, "인증번호가 일치하지 않습니다.", HttpStatus.BAD_REQUEST),
1616
INTERNAL_SERVER_ERROR(500, "서버 내부 오류입니다.", HttpStatus.INTERNAL_SERVER_ERROR),
1717
NOT_EXIST_ADMIN_CODE(400,"관리자 코드가 존재하지 않습니다.",HttpStatus.BAD_REQUEST),
18+
CREATED(201, "콘텐츠가 성공적으로 생성되었습니다.", HttpStatus.CREATED),
1819
INVALID_ADMIN_CODE(400,"관리자 코드가 일치하지 않습니다.",HttpStatus.BAD_REQUEST);
1920

2021
private final int statusCode;

src/main/java/com/haruhan/content/controller/ContentController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ public ResponseEntity<Message> getContent(@PathVariable Long contentId) {
3535
ContentResDto content = contentService.getContent(contentId);
3636
return ResponseEntity.ok(new Message(StatusCode.OK, content));
3737
}
38+
39+
@PostMapping
40+
public ResponseEntity<Message> createContent(@RequestBody ContentReqDto dto) {
41+
ContentResDto content = contentService.createContent(dto);
42+
return ResponseEntity.ok(new Message(StatusCode.CREATED, content));
43+
}
3844
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.haruhan.content.dto;
2+
3+
import java.util.List;
4+
5+
public record ContentReqDto(
6+
String title,
7+
String summary,
8+
List<String> background,
9+
List<String> importance,
10+
List<String> tip,
11+
List<String> additionalResources
12+
) {}

src/main/java/com/haruhan/content/service/ContentService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public interface ContentService {
1111
List<ContentResDto> getTop5BookmarkedContent();
1212

1313
ContentResDto getContent(Long contentId);
14-
}
14+
15+
ContentResDto createContent(ContentReqDto dto);
16+
}

src/main/java/com/haruhan/content/service/ContentServiceImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.haruhan.common.error.StatusCode;
55
import com.haruhan.common.error.entity.Content;
66
import com.haruhan.common.error.repository.ContentRepository;
7+
import com.haruhan.content.dto.ContentReqDto;
78
import com.haruhan.content.dto.ContentResDto;
89
import com.haruhan.user.entity.User;
910
import com.haruhan.user.repository.UserRepository;
@@ -51,6 +52,21 @@ public List<ContentResDto> getTop5BookmarkedContent() {
5152
.collect(Collectors.toList());
5253
}
5354

55+
@Override
56+
public ContentResDto createContent(ContentReqDto dto) {
57+
Content content = new Content(
58+
dto.title(),
59+
dto.summary(),
60+
String.join("\n", dto.background()),
61+
String.join("\n", dto.importance()),
62+
String.join("\n", dto.tip()),
63+
String.join("\n", dto.additionalResources())
64+
);
65+
66+
Content saved = contentRepository.save(content);
67+
return convertToDto(saved);
68+
}
69+
5470

5571
//문자열을 줄바꿈 기준으로 분리하여 리스트로 변환
5672
private List<String> splitByNewLine(String text) {

0 commit comments

Comments
 (0)