Skip to content

[권용진] Sprint2 #23

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 18 commits into
base: 권용진
Choose a base branch
from

Conversation

chaoskyj1120
Copy link
Collaborator

@chaoskyj1120 chaoskyj1120 commented Jun 12, 2025

요구사항

기본

File IO를 통한 데이터 영속화

  • 다음의 조건을 만족하는 서비스 인터페이스의 구현체를 작성하세요.
  • 클래스 패키지명: com.sprint.mission.discodeit.service.file
  • 클래스 네이밍 규칙: File[인터페이스 이름]
  • JCF 대신 FileIO와 객체 직렬화를 활용해 메소드를 구현하세요.
  • Application에서 서비스 구현체를 File*Service로 바꾸어 테스트해보세요.

서비스 구현체 분석

  • JCFService 구현체와 FileService 구현체를 비교하여 공통점과 차이점을 발견해보세요.
  • "비즈니스 로직"과 관련된 코드를 식별해보세요.
  • "저장 로직"과 관련된 코드를 식별해보세요.

레포지토리 설계 및 구현

  • "저장 로직"과 관련된 기능을 도메인 모델 별 인터페이스로 선언하세요.
  • 인터페이스 패키지명: com.sprint.mission.discodeit.repository
  • 인터페이스 네이밍 규칙: [도메인 모델 이름]Repository
  • 다음의 조건을 만족하는 레포지토리 인터페이스의 구현체를 작성하세요.
  • 클래스 패키지명: com.sprint.mission.discodeit.repository.jcf
  • 클래스 네이밍 규칙: JCF[인터페이스 이름]
  • 기존에 구현한 JCF*Service 구현체의 "저장 로직"과 관련된 코드를 참고하여 구현하세요.
  • 다음의 조건을 만족하는 레포지토리 인터페이스의 구현체를 작성하세요.
  • 클래스 패키지명: com.sprint.mission.discodeit.repository.file
  • 클래스 네이밍 규칙: File[인터페이스 이름]
  • 기존에 구현한 File*Service 구현체의 "저장 로직"과 관련된 코드를 참고하여 구현하세요.

심화

관심사 분리를 통한 레이어 간 의존성 주입

  • 다음의 조건을 만족하는 서비스 인터페이스의 구현체를 작성하세요.
  • 클래스 패키지명: com.sprint.mission.discodeit.service.basic
  • 클래스 네이밍 규칙: Basic[인터페이스 이름]
  • 기존에 구현한 서비스 구현체의 "비즈니스 로직"과 관련된 코드를 참고하여 구현하세요.
  • 필요한 Repository 인터페이스를 필드로 선언하고 생성자를 통해 초기화하세요.
  • "저장 로직"은 Repository 인터페이스 필드를 활용하세요. (직접 구현하지 마세요.)
  • Basic*Service 구현체를 활용하여 테스트해보세요.
  • JCF*Repository 구현체를 활용하여 테스트해보세요.
  • File*Repository 구현체를 활용하여 테스트해보세요.
  • 이전에 작성했던 코드(JCFService 또는 FileService)와 비교해 어떤 차이가 있는지 정리해보세요.

주요 변경사항

@chaoskyj1120 chaoskyj1120 changed the title Sprint2 [권용진] [권용진] Sprint2 Jun 12, 2025
파일 수정 시 동기화 적용
중첩 for문 stream으로 변경
public void addChannel(Channel channel) {
for (Channel c : channels) {
if(c.getId().equals(channel.getId())) {
// 같은 걸 찾믕
Copy link
Collaborator

Choose a reason for hiding this comment

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

별건 아닌데 오타가 있네요 ㅎㅎ

}

if(!channels.contains(channel)) {
System.out.println("1231231"+channel.getUsers());
Copy link
Collaborator

Choose a reason for hiding this comment

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

1231231 은 혹시 어떤 값일까요?
만약 디버깅 용도로 넣어 두신거면 제외해주시고, 디버깅은 디버깅 기능을 사용해서 하시는 습관을 들이시면 좋을것 같아여!

"\nmessages=" + messages.stream().map(Message::toString).toList() +
'}';
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

EOL 확인해주세요!


@Override
public Channel createChannel(User user, String channelName) {
if (user.getStatus() == UserStatus.DEACTIVE) return null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

return null 로 하시고 null을 외부에서 처리하지 마시고, 아예 예외로 던지는 것도 좋은 선택입니다.
아래도 수정 고려해주세요!!

Comment on lines +65 to +69
for(User userFromFile : users) {
if(userFromFile.getId().equals(user.getId())) {
userFromFile.addMessage(newMessage);
break;
}
Copy link
Collaborator

@spring-kang spring-kang Jun 18, 2025

Choose a reason for hiding this comment

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

함수형으로 한번 작성해보시길 권해드립니다.

아래 for문들도 모두 확인해서 함수형으로 짜보시고 어떤 로직이 더 가독성이 있는지 판단해보시기 바랍니다.

// ArrayList<User> 역직렬화및 반환
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(USER_FILE_PATH))) {
return (List<User>) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

에러는 각각 처리해주시는게 좋습니다.

File file = new File(USER_FILE_PATH);

if (!file.exists() || file.length() == 0) {
return new ArrayList<User>(); // 해당 파일이 없거나 비어 있다면 빈 ArrayList를 반환
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return new ArrayList<User>(); // 해당 파일이 없거나 비어 있다면 빈 ArrayList를 반환
return Collections.emptyList();// 해당 파일이 없거나 비어 있다면 빈 ArrayList를 반환

빈리스트를 반환하는게 목적이라면 의도가 명확하게 위처럼 표현하시는게 훨씬 직관적입니다.
불변 리스트를 리턴하는 것이기도 하구요.

@spring-kang
Copy link
Collaborator

서비스 초기화시 레퍼지토리를 주입하는 형태로 구현하셔야합니다! 의존성 주입에 대한 공부를 해보시면 좋을것 같아요!

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