Skip to content

CLI 자바 서비스 만들기 - 이민서#2

Open
p7548296-afk wants to merge 60 commits into
hoehoeabi:mainfrom
p7548296-afk:pr/clipost-main
Open

CLI 자바 서비스 만들기 - 이민서#2
p7548296-afk wants to merge 60 commits into
hoehoeabi:mainfrom
p7548296-afk:pr/clipost-main

Conversation

@p7548296-afk
Copy link
Copy Markdown

@p7548296-afk p7548296-afk commented Apr 16, 2026

  • 게시글 작성
  • 게시글 목록
  • 게시글 상세보기
  • 게시글 수정
  • 게시글 삭제
  • 종료
  • 게시글 조회수
  • 게시글 검색

CLI 자바 서비스 만들기

Java 콘솔 기반 텍스트 게시판 프로젝트입니다.

개요

  • 명령어 입력으로 게시글 CRUD를 수행합니다.
  • 객체지향 설계와 테스트 주도 방식으로 기능을 확장했습니다.
  • 현재는 조회수/검색 기능까지 구현된 상태입니다.

구현 기능

기능 명령어 설명
게시글 작성 write 제목/내용 입력 후 게시글 등록
게시글 목록 list 최신글 우선으로 목록 출력
게시글 상세보기 detail [id] 게시글 상세 조회 + 조회수 증가
게시글 수정 update [id] 제목/내용 수정
게시글 삭제 delete [id] 게시글 삭제
게시글 검색 search [keyword] 제목/내용 포함 검색
종료 exit 프로그램 종료

게시글 데이터 구조

class Article {
    int id;
    String title;
    String content;
    String regDate; // yyyy-MM-dd
    int count;      // 조회수
}

프로젝트 구조

src/
├─ main/
│  └─ java/com/ll/
│     ├─ Main.java           // 진입점
│     ├─ App.java            // 입출력 + 명령 라우팅
│     ├─ ArticleService.java // 게시글 비즈니스 로직
│     ├─ Article.java        // 게시글 도메인 모델
│     └─ Rq.java             // 명령어 파싱 유틸
└─ test/
   └─ java/com/ll/
      ├─ AppTest.java
      ├─ ArticleServiceTest.java
      ├─ ArticleTest.java
      └─ RqTest.java

실행 방법

./gradlew run

Windows PowerShell:

.\gradlew.bat run

실행 예시

명령어) write
제목: 자바 공부
내용: 자바 텍스트 게시판 만들기
=> 게시글이 등록되었습니다.

명령어) list
번호 | 제목 | 등록일 | 조회수
-----------------------------
1    | 자바 공부  | 2026-04-15 | 0

명령어) detail 1
번호: 1
제목: 자바 공부
내용: 자바 텍스트 게시판 만들기
등록일: 2026-04-15
조회수: 1

명령어) search 자바
번호 | 제목 | 등록일 | 조회수
-----------------------------
1    | 자바 공부  | 2026-04-15 | 1

명령어) exit
프로그램을 종료합니다.

테스트

./gradlew test

Windows PowerShell:

.\gradlew.bat test
  • 단정문은 AssertJ(assertThat) 스타일을 사용합니다.

개발 포인트

  • Scanner 기반 입력 처리
  • ArrayList<Article> 기반 목록 관리
  • LocalDate.now() 기반 등록일 관리
  • 최신글 우선(역순) 목록 출력
  • App/ArticleService/Article/Rq 책임 분리
  • JUnit5 + AssertJ 기반 단위 테스트 구성

추가 기능 체크리스트

  • 게시글 조회수 기능 (count)
  • 게시글 검색 기능 (search [keyword])
  • 파일 저장/불러오기
  • 게시글 정렬 옵션 (날짜순, 번호순 등)

