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

feat: 어드민 게시글 CRUD API 작성 #940

Merged
merged 30 commits into from
Oct 4, 2024

Conversation

songsunkook
Copy link
Collaborator

@songsunkook songsunkook commented Oct 3, 2024

🚀 작업 내용

  1. 코인 자체 게시글과 한기대 공지 게시글을 JOIN해서 제공하면 성능이 많이 떨어져서(100ms -> 13000ms) JOIN 없이 제공할 수 있도록 게시글 관련 DB 구조를 변경했습니다.
  2. 게시글 관련 기존 객체 Articlekoreatech_article이 아닌 articles 테이블을 참조하도록 변경했습니다.
  3. 게시글 관련 엔티티가 수정 및 추가되서 기존의 관련 비즈니스 로직도 일부 수정되었습니다.
  4. 옛날 코인 게시글 중 작성자 user 정보가 존재하지 않는 경우가 많아 탈퇴한 사용자의 코인 게시글은 제거했습니다.
  5. 코인 게시글의 사용자가 탈퇴한 경우 작성자 정보로 "탈퇴한 사용자"를 반환하도록 했습니다.
  6. 코인 공지 게시글을 어드민 페이지에서 열람하면 해당 어드민 계정의 name을 반환하고, 일반 코인 페이지에서 열람하면 "BCSD Lab"을 반환하도록 했습니다.

기존 테이블 구조

articles: 레거시 게시글 테이블. 옛날 코인 자체 게시글과 한기대 크롤링 게시글이 들어있음. 몇 달 전부터 미사용 중
koreatech_articles: 한기대 크롤링 게시글 테이블.

변경된 테이블 구조

articles: 게시글 테이블. 제목이나 내용 등 게시글 종류에 무관하게 필요한 내용이 포함됨
koreatech_articles: 한기대 크롤링 게시글만이 갖는 추가 필드를 다룸
koin_articles: 코인 자체 게시글만이 갖는 추가 필드를 다룸

💬 리뷰 중점사항

게시글 관련 DB 테이블을 싹 갈아엎어서 flyway가 많이 길어졌습니다. 로컬에서 꼭 한번씩 테스트해주시면 감사하겠습니다!

+) 이번 작업은 신규 캠퍼스팀원 @DHkimgit 및 백엔드 에이스 @ImTotem 과 함께 진행했습니다.

@songsunkook songsunkook added the Team Campus 캠퍼스 팀에서 작업할 이슈입니다 label Oct 3, 2024
@github-actions github-actions bot added the 기능 새로운 기능을 개발합니다. label Oct 3, 2024
@github-actions github-actions bot requested a review from kwoo28 October 3, 2024 14:43
Copy link

github-actions bot commented Oct 3, 2024

Unit Test Results

318 tests  +8   317 ✔️ +8   1m 23s ⏱️ +2s
  36 suites +1       1 💤 ±0 
  36 files   +1       0 ±0 

Results for commit 1cf2c98. ± Comparison against base commit a37767d.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@20HyeonsuLee 20HyeonsuLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

몇가지 코멘트 남겼습니다 확인해주세요~!

  • 추가로 리뷰하면서 ArticleService로직좀 살펴봤는데 리팩토링이 필요해보여요

`content` MEDIUMTEXT CHARACTER SET 'utf8mb4' NULL DEFAULT NULL COMMENT '내용',
`hit` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT '조회수',
`is_notice` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '공지사항인지 여부',
`is_deleted` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '삭제 여부',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

새로 생성하는 테이블들에 is_deleted가 꼭 필요한 걸까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

특정 작성자의 모든 게시글 조회와 같이 articles.is_deleted를 JOIN해서 함께 필터링해야 하는 경우를 감안해서 is_deleted를 koin_articles와 koreatech_articles도 가지도록 역정규화했습니다.

Comment on lines 14 to 15
DROP TABLE `koin`.`old_articles`;
DROP TABLE `koin`.`old_koreatech_articles`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C

기존 테이블의 삭제는 조금 보류해뒀으면 좋을 것 같아요.
배포중 롤백해야하는 상황이 생긴다면 git revert를 한 후 재배포를 할텐데 DB는 롤백이 안되기때문에 DB와 Entity의 정합성이 안맞을 것 같습니다

Copy link
Collaborator Author

@songsunkook songsunkook Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그래서 덤프뜨고 진행하면 되는지 질문드렸었는데 그래도 조심스럽게 대응해야 하는 건 맞는 것 같아요.
RENAME과 DROP만 나중으로 미루면 되는 내용이니 리뷰 반영해두겠습니다.

Copy link
Collaborator Author

@songsunkook songsunkook Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

적용 완료했습니다.(RENAME 롤백, DROP 롤백)

article_attachments 테이블은 기존 테이블을 그대로 사용하기 때문에 하위호환성을 지키기가 애매했습니다.

  • 기존에 걸려있던 article_id FK 해제
  • article_id 값 일괄 변경

따라서 배포 시 해당 테이블만 미리 dump해두고 진행하면 될 것 같습니다. 나머지 테이블은 전부 기존 테이블 그대로 유지했기에 코드만 롤백(revert)하면 됩니다.

Copy link
Contributor

@ImTotem ImTotem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!
배치만 보다가 보니까 적응이 안되네요 ㅋㅋㅋ

배치에도 테이블에 new_ 붙여야겠네요

Copy link
Contributor

@dradnats1012 dradnats1012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

송선권씨 옆에 두고 설명 들었습니다
DB 어렵네요...
몇가지만 확인해주세용

Comment on lines +62 to +65
Optional<Article> foundArticle = articleRepository.findById(noticeId);
if (foundArticle.isEmpty()) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getById()를 안쓴 이유가 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제거 요청은 대상 존재 유무에 상관없이 204 응답을 반환하는 것이 적절하다고 생각해서 대상이 존재하지 않는 경우 예외가 발생하는 getById() 대신 findById()를 사용하고 직접 핸들링하는 방향으로 작성했습니다.


@RestController
@RequiredArgsConstructor
public class AdminNoticeController implements AdminNoticeApi {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RequestMapping("/admin")으로 뺴도 될 것 같아요!

import jakarta.validation.Valid;

@Tag(name = "(Admin) Notice: 코인 공지", description = "")
public interface AdminNoticeApi {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도요!

@songsunkook songsunkook merged commit 8b1f5d9 into develop Oct 4, 2024
4 checks passed
@songsunkook songsunkook deleted the feature/admin-article-api branch October 4, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Campus 캠퍼스 팀에서 작업할 이슈입니다 기능 새로운 기능을 개발합니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants