ソースを参照

Udated Message Class

JaseG256 6 年 前
コミット
36c94a8069

+ 24
- 23
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Message.java ファイルの表示

@@ -1,33 +1,34 @@
1 1
 package ZipTeamOrange.model;
2 2
 
3
+import ZipTeamOrange.model.Audit.DateAudit;
4
+import ZipTeamOrange.model.Audit.UserDateAudit;
5
+
3 6
 import javax.persistence.*;
4 7
 
5 8
 @Entity
6
-public class Message {
9
+public class Message extends UserDateAudit {
7 10
 
8 11
     @Id
9 12
     @GeneratedValue(strategy = GenerationType.IDENTITY)
10 13
     private long id;
11 14
 
12
-    String message;
15
+    String text;
13 16
 
14
-    @ManyToOne
15
-    @JoinColumn(name="user_id")
16
-    User user;
17
+//    @ManyToOne
18
+//    @JoinColumn(name="user_id")
19
+//    User user;
17 20
 
18
-    @ManyToOne
19
-    @JoinColumn(name = "chat_id")
21
+    @ManyToOne(fetch = FetchType.LAZY, optional = false)
22
+    @JoinColumn(name = "chat_id", nullable = false)
20 23
     private Chat chat;
21 24
 
25
+    public Message() { }
22 26
 
23
-    public Message(String message) {
24
-        this.message = message;
27
+    public Message(String text) {
28
+        this.text = text;
25 29
         //this.user = user;
26 30
     }
27 31
 
28
-
29
-    public Message(){}
30
-
31 32
     public long getId() {
32 33
         return id;
33 34
     }
@@ -36,19 +37,19 @@ public class Message {
36 37
         this.id = id;
37 38
     }
38 39
 
39
-    public String getMessage() {
40
-        return message;
40
+    public String getText() {
41
+        return text;
41 42
     }
42 43
 
43
-    public void setMessage(String message) {
44
-        this.message = message;
44
+    public void setText(String text) {
45
+        this.text = text;
45 46
     }
46 47
 
47
-    public User getUser() {
48
-        return user;
49
-    }
50
-
51
-    public void setUser(User user) {
52
-        this.user = user;
53
-    }
48
+//    public User getUser() {
49
+//        return user;
50
+//    }
51
+//
52
+//    public void setUser(User user) {
53
+//        this.user = user;
54
+//    }
54 55
 }

+ 25
- 7
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/ChatRepository.java ファイルの表示

@@ -1,7 +1,25 @@
1
-//package ZipTeamOrange.repository;
2
-//
3
-//import ZipTeamOrange.model.Chat;
4
-//import org.springframework.data.jpa.repository.JpaRepository;
5
-//
6
-//public interface ChatRepository extends JpaRepository<Chat, Long> {
7
-//}
1
+package ZipTeamOrange.repository;
2
+
3
+import ZipTeamOrange.model.Chat;
4
+import org.springframework.data.domain.Page;
5
+import org.springframework.data.domain.Pageable;
6
+import org.springframework.data.domain.Sort;
7
+import org.springframework.data.jpa.repository.JpaRepository;
8
+
9
+import java.util.List;
10
+import java.util.Optional;
11
+
12
+public interface ChatRepository extends JpaRepository<Chat, Long> {
13
+
14
+    Optional<Chat> findById(Long chatId);
15
+
16
+    Page<Chat> findByCreatedBy(Long userId, Pageable pageable);
17
+
18
+    long countByCreatedBy(Long userId);
19
+
20
+    List<Chat> findByIdIn(List<Long> chatIds);
21
+
22
+    List<Chat> findByIdIn(List<Long> chatIds, Sort sort);
23
+
24
+}
25
+

+ 30
- 9
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/MessageRepository.java ファイルの表示

@@ -1,9 +1,30 @@
1
-//package ZipTeamOrange.repository;
2
-//
3
-//import ZipTeamOrange.model.Message;
4
-//import org.springframework.data.jpa.repository.JpaRepository;
5
-//
6
-//public interface MessageRepository extends JpaRepository<Message, Long> {
7
-//
8
-//
9
-//}
1
+package ZipTeamOrange.repository;
2
+
3
+import ZipTeamOrange.model.Chat;
4
+import ZipTeamOrange.model.Message;
5
+import org.springframework.data.domain.Page;
6
+import org.springframework.data.domain.Pageable;
7
+import org.springframework.data.domain.Sort;
8
+import org.springframework.data.jpa.repository.JpaRepository;
9
+import org.springframework.data.jpa.repository.Query;
10
+import org.springframework.data.repository.query.Param;
11
+
12
+import java.util.List;
13
+import java.util.Optional;
14
+
15
+public interface MessageRepository extends JpaRepository<Message, Long> {
16
+
17
+    Optional<Message> findById(Long messageId);
18
+
19
+    Page<Message> findByCreatedBy(Long userId, Pageable pageable);
20
+
21
+    long countByCreatedBy(Long userId);
22
+
23
+//    @Query("SELECT COUNT(m.id) from Message v where v.user.id = :userId")
24
+//    long countByUserId(@Param("userId") Long userId);
25
+
26
+    List<Message> findByIdIn(List<Long> messageIds);
27
+
28
+    List<Message> findByIdIn(List<Long> messageIds, Sort sort);
29
+
30
+}

+ 46
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/ChatRequest.java ファイルの表示

@@ -0,0 +1,46 @@
1
+package ZipTeamOrange.payload;
2
+
3
+import javax.validation.Valid;
4
+import javax.validation.constraints.NotBlank;
5
+import javax.validation.constraints.NotNull;
6
+import javax.validation.constraints.Size;
7
+import java.util.List;
8
+
9
+public class ChatRequest {
10
+    @NotBlank
11
+    @Size(max = 140)
12
+    private String topic;
13
+
14
+    @NotNull
15
+    @Size(min = 2, max = 6)
16
+    @Valid
17
+    private List<MessageRequest> choices;
18
+
19
+//    @NotNull
20
+//    @Valid
21
+//    private PollLength pollLength;
22
+
23
+    public String getTopic() {
24
+        return topic;
25
+    }
26
+
27
+    public void setTopic(String topic) {
28
+        this.topic = topic;
29
+    }
30
+
31
+    public List<MessageRequest> getChoices() {
32
+        return choices;
33
+    }
34
+
35
+    public void setChoices(List<MessageRequest> choices) {
36
+        this.choices = choices;
37
+    }
38
+
39
+//    public PollLength getPollLength() {
40
+//        return pollLength;
41
+//    }
42
+//
43
+//    public void setPollLength(PollLength pollLength) {
44
+//        this.pollLength = pollLength;
45
+//    }
46
+}

+ 18
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/MessageRequest.java ファイルの表示

@@ -0,0 +1,18 @@
1
+package ZipTeamOrange.payload;
2
+
3
+import javax.validation.constraints.NotBlank;
4
+import javax.validation.constraints.Size;
5
+
6
+public class MessageRequest {
7
+    @NotBlank
8
+    @Size(max = 40)
9
+    private String text;
10
+
11
+    public String getText() {
12
+        return text;
13
+    }
14
+
15
+    public void setText(String text) {
16
+        this.text = text;
17
+    }
18
+}

+ 17
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/UserIdentityAvailability.java ファイルの表示

@@ -0,0 +1,17 @@
1
+package ZipTeamOrange.payload;
2
+
3
+public class UserIdentityAvailability {
4
+    private Boolean available;
5
+
6
+    public UserIdentityAvailability(Boolean available) {
7
+        this.available = available;
8
+    }
9
+
10
+    public Boolean getAvailable() {
11
+        return available;
12
+    }
13
+
14
+    public void setAvailable(Boolean available) {
15
+        this.available = available;
16
+    }
17
+}

+ 28
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/UserSummary.java ファイルの表示

@@ -0,0 +1,28 @@
1
+package ZipTeamOrange.payload;
2
+
3
+public class UserSummary {
4
+    private Long id;
5
+    private String username;
6
+
7
+    public UserSummary(Long id, String username, String name) {
8
+        this.id = id;
9
+        this.username = username;
10
+    }
11
+
12
+    public Long getId() {
13
+        return id;
14
+    }
15
+
16
+    public void setId(Long id) {
17
+        this.id = id;
18
+    }
19
+
20
+    public String getUsername() {
21
+        return username;
22
+    }
23
+
24
+    public void setUsername(String username) {
25
+        this.username = username;
26
+    }
27
+
28
+}

+ 2
- 1
ZipTeamOrange-server/src/main/resources/data.sql ファイルの表示

@@ -1,2 +1,3 @@
1 1
 insert into roles(name) values ('ROLE_ADMIN');
2
-insert into roles(name) values ('ROLE_USER');
2
+insert into roles(name) values ('ROLE_USER');
3
+--select count (m.id) from Messages where m.userId = userId;