Skip to content

CLI 자바 서비스 만들기 - 박은빈#4

Open
0-0v wants to merge 20 commits into
hoehoeabi:mainfrom
0-0v:eunbhin
Open

CLI 자바 서비스 만들기 - 박은빈#4
0-0v wants to merge 20 commits into
hoehoeabi:mainfrom
0-0v:eunbhin

Conversation

@0-0v
Copy link
Copy Markdown

@0-0v 0-0v commented Apr 16, 2026

📝 CLI Java 게시판

Java 콘솔 환경에서 동작하는 텍스트 기반 게시판 서비스입니다.
사용자의 명령어 입력을 기반으로 게시글을 생성, 조회, 수정, 삭제할 수 있습니다.


🎯 주요 기능

  • 게시글 작성 (write)
  • 게시글 목록 조회 (list)
  • 게시글 상세 조회 (detail [id])
  • 게시글 수정 (update [id])
  • 게시글 삭제 (delete [id])
  • 프로그램 종료 (exit)

🧩 프로젝트 구조

src/main/java/com/gg
├── App.java // 실행 로직 및 명령어 처리
├── AppContext.java// 공통 객체 관리 (Controller, Service 등)
├── Article.java // 게시글 도메인 객체
├── Main.java // 프로그램 시작점
├── Rq.java // 사용자 입력 명령어 파싱
└── domain
    ├── article
    │   ├── ArticleController.java
    │   ├── ArticleRepository.java
    │   └── ArticleService.java
    └── system
        └── SystemController.java


🧠 설계 구조

  • Controller

    • 사용자 입력 처리 및 출력 담당
  • Service

    • 비즈니스 로직 수행
  • Repository

    • ArrayList를 활용한 데이터 저장 및 관리

📦 데이터 구조

class Article {
    int id;
    String title;
    String content;
    LocalDateTime regDate;
    LocalDateTime modifiedDate;
}
  • regDate : 게시글 생성 시점
  • modifiedDate : 수정 시 갱신 (없으면 null)

⚙️ 주요 구현 포인트

✔️ 1. 명령어 파싱 (Rq 클래스)

  • "detail 1" 형태의 입력을 분리
  • action + id 구조로 처리
  • id 없거나 잘못된 경우 -1로 처리

✔️ 2. 날짜 처리

  • LocalDateTime으로 데이터 저장
  • 출력 시 DateTimeFormatter를 활용해 포맷 적용
  • 수정 시 modifiedDate 갱신

✔️ 3. 예외 처리

  • id 미입력 (-1)
  • 존재하지 않는 게시글
  • 잘못된 입력 값 처리

✔️ 4. 리스트 출력

  • 최신 게시글이 위로 오도록 역순 출력

💬 실행 예시

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

명령어: list
번호 | 제목       | 등록일
-----------------------------
1    | 자바 공부  | 2025-08-03

명령어: detail 1
번호: 1
제목: 자바 공부
내용: 자바 텍스트 게시판 만들기
등록일: 2025-08-03

명령어: update 1
제목 (현재: 자바 공부): Java 게시판
내용 (현재: 자바 텍스트 게시판 만들기): 콘솔 기반으로 구현
=> 게시글이 수정되었습니다.

명령어: delete 1
=> 게시글이 삭제되었습니다.

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

🚀 실행 방법

./gradlew run

🎯 배운 점

  • CLI 기반 서비스에서 사용자 입력 흐름 처리 경험
  • Controller / Service / Repository 구조를 통한 계층 분리 설계
  • LocalDateTime과 포맷팅을 통한 데이터 표현과 저장 분리
  • 예외 처리를 통한 안정적인 프로그램 흐름 제어

🔥 개선 방향

  • 파일 또는 DB 기반 데이터 영속성 추가
  • 검색 기능 (키워드 기반 필터링)
  • 페이징 처리
  • 테스트 코드 추가 (JUnit)

@0-0v 0-0v changed the title CLI 자바 서비스 - 박은빈 CLI 자바 서비스 만들기 - 박은빈 Apr 16, 2026
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.

얘도 article 패키지 안에 넣어두는게 어땠을까요?

public static final DateTimeFormatter forPrintDateTimeFormatter ;


static {
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.

이렇게도 선언되는줄 처음 알았습니다. 잘 배워 갑니다


public class SystemController {
public void actionExit(){
System.out.println("프로그램을 종료합니다.");
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.

스캐너도 같이 닫아줬으면 좋았을거 같아요



public void write(String title, String content) {
Article article = new Article(++id, title, content, LocalDateTime.now()); //게시글 작성시 Article 객체 생성
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.

메서드 반환값이 void니까 가독성 생각하면
articles.add(new``` Article(++id, title, content, LocalDateTime.now()));
이 방식도 괜찮을거같아요. 성능상으론 두 방식 모두 차이는 없으나 은빈님 방식이 디버깅할때는 유리하네요.

import java.time.LocalDateTime;

@Getter
@Setter
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.

세터로 다 여는 대신 갱신이 있을법한( 이번 프로젝트에선 title,content,modifiedDate) 필드값들만 업데이트 해주는 메서드를 만드는게 더 좋을거같아요.
어차피 객체 만들때 생성자로 변수들에 할당하니까 변수들은 모두 private로 외부 접근 불가능하게 만들고

public Article modify(String title,String content,LocalDateTime modifiedDate){
    this.title= title;
  // 생략

이런 느낌으로요

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.

고생하셨습니다~

@p7548296-afk
Copy link
Copy Markdown

MVC 패턴을 기반으로 Controller / Service / Repository를 명확하게 분리하신 부분과, 객체를 중앙에서 관리하는 방식 등 전체적으로 구조 설계가 인상적인 PR이었습니다!

@m1nhy2uk
Copy link
Copy Markdown

CRUD가 Repository에 잘 분리되어 있고, getArticleByIdOrPrintError 로 중복 예외처리를 하나로 묶은 게 깔끔해요. CRUD 책임이 Repository에 잘 분리되어 있는게 인상적입니다. 고생 많으셨습니다.

@woo0218
Copy link
Copy Markdown

woo0218 commented Apr 17, 2026

구조 설계를 깔끔하고 목적성에 맞게 진행하신 부분이 인상적이었습니다. 고생하셨습니다!

String content;
LocalDateTime regDate; //객체에 원본을 넣고 출력할 때 format -> 정렬, 포맷 변경 시 용이하게 하기 위함.
private LocalDateTime modifiedDate; // 수정일

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

modifiedDate만 따로 private으로 한 건 단순 오타이신가요 다른 이유가 있으신가요?

Copy link
Copy Markdown
Author

@0-0v 0-0v Apr 17, 2026

Choose a reason for hiding this comment

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

전체 수정하다가 생긴 이슈 같습니다 ㅎㅎ날카로우시네요

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.

고생하셨습니다~

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