Skip to content

[안중원] sprint 1 #5

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

Open
wants to merge 8 commits into
base: 안중원
Choose a base branch
from

Conversation

joongwonAn
Copy link

@joongwonAn joongwonAn commented Jun 4, 2025

목표

  • Git과 GitHub을 통해 프로젝트를 관리할 수 있다.
  • 채팅 서비스의 도메인 모델을 설계하고, Java로 구현할 수 있다.
  • 인터페이스를 설계하고 구현체를 구현할 수 있다.
  • 싱글톤 패턴을 구현할 수 있다.
  • Java Collections Framework에 데이터를 생성/수정/삭제할 수 있다.
  • Stream API를 통해 JCF의 데이터를 조회할 수 있다.
  • [심화] 모듈 간 의존 관계를 이해하고 팩토리 패턴을 활용해 의존성을 관리할 수 있다.

프로젝트 마일스톤

  • 프로젝트 초기화 (Java, Gradle)
  • 도메인 모델 구현
  • 서비스 인터페이스 설계 및 구현체 구현
    • 각 도메인 모델별 CRUD
    • JCFx메모리 기반
  • 의존성 주입

요구사항

기본 요구사항

프로젝트 초기화

  • IntelliJ를 통해 다음의 조건으로 Java 프로젝트를 생성합니다.
    • IntelliJ에서 제공하는 프로젝트 템플릿 중 Java를 선택합니다.
    • 프로젝트의 경로는 스프린트 미션 리포지토리의 경로와 같게 설정합니다.
  • Create Git Repository 옵션은 체크하지 않습니다.
  • Build system은 Gradle을 사용합니다. Gradle DSL은 Groovy를 사용합니다.
  • JDK 17을 선택합니다.
  • GroupId는 com.sprint.mission로 설정합니다.
  • ArtifactId는 수정하지 않습니다.
  • .gitignore에 IntelliJ와 관련된 파일이 형상관리 되지 않도록 .idea디렉토리를 추가합니다.

도메인 모델링

  • 디스코드 서비스를 활용해보면서 각 도메인 모델에 필요한 정보를 도출하고, Java Class로 구현하세요
    • 패키지명: com.sprint.mission.discodeit.entity
    • 도메인 모델 정의
      • 공통
        • id: 객체를 식별하기 위한 id로 UUID 타입으로 선언합니다.
        • createdAt, updatedAt: 각각 객체의 생성, 수정 시간을 유닉스 타임스탬프로 나타내기 위한 필드로 Long 타입으로 선언합니다.
      • User
      • Channel
      • Message
    • 생성자
      • id는 생성자에서 초기화하세요.
      • createdAt는 생성자에서 초기화하세요.
      • id, createdAt, updatedAt을 제외한 필드는 생성자의 파라미터를 통해 초기화하세요.
    • 메소드
      • 각 필드를 반환하는 Getter 함수를 정의하세요.
      • 필드를 수정하는 update 함수를 정의하세요.

서비스 설계 및 구현

  • 도메인 모델 별 CRUD(생성, 읽기, 모두 읽기, 수정, 삭제) 기능을 인터페이스로 선언하세요.

    • 인터페이스 패키지명: com.sprint.mission.discodeit.service
    • 인터페이스 네이밍 규칙: [도메인 모델 이름]Service
  • 다음의 조건을 만족하는 서비스 인터페이스의 구현체를 작성하세요.

    • 클래스 패키지명: com.sprint.mission.discodeit.service.jcf
    • 클래스 네이밍 규칙: JCF[인터페이스 이름]
    • Java Collections Framework를 활용하여 데이터를 저장할 수 있는 필드(data)를 final로 선언하고 생성자에서 초기화하세요.
    • data 필드를 활용해 생성, 조회, 수정, 삭제하는 메소드를 구현하세요.

메인 클래스 구현

  • 메인 메소드가 선언된 JavaApplication 클래스를 선언하고, 도메인 별 서비스 구현체를 테스트해보세요.
    • 등록
    • 조회(단건, 다건)
    • 수정
    • 수정된 데이터 조회
    • 삭제
    • 조회를 통해 삭제되었는지 확인

기본 요구사항 커밋 태그

  • 여기까지 진행 후 반드시 커밋해주세요. 그리고 sprint1-basic 태그를 생성해주세요.

심화 요구 사항

서비스 간 의존성 주입

  • 도메인 모델 간 관계를 고려해서 검증하는 로직을 추가하고, 테스트해보세요.

    힌트: Message를 생성할 때 연관된 도메인 모델 데이터 확인하기


피드백 내역

20250604

  • PR 세부내역 수정
  • Use - Channel - Message 간 양방향 관계임을 알고 동기화 시키기
  • for문인 곳을 Stream으로 고치기

import java.util.UUID;

public class JCFChannelService implements ChannelService {
private final List<Channel> data = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Map 사용이 더 적절해보입니다

import java.util.UUID;

public class JCFMessageService implements MessageService {
private final List<Message> data = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 Map

import java.util.stream.Collectors;

public class JCFUserService implements UserService {
private final List<User> data;
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 Map

Comment on lines +52 to +70
// 수정
/* @Override
public User updateUserById(UUID id, String newName) {
for (User user : data) {
if (user.getId().equals(id)) {
user.setUsername(newName);
user.setUpdatedAt();
return user;
}
}
return null;
}*/
// Stream 변환
/*
* update 로직 : 찾음 > 수정 > 반환
* filter > findFirst로 찾고, map으로 수정
* 여기서 map은 중간 연산자 아니고, Optional!!
*
* +) Stream은 내부 반복자라 전체를 내부 순회하므로 update 할 요소가 많아지면 Stream 사용 권장 X
Copy link
Collaborator

@joonfluence joonfluence Jun 10, 2025

Choose a reason for hiding this comment

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

개발단계에서 학습이나 코딩에는 도움이 되겠지만,
나중에는 이런 주석들은 다 삭제되어야 합니다!

Comment on lines +25 to +26
User user1 = userService.createUser("user1");
User user2 = userService.createUser("user2");
Copy link
Collaborator

Choose a reason for hiding this comment

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

유저이름을 String으로 넘겨 생성하는 것보다,
유저 객체를 넘겨서 생성하는 편이 좀 더 적절해보이긴 하네요

Copy link
Collaborator

@joonfluence joonfluence left a comment

Choose a reason for hiding this comment

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

전반적으로 리팩토링이 필요한 코드로 보입니다. Stream 활용 등은 잘 해주셨으나, 도메인 객체 내에 선언된 여러 메서드들이 사용되지 않는 경우도 더러 있고, 사용하지 않는/불필요한 주석 제거, Map 활용 등 여러 포인트들을 잡아서 리팩토링하면 좋겠습니다!

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.

2 participants