hoehoeabi and others added 30 commits April 7, 2026 17:08
Added project overview, features, and class structure to README.
- App을 실행
- 뷰를 분리할 예정
hoehoeabi and others added 18 commits April 15, 2026 09:37
- static 변수는 프로그램이 시작될 때 메모리에 올라가서 종료될 때까지 남아있다. ArticleRepository나 ArticleService 인스턴스는 어차피 ArticleController가 생성될 때 내부 필드로 주입되어 계속 참조되고 있으므로, Container가 굳이 중복해서 들고 있을 필요가 없다.

- 외부에서 Container.getArticleService()를 호출할 일이 없다.
- 기존 : case "list" -> articleController.showList();
- 이후 : case "list" -> articleController.showList(rq);
- 유틸클래스에 들어가기엔 page,pageable,Rq 셋다 안어울린다고 생각하였기에
return this.count;
}

public void setId(int id) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

id는 최초에 생성될때 할당되고 그뒤로 바뀔일이 없으니 setId는 노출 안시키는게 좋을거같아요


// 전체 게시글 목록을 반환합니다.
public List<Article> findAll() {
return List.copyOf(postList);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

수정되면 안되니까 불변객체로 내보낸거 좋은거같아여ㅛ

}

// 명령어(actionName)에 따라 기능을 분기 실행하고, 종료 명령이면 true를 반환합니다.
private boolean handleCommand(Rq rq) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

코드뎁스때문에 따로 메서드로 빼신거 좋은거같아요


return false;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

여유가 되신다면 화면에 보여주는 부분(View)과 명령을 전달하는 부분(Controller)을 조금씩 나누어보는 건 어떨까요? 지금 당장 바꾸지 않더라도, 나중에 기능이 더 늘어날 때를 대비해 역할을 나누는 연습을 해보시면 큰 도움이 될 것 같아 조심스럽게 의견 남겨봅니다!

Copy link
Copy Markdown
Owner

@hoehoeabi hoehoeabi left a comment

Choose a reason for hiding this comment

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

테스트코드 짜기 귀찮으셨을텐데 고생 많으셨습니다

@Nested
@DisplayName("게시글 목록 출력(listArticles) 테스트")
class ListArticlesTest {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

테스트 사항들을 구체적으로 나누면서 작성하신게 인상적이었습니다! 고생하셨습니다!

printArticleRow(articles.get(i));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

reversed()를 쓰지 않으신 건 목록 출력할 때마다 정렬하는 오버헤드를 고려하신 건가요 아니면 다른 이유가 있으신가요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

reversed()를 안 쓴 건 보통 매번 복사/정렬하는 비용과 원본 순서 변경 위험을 피하기 위해서 입니다!
list 출력은 원본은 그대로 두고, 인덱스를 뒤에서부터 순회하는 방식이 가장 단순하고 안정적이라고 해서 사용해봤습니다.

Copy link
Copy Markdown

@kjh3165 kjh3165 left a comment

Choose a reason for hiding this comment

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

조회수, 검색 기능 추가하시고 예외처리도 적절하게 하시고 TDD도 적용하셨네요. 고생하셨습니다~

@0-0v
Copy link
Copy Markdown

0-0v commented Apr 17, 2026

추가 기능과 TDD까지 구현하신 점이 좋아 보입니다! 또 주석을 함께 작성해주셔서 코드 흐름을 이해하는 데 도움이 되었습니다
커밋을 조금 더 세분화하고 파일도 역할별로 나누면 전체 구조를 파악하기 더 수월할 것 같습니다.!!

Copy link
Copy Markdown

@m1nhy2uk m1nhy2uk left a comment

Choose a reason for hiding this comment

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

주석이 잘 달려있어 읽는데 수월했습니다.
테스트코드짜시는데 고생하신게 엿보입니다.
고생많으셨습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

작은 동작들을 메서드로 잘 분리된거같아요.
App이 Controller + Service 역할을 동시에 하고 있어 분리가 되도 좋을 것 같습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants