From 8f1510ea3e7e62bf5b277fd2335f9c20327069c0 Mon Sep 17 00:00:00 2001 From: lej8924 Date: Wed, 17 Jul 2024 12:36:23 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feat:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80-=ED=8B=B0=ED=81=B4=EB=85=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ticle/server/ServerApplication.java | 3 +- .../com/ticle/server/memo/domain/Memo.java | 3 ++ .../mypage/controller/NoteController.java | 32 ++++++++--- .../mypage/controller/QuestionController.java | 21 ++++---- .../controller/SavedTicleController.java | 12 ++--- .../dto/request/CommentUpdateRequest.java | 16 ++++++ .../NoteUpdateRequest.java} | 8 +-- .../NoteResponse.java} | 10 ++-- .../QuestionResponse.java} | 8 +-- .../SavedTicleResponse.java} | 8 +-- .../server/mypage/service/MyPageService.java | 53 +++++++++++++++---- .../post/controller/PostApiController.java | 5 +- .../server/post/service/PostService.java | 11 ++-- .../com/ticle/server/user/domain/User.java | 2 +- src/main/resources/data.sql | 6 ++- 15 files changed, 134 insertions(+), 64 deletions(-) create mode 100644 src/main/java/com/ticle/server/mypage/dto/request/CommentUpdateRequest.java rename src/main/java/com/ticle/server/mypage/dto/{UpdateCommentDto.java => request/NoteUpdateRequest.java} (60%) rename src/main/java/com/ticle/server/mypage/dto/{MyNoteDto.java => response/NoteResponse.java} (74%) rename src/main/java/com/ticle/server/mypage/dto/{MyQuestionDto.java => response/QuestionResponse.java} (74%) rename src/main/java/com/ticle/server/mypage/dto/{SavedTicleDto.java => response/SavedTicleResponse.java} (81%) diff --git a/src/main/java/com/ticle/server/ServerApplication.java b/src/main/java/com/ticle/server/ServerApplication.java index c43a3b5..ad87600 100644 --- a/src/main/java/com/ticle/server/ServerApplication.java +++ b/src/main/java/com/ticle/server/ServerApplication.java @@ -2,9 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.context.annotation.PropertySource; -@SpringBootApplication +@SpringBootApplication(exclude = SecurityAutoConfiguration.class) public class ServerApplication { public static void main(String[] args) { diff --git a/src/main/java/com/ticle/server/memo/domain/Memo.java b/src/main/java/com/ticle/server/memo/domain/Memo.java index b79f142..8b934fb 100644 --- a/src/main/java/com/ticle/server/memo/domain/Memo.java +++ b/src/main/java/com/ticle/server/memo/domain/Memo.java @@ -38,4 +38,7 @@ public class Memo extends BaseTimeEntity { @JoinColumn(name = "post_id") private Post post; + public void updateNote(String content){ + this.content = content; + } } diff --git a/src/main/java/com/ticle/server/mypage/controller/NoteController.java b/src/main/java/com/ticle/server/mypage/controller/NoteController.java index db6ce9c..961cd06 100644 --- a/src/main/java/com/ticle/server/mypage/controller/NoteController.java +++ b/src/main/java/com/ticle/server/mypage/controller/NoteController.java @@ -1,7 +1,8 @@ package com.ticle.server.mypage.controller; import com.ticle.server.global.dto.ResponseTemplate; -import com.ticle.server.mypage.dto.MyNoteDto; +import com.ticle.server.mypage.dto.response.NoteResponse; +import com.ticle.server.mypage.dto.request.NoteUpdateRequest; import com.ticle.server.mypage.service.MyPageService; import com.ticle.server.user.service.CustomUserDetails; import io.swagger.v3.oas.annotations.Operation; @@ -10,10 +11,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -25,13 +23,31 @@ public class NoteController { private final MyPageService myPageService; - @Operation(summary="티클노트",description = "userId에 해당하는 note들을 불러옴") + @Operation(summary="티클노트 조회",description = "userId에 해당하는 note들을 불러옴") @GetMapping("/my-note") public ResponseEntity> getMyNotes(@AuthenticationPrincipal CustomUserDetails customUserDetails){ Long userId = customUserDetails.getUserId(); - List myNoteDtos = myPageService.getMyNotes(userId); + List noteResponses = myPageService.getMyNotes(userId); return ResponseEntity .status(HttpStatus.OK) - .body(ResponseTemplate.from(myNoteDtos)); + .body(ResponseTemplate.from(noteResponses)); + } + + @Operation(summary="티클노트 수정",description = "noteId에 해당하는 note들을 수정함") + @PutMapping("/my-note/{id}") + public ResponseEntity> updateMyNotes(@AuthenticationPrincipal CustomUserDetails customUserDetails,@PathVariable("id") Long id, @RequestBody NoteUpdateRequest noteUpdateRequest){ + myPageService.updateNote(customUserDetails,id,noteUpdateRequest); + return ResponseEntity + .status(HttpStatus.OK) + .body(ResponseTemplate.from(id + "번 노트가 수정되었습니다.")); + } + + @Operation(summary="티클노트 삭제",description = "noteId에 해당하는 note들을 삭제함") + @DeleteMapping("/my-note/{id}") + public ResponseEntity> deleteMyNotes(@AuthenticationPrincipal CustomUserDetails customUserDetails, @PathVariable("id") Long id){ + myPageService.deleteNote(customUserDetails,id); + return ResponseEntity + .status(HttpStatus.OK) + .body(ResponseTemplate.from(id + "번 노트가 삭제되었습니다.")); } } diff --git a/src/main/java/com/ticle/server/mypage/controller/QuestionController.java b/src/main/java/com/ticle/server/mypage/controller/QuestionController.java index ba818ed..f29fe89 100644 --- a/src/main/java/com/ticle/server/mypage/controller/QuestionController.java +++ b/src/main/java/com/ticle/server/mypage/controller/QuestionController.java @@ -1,8 +1,8 @@ package com.ticle.server.mypage.controller; import com.ticle.server.global.dto.ResponseTemplate; -import com.ticle.server.mypage.dto.MyQuestionDto; -import com.ticle.server.mypage.dto.UpdateCommentDto; +import com.ticle.server.mypage.dto.response.QuestionResponse; +import com.ticle.server.mypage.dto.request.CommentUpdateRequest; import com.ticle.server.mypage.service.MyPageService; import com.ticle.server.user.jwt.JwtTokenProvider; import com.ticle.server.user.service.CustomUserDetails; @@ -32,26 +32,21 @@ public class QuestionController { @GetMapping("/my-question") public ResponseEntity> getMyQuestions(@AuthenticationPrincipal CustomUserDetails customUserDetails){ -// Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); -// if (authentication == null || !authentication.isAuthenticated()) { -// return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ResponseTemplate.EMPTY_RESPONSE); -// } - Long userId = customUserDetails.getUserId(); - List myQuestionDtos; - myQuestionDtos = myPageService.getMyQuestions(userId); + List questionResponses; + questionResponses = myPageService.getMyQuestions(userId); return ResponseEntity .status(HttpStatus.OK) - .body(ResponseTemplate.from(myQuestionDtos)); + .body(ResponseTemplate.from(questionResponses)); } @Operation(summary = "마이물어봥 수정",description = "question_id에서 수정하기") @PutMapping("/my-question/{id}") - public ResponseEntity> updateQuestion(@AuthenticationPrincipal CustomUserDetails customUserDetails,@PathVariable("id") Long questionId, @RequestBody UpdateCommentDto updateCommentDto) { + public ResponseEntity> updateQuestion(@AuthenticationPrincipal CustomUserDetails customUserDetails,@PathVariable("id") Long questionId, @RequestBody CommentUpdateRequest commentUpdateRequest) { Long userId = customUserDetails.getUserId(); - myPageService.updateComment(userId, questionId, updateCommentDto.getContent()); + myPageService.updateComment(userId, questionId, commentUpdateRequest.getContent()); return ResponseEntity .status(HttpStatus.OK) @@ -59,4 +54,6 @@ public ResponseEntity> updateQuestion(@AuthenticationPr } + + } diff --git a/src/main/java/com/ticle/server/mypage/controller/SavedTicleController.java b/src/main/java/com/ticle/server/mypage/controller/SavedTicleController.java index 1a8c938..d3aa7e5 100644 --- a/src/main/java/com/ticle/server/mypage/controller/SavedTicleController.java +++ b/src/main/java/com/ticle/server/mypage/controller/SavedTicleController.java @@ -1,15 +1,13 @@ package com.ticle.server.mypage.controller; import com.ticle.server.global.dto.ResponseTemplate; -import com.ticle.server.mypage.dto.SavedTicleDto; +import com.ticle.server.mypage.dto.response.SavedTicleResponse; import com.ticle.server.mypage.service.MyPageService; import com.ticle.server.user.domain.type.Category; import com.ticle.server.user.service.CustomUserDetails; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cloud.client.loadbalancer.Response; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; @@ -35,16 +33,16 @@ public class SavedTicleController { @GetMapping("/saved-ticles") public ResponseEntity> getSavedTicles(@AuthenticationPrincipal CustomUserDetails customUserDetails, @RequestParam(value = "category",required = false) Category category, @PageableDefault(page=0,size=9,sort="id",direction = Sort.Direction.DESC)Pageable pageable){ Long userId = customUserDetails.getUserId(); - List savedTicleDtos; + List savedTicleResponses; if(category != null){ - savedTicleDtos = myPageService.getSavedArticlesByCategory(userId,category,pageable); + savedTicleResponses = myPageService.getSavedArticlesByCategory(userId,category,pageable); }else{ - savedTicleDtos = myPageService.getSavedArticles(userId,pageable); + savedTicleResponses = myPageService.getSavedArticles(userId,pageable); } return ResponseEntity .status(HttpStatus.OK) - .body(ResponseTemplate.from(savedTicleDtos)); + .body(ResponseTemplate.from(savedTicleResponses)); } diff --git a/src/main/java/com/ticle/server/mypage/dto/request/CommentUpdateRequest.java b/src/main/java/com/ticle/server/mypage/dto/request/CommentUpdateRequest.java new file mode 100644 index 0000000..5900a1e --- /dev/null +++ b/src/main/java/com/ticle/server/mypage/dto/request/CommentUpdateRequest.java @@ -0,0 +1,16 @@ +package com.ticle.server.mypage.dto.request; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class CommentUpdateRequest { + private String content; + + @Builder + public CommentUpdateRequest(String content){ + this.content = content; + } +} diff --git a/src/main/java/com/ticle/server/mypage/dto/UpdateCommentDto.java b/src/main/java/com/ticle/server/mypage/dto/request/NoteUpdateRequest.java similarity index 60% rename from src/main/java/com/ticle/server/mypage/dto/UpdateCommentDto.java rename to src/main/java/com/ticle/server/mypage/dto/request/NoteUpdateRequest.java index 842b949..c411db8 100644 --- a/src/main/java/com/ticle/server/mypage/dto/UpdateCommentDto.java +++ b/src/main/java/com/ticle/server/mypage/dto/request/NoteUpdateRequest.java @@ -1,4 +1,4 @@ -package com.ticle.server.mypage.dto; +package com.ticle.server.mypage.dto.request; import lombok.Builder; import lombok.Getter; @@ -6,11 +6,13 @@ @Getter @NoArgsConstructor -public class UpdateCommentDto { +public class NoteUpdateRequest { + private String content; @Builder - public UpdateCommentDto(String content){ + public NoteUpdateRequest(String content){ this.content = content; } + } diff --git a/src/main/java/com/ticle/server/mypage/dto/MyNoteDto.java b/src/main/java/com/ticle/server/mypage/dto/response/NoteResponse.java similarity index 74% rename from src/main/java/com/ticle/server/mypage/dto/MyNoteDto.java rename to src/main/java/com/ticle/server/mypage/dto/response/NoteResponse.java index e5b1801..a10fa47 100644 --- a/src/main/java/com/ticle/server/mypage/dto/MyNoteDto.java +++ b/src/main/java/com/ticle/server/mypage/dto/response/NoteResponse.java @@ -1,10 +1,8 @@ -package com.ticle.server.mypage.dto; +package com.ticle.server.mypage.dto.response; import com.ticle.server.memo.domain.Memo; -import com.ticle.server.opinion.domain.Opinion; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; import lombok.Getter; import java.time.LocalDateTime; @@ -12,15 +10,15 @@ @Getter @AllArgsConstructor @Builder -public class MyNoteDto { +public class NoteResponse { private Long noteId; private String content; private LocalDateTime memoDate; private Long postId; private String postTitle; - public static MyNoteDto toDto(Memo memo){ - return MyNoteDto.builder() + public static NoteResponse toDto(Memo memo){ + return NoteResponse.builder() .noteId(memo.getMemoId()) .content(memo.getContent()) .memoDate(memo.getCreatedDate()) diff --git a/src/main/java/com/ticle/server/mypage/dto/MyQuestionDto.java b/src/main/java/com/ticle/server/mypage/dto/response/QuestionResponse.java similarity index 74% rename from src/main/java/com/ticle/server/mypage/dto/MyQuestionDto.java rename to src/main/java/com/ticle/server/mypage/dto/response/QuestionResponse.java index 6a662ed..b6ed82c 100644 --- a/src/main/java/com/ticle/server/mypage/dto/MyQuestionDto.java +++ b/src/main/java/com/ticle/server/mypage/dto/response/QuestionResponse.java @@ -1,4 +1,4 @@ -package com.ticle.server.mypage.dto; +package com.ticle.server.mypage.dto.response; import com.ticle.server.opinion.domain.Opinion; import lombok.AllArgsConstructor; @@ -8,14 +8,14 @@ @Getter @AllArgsConstructor @Builder -public class MyQuestionDto { +public class QuestionResponse { private Long questionId; private String question; private Long viewCount; private Long commentCount; - public static MyQuestionDto toDto(Opinion opinion){ - return MyQuestionDto.builder() + public static QuestionResponse toDto(Opinion opinion){ + return QuestionResponse.builder() .questionId(opinion.getOpinionId()) .question(opinion.getQuestion()) .viewCount(opinion.getViewCount()) diff --git a/src/main/java/com/ticle/server/mypage/dto/SavedTicleDto.java b/src/main/java/com/ticle/server/mypage/dto/response/SavedTicleResponse.java similarity index 81% rename from src/main/java/com/ticle/server/mypage/dto/SavedTicleDto.java rename to src/main/java/com/ticle/server/mypage/dto/response/SavedTicleResponse.java index 5db97c9..3b0de76 100644 --- a/src/main/java/com/ticle/server/mypage/dto/SavedTicleDto.java +++ b/src/main/java/com/ticle/server/mypage/dto/response/SavedTicleResponse.java @@ -1,4 +1,4 @@ -package com.ticle.server.mypage.dto; +package com.ticle.server.mypage.dto.response; import com.ticle.server.global.domain.S3Info; import com.ticle.server.post.domain.Post; @@ -10,7 +10,7 @@ @Getter @AllArgsConstructor @Builder -public class SavedTicleDto { +public class SavedTicleResponse { private Long postId; private String title; private String content; @@ -19,8 +19,8 @@ public class SavedTicleDto { private Category postCategory; private S3Info image; - public static SavedTicleDto toDto(Post post) { - return SavedTicleDto.builder() + public static SavedTicleResponse toDto(Post post) { + return SavedTicleResponse.builder() .postId(post.getPostId()) .title(post.getTitle()) .content(post.getContent()) diff --git a/src/main/java/com/ticle/server/mypage/service/MyPageService.java b/src/main/java/com/ticle/server/mypage/service/MyPageService.java index 7eb15a2..2ce5db8 100644 --- a/src/main/java/com/ticle/server/mypage/service/MyPageService.java +++ b/src/main/java/com/ticle/server/mypage/service/MyPageService.java @@ -1,9 +1,10 @@ package com.ticle.server.mypage.service; import com.ticle.server.memo.domain.Memo; -import com.ticle.server.mypage.dto.MyNoteDto; -import com.ticle.server.mypage.dto.MyQuestionDto; -import com.ticle.server.mypage.dto.SavedTicleDto; +import com.ticle.server.mypage.dto.request.NoteUpdateRequest; +import com.ticle.server.mypage.dto.response.NoteResponse; +import com.ticle.server.mypage.dto.response.QuestionResponse; +import com.ticle.server.mypage.dto.response.SavedTicleResponse; import com.ticle.server.mypage.repository.NoteRepository; import com.ticle.server.opinion.domain.Comment; import com.ticle.server.opinion.repository.CommentRepository; @@ -15,6 +16,7 @@ import com.ticle.server.user.domain.User; import com.ticle.server.user.domain.type.Category; import com.ticle.server.user.repository.UserRepository; +import com.ticle.server.user.service.CustomUserDetails; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -38,33 +40,35 @@ public class MyPageService { private final CommentRepository commentRepository; private final int SIZE = 9; - public List getSavedArticles(Long userId,Pageable pageable) { + public List getSavedArticles(Long userId, Pageable pageable) { // Pageable pageable = PageRequest.of(page-1,SIZE); Page scraps = scrappedRepository.findByUserId(userId,pageable); return scraps.stream() .map(scrap -> postRepository.findById(scrap.getPost().getPostId()).orElse(null)) .filter(post -> post != null) - .map(SavedTicleDto::toDto) + .map(SavedTicleResponse::toDto) .collect(Collectors.toList()); } - public List getSavedArticlesByCategory(Long userId, Category category,Pageable pageable) { + public List getSavedArticlesByCategory(Long userId, Category category, Pageable pageable) { // Pageable pageable = PageRequest.of(page-1,SIZE); Page scraps = scrappedRepository.findByUserIdAndPostCategory(userId, category,pageable); return scraps.stream() .map(scrap -> postRepository.findById(scrap.getPost().getPostId()).orElse(null)) .filter(post -> post != null) - .map(SavedTicleDto::toDto) + .map(SavedTicleResponse::toDto) .collect(Collectors.toList()); } - public List getMyQuestions(Long userId) { + //////////////////////////////////////////////티클문답/////////////////////////////////////////////////////////////// + + public List getMyQuestions(Long userId) { List questions = opinionRepository.findByUserId(userId); return questions.stream() - .map(MyQuestionDto::toDto) + .map(QuestionResponse::toDto) .collect(toList()); } @@ -79,11 +83,38 @@ public void updateComment(Long userId, Long opinionId, String newContent) { } - public List getMyNotes(Long userId) { + //////////////////////////////////////////////티클노트/////////////////////////////////////////////////////////////// + + public List getMyNotes(Long userId) { List memos = noteRepository.findByUserId(userId); return memos.stream() - .map(MyNoteDto::toDto) + .map(NoteResponse::toDto) .collect(toList()); } + @Transactional + public void updateNote(CustomUserDetails customUserDetails, Long noteId, NoteUpdateRequest noteUpdateRequest){ + Memo memo = noteRepository.findById(noteId) + .orElseThrow(() -> new RuntimeException("Memo not found")); + + if (!memo.getUser().getId().equals(customUserDetails.getUserId())) { + throw new RuntimeException("You do not have permission to edit this memo"); + } + + memo.updateNote(noteUpdateRequest.getContent()); + noteRepository.save(memo); + } + + @Transactional + public void deleteNote(CustomUserDetails customUserDetails, Long noteId) { + Memo memo = noteRepository.findById(noteId) + .orElseThrow(() -> new RuntimeException("Memo not found")); + + if (!memo.getUser().getId().equals(customUserDetails.getUserId())) { + throw new RuntimeException("You do not have permission to delete this memo"); + } + + noteRepository.delete(memo); + } + } diff --git a/src/main/java/com/ticle/server/post/controller/PostApiController.java b/src/main/java/com/ticle/server/post/controller/PostApiController.java index 0259a3a..ff9758a 100644 --- a/src/main/java/com/ticle/server/post/controller/PostApiController.java +++ b/src/main/java/com/ticle/server/post/controller/PostApiController.java @@ -10,6 +10,7 @@ import com.ticle.server.post.service.PostService; import com.ticle.server.scrapped.domain.Scrapped; import com.ticle.server.scrapped.dto.ScrappedDto; +import com.ticle.server.user.service.CustomUserDetails; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -78,9 +79,9 @@ public ResponseEntity> scrappedArticle(@PathVariable lo // post memo @Operation(summary = "메모", description = "메모 작성하기") @PostMapping("/memo/{id}") - public ResponseEntity> memoArticle(@PathVariable long id, @RequestBody MemoRequest memoRequest, @AuthenticationPrincipal UserDetails userDetails) { + public ResponseEntity> memoArticle(@PathVariable("id") Long id, @RequestBody MemoRequest memoRequest, @AuthenticationPrincipal CustomUserDetails customUserDetails) { { - Object memo = postService.writeMemo(id, userDetails, memoRequest.getTargetText(), memoRequest.getContent()); + Object memo = postService.writeMemo(id, customUserDetails, memoRequest.getTargetText(), memoRequest.getContent()); return ResponseEntity .status(HttpStatus.OK) diff --git a/src/main/java/com/ticle/server/post/service/PostService.java b/src/main/java/com/ticle/server/post/service/PostService.java index 1a50419..9844693 100644 --- a/src/main/java/com/ticle/server/post/service/PostService.java +++ b/src/main/java/com/ticle/server/post/service/PostService.java @@ -10,6 +10,8 @@ import com.ticle.server.scrapped.domain.Scrapped; import com.ticle.server.scrapped.repository.ScrappedRepository; import com.ticle.server.user.domain.User; +import com.ticle.server.user.repository.UserRepository; +import com.ticle.server.user.service.CustomUserDetails; import com.ticle.server.user.service.UserService; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; @@ -38,6 +40,7 @@ public class PostService { private final ScrappedRepository scrappedRepository; private final UserService userService; private final NoteRepository noteRepository; + private final UserRepository userRepository; // 카테고리에 맞는 글 찾기 public Page findAllByCategory(String category, int page) { @@ -127,13 +130,13 @@ public Object scrappedById(long id, UserDetails userDetails) { return scrappedRepository.save(scrapped); } - public Object writeMemo(long id, UserDetails userDetails, String targetText, String content) { + public Object writeMemo(long id, CustomUserDetails customUserDetails, String targetText, String content) { // getUsername에는 email이 들어있음. / email로 유저 찾고 id 찾도록 함. - User user = userService.getLoginUserByEmail(userDetails.getUsername()); + Optional user = userRepository.findById(customUserDetails.getUserId()); // 같은 내용의 targetText-content 세트가 있는지 확인 - Memo existingMemo = noteRepository.findByUserAndTargetTextAndContent(user, targetText, content); + Memo existingMemo = noteRepository.findByUserAndTargetTextAndContent(user.get(), targetText, content); if (existingMemo != null) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "이미 동일한 메모가 존재합니다."); @@ -141,7 +144,7 @@ public Object writeMemo(long id, UserDetails userDetails, String targetText, Str Memo memo = new Memo(); memo.setPost(postRepository.findByPostId(id)); - memo.setUser(user); + memo.setUser(user.get()); memo.setTargetText(targetText); memo.setContent(content); diff --git a/src/main/java/com/ticle/server/user/domain/User.java b/src/main/java/com/ticle/server/user/domain/User.java index 280b465..c5f3bda 100644 --- a/src/main/java/com/ticle/server/user/domain/User.java +++ b/src/main/java/com/ticle/server/user/domain/User.java @@ -16,7 +16,7 @@ import java.util.List; import java.util.stream.Collectors; -@Table(name = "users") +@Table(name = "user") @Entity @Getter @Builder diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index ff03378..112c544 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,7 +1,7 @@ -- User mockup data ALTER TABLE opinion MODIFY comment_count BIGINT NOT NULL DEFAULT 0; -INSERT INTO users (agree_terms, email, nick_name, password, category) +INSERT INTO user (agree_terms, email, nick_name, password, category) VALUES (TRUE, 'user1@example.com', 'UserOne', 'password1', 'BACKEND'), (TRUE, 'user2@example.com', 'UserTwo', 'password2', 'WEB_FRONT'), (TRUE, 'user3@example.com', 'UserThree', 'password3', 'NETWORK'), @@ -109,3 +109,7 @@ values (1,1), (4,1), (1,2), (6,2); + +# INSERT INTO memo (content,post_id,user_id) values('hello',1,1,''),('hello2',2,1); + +select * from memo; \ No newline at end of file