Skip to content

Commit 708bb4e

Browse files
authored
Merge pull request #52 from hyohyo-zz/sprint2-advenced
[조현아] sprint2
2 parents a572c6e + 7868df7 commit 708bb4e

31 files changed

+1305
-85
lines changed

HELP.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Getting Started
2+
3+
### Reference Documentation
4+
For further reference, please consider the following sections:
5+
6+
* [Official Gradle documentation](https://docs.gradle.org)
7+
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.4/gradle-plugin)
8+
* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.4/gradle-plugin/packaging-oci-image.html)
9+
* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html)
10+
11+
### Guides
12+
The following guides illustrate how to use some features concretely:
13+
14+
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
15+
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
16+
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)
17+
18+
### Additional Links
19+
These additional references should also help you:
20+
21+
* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)
22+

src/main/java/com/sprint/mission/discodeit/JavaApplication.java

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
import com.sprint.mission.discodeit.service.ChannelService;
88
import com.sprint.mission.discodeit.service.MessageService;
99
import com.sprint.mission.discodeit.service.UserService;
10+
import com.sprint.mission.discodeit.util.DataInitializer;
1011

1112
import java.util.*;
1213
import java.util.stream.Collectors;
1314

1415
public class JavaApplication {
1516
public static void main(String[] args) {
17+
//초기화
18+
DataInitializer.clearSerializedData();
19+
1620
ServiceFactory serviceFactory = ServiceFactory.getInstance();
1721

1822
ChannelService channelService = serviceFactory.createChannelService();
@@ -30,7 +34,6 @@ public static void main(String[] args) {
3034

3135
}
3236

33-
3437
//유저생성 및 등록
3538
private static List<User> createAndRegisterUsers(UserService userService) {
3639
List<User> users = List.of(
@@ -40,9 +43,7 @@ private static List<User> createAndRegisterUsers(UserService userService) {
4043
new User("이훈이", "남", "[email protected]", "010-2345-6789", "2hun222"),
4144
new User("맹구", "남", "[email protected]", "010-1010-0101", "stone_lover"),
4245
new User("한유리", "여", "[email protected]", "010-1111-2222", "12345"),
43-
//-----심화-----//
44-
//중복 이메일 유저_ex)
45-
new User("한유리", "여", "[email protected]", "010-1111-2222", "12345")
46+
new User("한유리", "여", "[email protected]", "010-1111-2222", "12345") //중복 이메일 유저_ex)
4647
);
4748

4849
System.out.println("<--------------------유저를 등록합니다------------------------->\n.\n.");
@@ -62,7 +63,6 @@ private static List<User> createAndRegisterUsers(UserService userService) {
6263

6364
System.out.println(".\n.\n<--------------------유저 등록 종료---------------------------->\n");
6465
return registeredUsers;
65-
//-----심화-----//
6666
}
6767

6868
//채널,멤버,카테고리 생성 및 등록
@@ -71,11 +71,9 @@ private static List<Channel> createAndRegisterChannels(ChannelService channelSer
7171
Set<User> members1 = new HashSet<>(Set.of(users.get(0), users.get(1), users.get(3)));
7272
List<String> cat1 = List.of("공지", "질문", "2팀");
7373

74-
//채널2 멤버, 카테고리생성
7574
Set<User> members2 = new HashSet<>(Set.of(users.get(1), users.get(2), users.get(4)));
7675
List<String> cat2 = List.of("이벤트", "소통");
7776

78-
//채널3 멤버, 카테고리생성
7977
Set<User> members3 = new HashSet<>(Set.of(users.get(5)));
8078
List<String> cat3 = List.of("기타");
8179

@@ -147,7 +145,6 @@ private static void demonstrateUserOperations(UserService userService, List<User
147145
readUser(userService, users);
148146
updateUser(userService, users);
149147
deleteUser(userService, users);
150-
groupingUser(userService, users);
151148

152149
}
153150

@@ -202,23 +199,12 @@ private static void deleteUser(UserService userService, List<User> users){
202199
System.out.println();
203200
}
204201

205-
private static void groupingUser(UserService userService, List<User> users){
206-
System.out.println("------------------------- GroupingUser -------------------------");
207-
//성별 그룹화
208-
System.out.println("\n성별 그룹화");
209-
userService.groupByGender().forEach((gender, list) -> {
210-
System.out.println("[" + gender + "]\n" + list);
211-
});
212-
}
213-
214-
215202
private static void demonstrateChannelOperations(ChannelService channelService, List<Channel> channels, List<User> users) {
216203
System.out.println("\n########################### Channel ############################");
217204

218205
readChannel(channelService,channels,users);
219206
updateChannel(channelService,channels,users);
220207
deleteChannel(channelService,channels,users);
221-
groupingChannel(channelService, channels, users);
222208
}
223209

224210
private static void readChannel(ChannelService channelService, List<Channel> channels, List<User> users){
@@ -317,22 +303,6 @@ private static void deleteChannel(ChannelService channelService, List<Channel> c
317303
channelService.readAll().forEach(System.out::println);
318304

319305
}
320-
private static void groupingChannel(ChannelService channelService, List<Channel> channels, List<User> users) {
321-
System.out.println("------------------------- GroupingUser -------------------------");
322-
//채널별 카테고리
323-
System.out.print("\n채널별 카테고리 목록:\n");
324-
channelService.groupByChannel().forEach((channelName, list) -> {
325-
System.out.println("[" + channelName + "]\n" + list);
326-
});
327-
328-
//채널별 유저 수
329-
System.out.println("\n채널별 유저 수:");
330-
for (Channel channel : channels) {
331-
int memberCount = channelService.members(channel.getId()).size();
332-
System.out.println("[" + channel.getChannelName() + "] 채널 유저 수: " + memberCount + "명");
333-
}
334-
}
335-
336306

337307
private static void demonstrateMessageOperations(MessageService messageService) {
338308
System.out.println("\n########################### Message ###########################");
Binary file not shown.

src/main/java/com/sprint/mission/discodeit/entity/Channel.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.sprint.mission.discodeit.entity;
22

3+
import java.io.Serializable;
34
import java.util.*;
45
import java.util.stream.Collectors;
56

6-
public class Channel {
7+
public class Channel implements Serializable {
8+
private static final long serialVersionUID = 1L;
9+
710
private UUID id;
811
private String channelName;
912
private User keyUser;
@@ -32,13 +35,15 @@ public UUID getId() {
3235
public String getChannelName() {
3336
return channelName;
3437
}
38+
3539
public void setChannelName(String channelName) {
3640
this.channelName = channelName;
3741
}
3842

3943
public List<String> getCategory() {
4044
return categories;
4145
}
46+
4247
public void setCategory(List<String> categories) {
4348
this.categories = categories;
4449
}
@@ -53,13 +58,15 @@ public void setMembers(Set<User> members) {
5358
public long getCreatedAt() {
5459
return createdAt;
5560
}
61+
5662
public void setCreatedAt(long createdAt) {
5763
this.createdAt = createdAt;
5864
}
5965

6066
public long getUpdatedAt() {
6167
return updatedAt;
6268
}
69+
6370
public void setUpdatedAt(long updatedAt) {
6471
this.updatedAt = updatedAt;
6572
}
@@ -80,21 +87,46 @@ public void update(Channel updateChannelData) {
8087
this.updatedAt = System.currentTimeMillis();
8188
}
8289

90+
//채널 멤버가 아닌 유저가 메시지 생성시
8391
public void validateMembership(User sender) {
84-
//채널 멤버가 아닌 유저가 메시지 생성시
8592
if (!members.contains(sender)) {
8693
throw new IllegalArgumentException(
8794
" ---" + sender.getName() + "(은/는) [" + channelName + "]채널 멤버가 아닙니다.");
8895
}
8996
}
90-
public void validateCategory(String category) {
91-
//채널에 없는 카테고리에 메시지 생성시
97+
98+
//카테고리 중복 확인
99+
public void validateUniqueCategory() {
100+
Set<String> categorySet = new HashSet<>(this.categories);
101+
if (categorySet.size() != this.categories.size()) {
102+
throw new IllegalArgumentException(" --- 중복된 카테고리가 포함되어 있습니다.");
103+
}
104+
}
105+
106+
//채널에 없는 카테고리에 메시지 생성시
107+
public void validateCategory(String category){
92108
if (!categories.contains(category)) {
93109
throw new IllegalArgumentException(
94110
" ---"+ category + "(은/는) [" +channelName + "]채널에 존재 하지 않는 카테고리입니다.");
95111
}
96112
}
97113

114+
public void addKeyUserToMembers() {
115+
this.members.add(this.keyUser);
116+
}
117+
118+
@Override
119+
public int hashCode() {
120+
return id.hashCode();
121+
}
122+
123+
@Override
124+
public boolean equals(Object obj) {
125+
if (this == obj) return true;
126+
if (!(obj instanceof Channel channel)) return false;
127+
return id.equals(channel.id);
128+
}
129+
98130
public String toString() {
99131
return "Channel{" +
100132
"ChannelName= '" + channelName + '\'' +

src/main/java/com/sprint/mission/discodeit/entity/Message.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.sprint.mission.discodeit.entity;
22

3+
import java.io.Serializable;
34
import java.util.List;
45
import java.util.Set;
56
import java.util.UUID;
67

7-
public class Message {
8+
public class Message implements Serializable {
9+
private static final long serialVersionUID = 1L;
10+
811
private UUID id;
912
private User sender; //보낸사람
1013
private Channel channel;
@@ -79,6 +82,18 @@ public void validateContent() {
7982
}
8083
}
8184

85+
@Override
86+
public int hashCode() {
87+
return id.hashCode();
88+
}
89+
90+
@Override
91+
public boolean equals(Object obj) {
92+
if (this == obj) return true;
93+
if (!(obj instanceof Message message)) return false;
94+
return id.equals(message.id);
95+
}
96+
8297
public String toString() {
8398
return "Message{" +
8499
"id= '" + id + '\'' +

src/main/java/com/sprint/mission/discodeit/entity/User.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package com.sprint.mission.discodeit.entity;
22

3+
import java.io.Serializable;
34
import java.util.ArrayList;
45
import java.util.HashSet;
56
import java.util.UUID;
67

7-
public class User {
8+
public class User implements Serializable {
9+
private static final long serialVersionUID = 1L;
10+
811
private UUID id;
912
private String gender;
1013
private String name;
1114
private String email;
1215
private String phone;
13-
private String password;
16+
private transient String password;
1417
private long createdAt;
1518
private long updatedAt;
1619

@@ -32,48 +35,71 @@ public UUID getId() {
3235
public String getName() {
3336
return name;
3437
}
38+
3539
public void setName(String name) {
3640
this.name = name;
3741
}
3842

39-
public String getGender() {return gender;}
40-
public void setGender(String gender) {this.gender = gender;}
43+
public String getGender() {
44+
return gender;
45+
}
46+
47+
public void setGender(String gender) {
48+
this.gender = gender;
49+
}
4150

4251
public String getEmail() {
4352
return email;
4453
}
54+
4555
public void setEmail(String email) {
4656
this.email = email;
4757
}
4858

4959
public String getPhone() {
5060
return phone;
5161
}
62+
5263
public void setPhone(String phone) {
5364
this.phone = phone;
5465
}
5566

5667
public String getPassword() {
5768
return password;
5869
}
70+
5971
public void setPassword(String password) {
6072
this.password = password;
6173
}
6274

6375
public long getCreatedAt() {
6476
return createdAt;
6577
}
78+
6679
public void setCreatedAt(long createdAt) {
6780
this.createdAt = createdAt;
6881
}
6982

7083
public long getUpdatedAt() {
7184
return updatedAt;
7285
}
86+
7387
public void setUpdatedAt(long updatedAt) {
7488
this.updatedAt = updatedAt;
7589
}
7690

91+
@Override
92+
public int hashCode() {
93+
return id.hashCode();
94+
}
95+
96+
@Override
97+
public boolean equals(Object obj) {
98+
if (this == obj) return true;
99+
if (!(obj instanceof User user)) return false;
100+
return id.equals(user.id);
101+
}
102+
77103
public void update(User updateUserData) {
78104
this.name = updateUserData.name;
79105
this.gender = updateUserData.gender;

0 commit comments

Comments
 (0)