Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

위키 등록 기능을 구현한다. #174

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package maeilwiki.member;

import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRepository extends JpaRepository<Member, Long> {
}
21 changes: 21 additions & 0 deletions maeil-wiki/src/main/java/maeilwiki/wiki/WikiApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package maeilwiki.wiki;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
class WikiApi {

private final WikiService wikiService;

@PostMapping("/wiki")
public ResponseEntity<Void> createWiki(@RequestBody WikiRequest request) {
wikiService.create(request);

return ResponseEntity.noContent().build();
}
}
6 changes: 6 additions & 0 deletions maeil-wiki/src/main/java/maeilwiki/wiki/WikiRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package maeilwiki.wiki;

import org.springframework.data.jpa.repository.JpaRepository;

interface WikiRepository extends JpaRepository<Wiki, Long> {
}
14 changes: 14 additions & 0 deletions maeil-wiki/src/main/java/maeilwiki/wiki/WikiRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package maeilwiki.wiki;

import maeilwiki.member.Member;

record WikiRequest(String question, String questionDetail, String category, boolean isAnonymous) {

public Wiki toWiki(Member member) {
if (questionDetail == null || questionDetail.isBlank()) {
return new Wiki(question, category, isAnonymous, member);
}

return new Wiki(question, questionDetail, category, isAnonymous, member);
}
}
24 changes: 24 additions & 0 deletions maeil-wiki/src/main/java/maeilwiki/wiki/WikiService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package maeilwiki.wiki;

import lombok.RequiredArgsConstructor;
import maeilwiki.member.Member;
import maeilwiki.member.MemberRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
class WikiService {

private final WikiRepository wikiRepository;
private final MemberRepository memberRepository;

@Transactional
public void create(WikiRequest request) {
Member temporalMember = new Member("temp", "1234", "GITHUB");
memberRepository.save(temporalMember);
Wiki wiki = request.toWiki(temporalMember); // TODO : 로그인 구현

wikiRepository.save(wiki);
}
}
Loading