-
Notifications
You must be signed in to change notification settings - Fork 24
[조백선] sprint3 #89
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
base: 조백선
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uC870\uBC31\uC120-sprint3"
[조백선] sprint3 #89
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/gradlew text eol=lf | ||
*.bat text eol=crlf | ||
*.jar binary |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
plugins { | ||
id 'java' | ||
id 'java' | ||
id 'org.springframework.boot' version '3.4.4' | ||
id 'io.spring.dependency-management' version '1.1.7' | ||
} | ||
|
||
group = 'com.sprint.mission' | ||
version = '1.0-SNAPSHOT' | ||
version = '0.0.1-SNAPSHOT' | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
configurations { | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation platform('org.junit:junit-bom:5.10.0') | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#Tue Apr 08 18:10:09 KST 2025 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
rootProject.name = '3-sprint-mission' | ||
|
||
rootProject.name = 'discodeit' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.sprint.mission.discodeit; | ||
|
||
import com.sprint.mission.discodeit.dto.data.ChannelDto; | ||
import com.sprint.mission.discodeit.dto.data.UserDto; | ||
import com.sprint.mission.discodeit.dto.request.MessageCreateRequest; | ||
import com.sprint.mission.discodeit.dto.request.PublicChannelCreateRequest; | ||
import com.sprint.mission.discodeit.dto.request.UserCreateRequest; | ||
import com.sprint.mission.discodeit.entity.Channel; | ||
import com.sprint.mission.discodeit.entity.Message; | ||
import com.sprint.mission.discodeit.entity.User; | ||
import com.sprint.mission.discodeit.repository.ChannelRepository; | ||
import com.sprint.mission.discodeit.repository.UserRepository; | ||
import com.sprint.mission.discodeit.service.ChannelService; | ||
import com.sprint.mission.discodeit.service.MessageService; | ||
import com.sprint.mission.discodeit.service.UserService; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.Optional; | ||
|
||
@SpringBootApplication | ||
public class DiscodeitApplication { | ||
|
||
static User setupUser(UserService userService) { | ||
UserCreateRequest request = new UserCreateRequest("woody", "[email protected]", "woody1234"); | ||
User user = userService.create(request, Optional.empty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 파라미터로 Optional을 받는건 조금 어색한거 같아요. 일단 Optional을 파라미터로 받는건 안티패턴으로 알고 있어요. Optional은 반환값을 관리위해서 사용된 개념이어서요. 참고 : https://yeonyeon.tistory.com/224 질문에도 있던 사항인거 같아 같이 답을 드리면, 나중에 Rest API 형태로 구현할거라 생각이 되는데요. 그때 보통 Controller에서 Multipart 형태로 데이터를 받을거에요. 파일 자체가 크니까 Controller에서 local에 특정 경로(여러 저장 요청을 동시에 받을 수 있으므로 경로 timestamp로 경로 구분해서) 에 저장해두고 그 경로만 그리고 Controller에서 finally 혹은 try-resources로 반드시 local에 저장해둔 파일 있으면 삭제까지 하구요. 그런데 요구사항에서 User랑 Message에서 BinaryContent를 의존하는걸로 봐서는 코드 내에서 파일 바이너리 값은 전체를 계속 다룰 생각인가 보내요. 그 바이너리 값도 UserCreateRequestDTO 안에 있는게 더 좋을거 같아요. 그게 더 직관적일거 같아요 |
||
return user; | ||
} | ||
|
||
static Channel setupChannel(ChannelService channelService) { | ||
PublicChannelCreateRequest request = new PublicChannelCreateRequest("공지", "공지 채널입니다."); | ||
Channel channel = channelService.create(request); | ||
return channel; | ||
} | ||
|
||
static void messageCreateTest(MessageService messageService, Channel channel, User author) { | ||
MessageCreateRequest request = new MessageCreateRequest(channel.getId(), author.getId(), "안녕하세요."); | ||
Message message = messageService.create(request, new ArrayList<>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기에서도 ArrayList 파라미터 더 받지 말고 파일은 미리 처리하고 필요한 변수들은 최대한 MessageCreateRequest 안에서 가지고 있도록 작성해주세요. 변수를 여러개 받아야한다는걸 매번 고민하는 것 보다 MessageCreateRequest에 필요한 변수가 다 있는 형태가 더 직관적이라고 생각해요. |
||
System.out.println("메시지 생성: " + message.getId()); | ||
} | ||
|
||
public static void main(String[] args) { | ||
ConfigurableApplicationContext context = SpringApplication.run(DiscodeitApplication.class, args); | ||
|
||
UserService userService = context.getBean(UserService.class); | ||
ChannelService channelService = context.getBean(ChannelService.class); | ||
MessageService messageService = context.getBean(MessageService.class); | ||
|
||
User user = setupUser(userService); | ||
Channel channel = setupChannel(channelService); | ||
|
||
messageCreateTest(messageService, channel, user); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 프로젝트에서 lombok을 사용하고 있는데, 기왕 롬복을 사용할거라면 인스턴스를 생성할때도 Builder 패턴을 사용하길 권장드려요.
이유는 new 생성자로 생성하는건 파라미터의 순서와 갯수를 매번 고려해야하고 읽는 사람이 가독성이 떨어지는 단점이 있어요.
반면에 Builder 패턴은 어떤 변수에 어떤 값이 들어갈지 바로 보이기 때문에 가독성이나 순서와 갯수를 고려하지 않아도 돼죠.
현대화된 언어들에서는
Named Parameter
라는 개념으로 파라미터를 호출할때 지정하는 방법이 있는데, 자바에서는 아직 그게 없네요 ㅎㅎ 그래서 builder 패턴을 사용하는거에요.참고
빌터패턴 : https://gwonbookcase.tistory.com/100?category=777301
Dart의 Named parameter : https://leftday.tistory.com/120