Skip to content

Commit 7c44d88

Browse files
authored
Merge pull request #178 from yinneu/part1-연예림-sprint3
[연예림] sprint3
2 parents b9b1866 + 2b0fb6d commit 7c44d88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1781
-1170
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
.metadata
66
bin/
77
tmp/
8+
log/
9+
*.log
810
*.tmp
911
*.bak
1012
*.swp
@@ -13,6 +15,7 @@ local.properties
1315
.settings/
1416
.loadpath
1517
.recommenders
18+
.github/
1619

1720
# External tool builders
1821
.externalToolBuilders/

build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
plugins {
22
id 'java'
33
id 'checkstyle'
4+
id 'org.springframework.boot' version '3.4.0'
5+
id 'io.spring.dependency-management' version '1.1.7'
46
}
57

68
group = 'com.sprint.mission'
79
version = '1.0-SNAPSHOT'
810

11+
java {
12+
toolchain {
13+
languageVersion = JavaLanguageVersion.of(17)
14+
}
15+
}
16+
17+
configurations {
18+
compileOnly {
19+
extendsFrom annotationProcessor
20+
}
21+
}
22+
923
repositories {
1024
mavenCentral()
1125
}
1226

1327
dependencies {
28+
implementation 'org.springframework.boot:spring-boot-starter-web'
29+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
30+
compileOnly 'org.projectlombok:lombok'
31+
annotationProcessor 'org.projectlombok:lombok'
1432
testImplementation platform('org.junit:junit-bom:5.10.0')
1533
testImplementation 'org.junit.jupiter:junit-jupiter'
1634
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.sprint.mission.discodeit;
2+
3+
import com.sprint.mission.discodeit.dto.*;
4+
import com.sprint.mission.discodeit.entity.Channel;
5+
import com.sprint.mission.discodeit.entity.Message;
6+
import com.sprint.mission.discodeit.entity.User;
7+
import com.sprint.mission.discodeit.service.ChannelService;
8+
import com.sprint.mission.discodeit.service.MessageService;
9+
import com.sprint.mission.discodeit.service.UserService;
10+
import lombok.extern.slf4j.Slf4j;
11+
import org.springframework.boot.SpringApplication;
12+
import org.springframework.boot.autoconfigure.SpringBootApplication;
13+
import org.springframework.context.ConfigurableApplicationContext;
14+
15+
import java.util.List;
16+
import java.util.UUID;
17+
18+
@SpringBootApplication
19+
@Slf4j
20+
public class DiscodeitApplication {
21+
22+
static UserResponse setupUser(UserService userService) {
23+
return userService.createUser(new UserRequest("woody34", "woody34@codeit.com", "woody1234", null));
24+
}
25+
26+
static ChannelResponse setupChannel(ChannelService channelService) {
27+
return channelService.createPublicChannel(new ChannelRequest.CreatePublic("공지", "공지 채널입니다."));
28+
}
29+
30+
static ChannelResponse setupPrivateChannel(ChannelService channelService, List<UUID> joinUsers) {
31+
return channelService.createPrivateChannel(new ChannelRequest.CreatePrivate(joinUsers));
32+
}
33+
34+
static void messageCreateTest(MessageService messageService, UUID channelId, UUID authorId) {
35+
Message message = messageService.createMessage(new MessageRequest.Create("안녕하세요.", channelId, authorId, null));
36+
log.info("메시지 생성: {}", message.getId());
37+
}
38+
39+
public static void main(String[] args) {
40+
ConfigurableApplicationContext context = SpringApplication.run(DiscodeitApplication.class, args);
41+
42+
// 서비스 초기화
43+
// TODO context에서 Bean을 조회하여 각 서비스 구현체 할당 코드 작성하세요.
44+
UserService userService = context.getBean(UserService.class);
45+
ChannelService channelService = context.getBean(ChannelService.class);
46+
MessageService messageService = context.getBean(MessageService.class);
47+
48+
// 셋업
49+
UserResponse user = setupUser(userService);
50+
ChannelResponse channel = setupChannel(channelService);
51+
ChannelResponse privateChannel = setupPrivateChannel(channelService, List.of(user.id()));
52+
// 테스트
53+
messageCreateTest(messageService, channel.id(), user.id());
54+
}
55+
}
Lines changed: 58 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,58 @@
1-
package com.sprint.mission.discodeit;
2-
3-
import com.sprint.mission.discodeit.entity.*;
4-
import com.sprint.mission.discodeit.repository.ChannelRepository;
5-
import com.sprint.mission.discodeit.repository.MessageRepository;
6-
import com.sprint.mission.discodeit.repository.UserRepository;
7-
import com.sprint.mission.discodeit.repository.file.FileChannelRepository;
8-
import com.sprint.mission.discodeit.repository.file.FileMessageRepository;
9-
import com.sprint.mission.discodeit.repository.file.FileUserRepository;
10-
import com.sprint.mission.discodeit.repository.jcf.JCFChannelRepository;
11-
import com.sprint.mission.discodeit.repository.jcf.JCFMessageRepository;
12-
import com.sprint.mission.discodeit.repository.jcf.JCFUserRepository;
13-
import com.sprint.mission.discodeit.service.*;
14-
import com.sprint.mission.discodeit.service.basic.BasicChannelService;
15-
import com.sprint.mission.discodeit.service.basic.BasicMassageService;
16-
import com.sprint.mission.discodeit.service.basic.BasicUserService;
17-
import com.sprint.mission.discodeit.service.file.*;
18-
import com.sprint.mission.discodeit.service.jcf.*;
19-
20-
import java.util.List;
21-
22-
public class JavaApplication {
23-
24-
static User setupUser(UserService userService) {
25-
User user = userService.createUser("woody", "woody@codeit.com", "woody1234");
26-
return user;
27-
}
28-
29-
static Channel setupChannel(ChannelService channelService) {
30-
Channel channel = channelService.createChannel(ChannelType.PUBLIC, "공지", "공지 채널입니다.");
31-
return channel;
32-
}
33-
34-
static void messageCreateTest(MessageService messageService, Channel channel, User author) {
35-
Message message = messageService.createMessage("안녕하세요.", channel.getId(), author.getId());
36-
System.out.println("메시지 생성: " + message.getId());
37-
}
38-
39-
public static void main(String[] args) {
40-
41-
// jcf
42-
// System.out.println("===Use JCF Repository===");
43-
// UserRepository userRepository = new JCFUserRepository();
44-
// ChannelRepository channelRepository = new JCFChannelRepository();
45-
// MessageRepository messageRepository = new JCFMessageRepository();
46-
47-
// file
48-
System.out.println("===Use File Repository===");
49-
UserRepository userRepository = new FileUserRepository();
50-
ChannelRepository channelRepository = new FileChannelRepository();
51-
MessageRepository messageRepository = new FileMessageRepository();
52-
53-
// 서비스 초기화
54-
// TODO Basic*Service 구현체를 초기화하세요.
55-
UserService userService = new BasicUserService(userRepository);
56-
ChannelService channelService = new BasicChannelService(channelRepository, userService);
57-
MessageService messageService = new BasicMassageService(messageRepository, channelService, userService);
58-
59-
// 셋업
60-
User user = setupUser(userService);
61-
Channel channel = setupChannel(channelService);
62-
// 테스트
63-
messageCreateTest(messageService, channel, user);
64-
65-
}
66-
}
1+
//package com.sprint.mission.discodeit;
2+
//
3+
//import com.sprint.mission.discodeit.entity.*;
4+
//import com.sprint.mission.discodeit.repository.ChannelRepository;
5+
//import com.sprint.mission.discodeit.repository.MessageRepository;
6+
//import com.sprint.mission.discodeit.repository.UserRepository;
7+
//import com.sprint.mission.discodeit.repository.file.*;
8+
//import com.sprint.mission.discodeit.repository.jcf.*;
9+
//import com.sprint.mission.discodeit.service.*;
10+
//import com.sprint.mission.discodeit.service.basic.BasicChannelService;
11+
//import com.sprint.mission.discodeit.service.basic.BasicMassageService;
12+
//import com.sprint.mission.discodeit.service.basic.BasicUserService;
13+
//
14+
//public class JavaApplication {
15+
//
16+
// static User setupUser(UserService userService) {
17+
// User user = userService.createUser("woody", "woody@codeit.com", "woody1234");
18+
// return user;
19+
// }
20+
//
21+
// static Channel setupChannel(ChannelService channelService) {
22+
// Channel channel = channelService.createChannel(Channel.ChannelType.PUBLIC, "공지", "공지 채널입니다.");
23+
// return channel;
24+
// }
25+
//
26+
// static void messageCreateTest(MessageService messageService, Channel channel, User author) {
27+
// Message message = messageService.createMessage("안녕하세요.", channel.getId(), author.getId());
28+
// System.out.println("메시지 생성: " + message.getId());
29+
// }
30+
//
31+
// public static void main(String[] args) {
32+
//
33+
// // jcf
34+
//// System.out.println("===Use JCF Repository===");
35+
//// UserRepository userRepository = new JCFUserRepository();
36+
//// ChannelRepository channelRepository = new JCFChannelRepository();
37+
//// MessageRepository messageRepository = new JCFMessageRepository();
38+
//
39+
// // file
40+
// System.out.println("===Use File Repository===");
41+
// UserRepository userRepository = new FileUserRepository();
42+
// ChannelRepository channelRepository = new FileChannelRepository();
43+
// MessageRepository messageRepository = new FileMessageRepository();
44+
//
45+
// // 서비스 초기화
46+
//// // TODO Basic*Service 구현체를 초기화하세요.
47+
//// UserService userService = new BasicUserService(userRepository);
48+
//// ChannelService channelService = new BasicChannelService(channelRepository);
49+
//// MessageService messageService = new BasicMassageService(messageRepository, channelService, userService);
50+
////
51+
//// // 셋업
52+
//// User user = setupUser(userService);
53+
//// Channel channel = setupChannel(channelService);
54+
//// // 테스트
55+
//// messageCreateTest(messageService, channel, user);
56+
//
57+
// }
58+
//}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.sprint.mission.discodeit.dto;
2+
3+
import java.util.List;
4+
import java.util.UUID;
5+
6+
public record ChannelRequest(
7+
) {
8+
public record CreatePublic(
9+
String title,
10+
String description
11+
) {}
12+
13+
public record CreatePrivate(
14+
List<UUID> joinUsers
15+
) {}
16+
17+
public record Update(
18+
String title,
19+
String description
20+
) {}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.sprint.mission.discodeit.dto;
2+
3+
import com.sprint.mission.discodeit.entity.Channel;
4+
5+
import java.time.Instant;
6+
import java.util.List;
7+
import java.util.UUID;
8+
9+
public record ChannelResponse(
10+
UUID id,
11+
String title,
12+
String description,
13+
Channel.ChannelType channelType,
14+
Instant createdAt,
15+
Instant updatedAt,
16+
Instant lastMessageTime,
17+
List<UUID> joinUsers
18+
) {
19+
public static ChannelResponse entityToDto(Channel channel, Instant lastMessageTime, List<UUID> joinUsers) {
20+
return new ChannelResponse(channel.getId(), channel.getTitle(), channel.getDescription(), channel.getChannelType(), channel.getCreatedAt(), channel.getUpdatedAt(), lastMessageTime, joinUsers);
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.sprint.mission.discodeit.dto;
2+
3+
import org.springframework.web.multipart.MultipartFile;
4+
5+
import java.util.List;
6+
import java.util.UUID;
7+
8+
public record MessageRequest() {
9+
public record Create(
10+
String content,
11+
UUID channelId,
12+
UUID userId,
13+
List<MultipartFile> files
14+
) {}
15+
16+
public record Update(
17+
String content,
18+
List<MultipartFile> files
19+
) {}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.sprint.mission.discodeit.dto;
2+
3+
import org.springframework.web.multipart.MultipartFile;
4+
5+
import java.util.UUID;
6+
7+
public record UserRequest(
8+
String name,
9+
String email,
10+
String password,
11+
MultipartFile file
12+
) {
13+
14+
public record Login(
15+
String name,
16+
String password
17+
){
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.sprint.mission.discodeit.dto;
2+
3+
import com.sprint.mission.discodeit.entity.User;
4+
import com.sprint.mission.discodeit.entity.UserStatus;
5+
6+
import java.time.Instant;
7+
import java.util.UUID;
8+
9+
public record UserResponse(
10+
UUID id,
11+
Instant createdAt,
12+
Instant updatedAt,
13+
String name,
14+
String email,
15+
UserStatus.Status status
16+
) {
17+
public static UserResponse entityToDto(User user, UserStatus userStatus) {
18+
return new UserResponse(user.getId(), user.getCreatedAt(), user.getUpdatedAt(), user.getName(), user.getEmail(), userStatus.getStatus());
19+
}
20+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.sprint.mission.discodeit.entity;
2+
3+
import lombok.Getter;
4+
5+
import java.io.Serializable;
6+
import java.time.Instant;
7+
import java.util.UUID;
8+
9+
@Getter
10+
public class BinaryContent implements Serializable {
11+
private static final long serialVersionUID = 1L;
12+
private final UUID id;
13+
private Instant createdAt;
14+
private String fileName;
15+
private String contentType;
16+
private byte[] bytes;
17+
private ParentType parentType;
18+
private UUID userId;
19+
private UUID messageId;
20+
21+
public enum ParentType {
22+
USER,
23+
MESSAGE
24+
}
25+
26+
public static BinaryContent createBinaryContent(String fileName, String contentType, byte[] bytes, ParentType parentType, UUID parentId) {
27+
if (parentType == ParentType.USER) {
28+
return new BinaryContent(fileName, contentType, bytes, parentType, parentId, null);
29+
} else {
30+
return new BinaryContent(fileName, contentType, bytes, parentType, null, parentId);
31+
}
32+
}
33+
34+
private BinaryContent(String fileName, String contentType, byte[] bytes, ParentType parentType, UUID userId, UUID messageId) {
35+
this.id = UUID.randomUUID();
36+
this.createdAt = Instant.now();
37+
this.fileName = fileName;
38+
this.bytes = bytes;
39+
this.contentType = contentType;
40+
this.parentType = parentType;
41+
this.userId = userId;
42+
this.messageId = messageId;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "BinaryContent{id:" + id
48+
+ ",userId:" + userId
49+
+ ",createdAt:" + createdAt
50+
+ ",fileName:" + fileName
51+
+ ",contentType:" + contentType
52+
+ ",parentType:" + parentType
53+
+ ",userId:" + userId
54+
+ ",messageId:" + messageId
55+
+ "}";
56+
}
57+
58+
}

0 commit comments

Comments
 (0)