-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : add chat room application service
- Loading branch information
Showing
12 changed files
with
476 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,74 @@ | ||
package chat | ||
|
||
import "time" | ||
import ( | ||
"database/sql" | ||
"time" | ||
) | ||
|
||
type ( | ||
RoomType string | ||
MessageType string | ||
) | ||
|
||
func (t RoomType) IsValid() bool { | ||
switch t { | ||
case EVENT_ROOM_TYPE: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
const ( | ||
RoomTypePersonal = "personal" | ||
RoomTypeGathering = "gathering" | ||
EVENT_ROOM_TYPE = "event" | ||
) | ||
|
||
const ( | ||
MessageTypeNormal = "normal" | ||
MessageTypePromise = "promise" | ||
EVENT_MESSAGE = "event" | ||
) | ||
|
||
type Room struct { | ||
ID int64 `field:"id" json:"id"` | ||
Name string `field:"name" json:"name"` | ||
RoomType RoomType `field:"RoomType" json:"RoomType"` | ||
CreatedAt time.Time `field:"createdAt" json:"createdAt"` | ||
UpdatedAt time.Time `field:"updatedAt" json:"updatedAt"` | ||
DeletedAt time.Time `field:"deletedAt" json:"deletedAt"` | ||
type RoomSimpleInfo struct { | ||
ID string `field:"id" json:"id"` | ||
RoomName string `field:"roomName" json:"roomName"` | ||
RoomType string `field:"roomType" json:"roomType"` | ||
JoinUsers *[]JoinUsersSimpleInfo `field:"joinUsers" json:"joinUsers"` | ||
CreatedAt time.Time `field:"createdAt" json:"createdAt"` | ||
UpdatedAt time.Time `field:"updatedAt" json:"updatedAt"` | ||
} | ||
|
||
type Message struct { | ||
ID int64 `field:"id" json:"id"` | ||
UserID int64 `field:"userID" json:"userID"` | ||
RoomID int64 `field:"roomID" json:"roomID"` | ||
MessageType MessageType `field:"messageType" json:"messageType"` | ||
Content string `field:"content" json:"content"` | ||
CreatedAt time.Time `field:"createdAt" json:"createdAt"` | ||
UpdatedAt time.Time `field:"updatedAt" json:"updatedAt"` | ||
DeletedAt time.Time `field:"deletedAt" json:"deletedAt"` | ||
type JoinUsersSimpleInfo struct { | ||
ID string `field:"id" json:"userId"` | ||
UserNickname string `field:"nickname" json:"userNickname"` | ||
UserProfileImage sql.NullString `field:"profileImage" json:"profileImageId"` | ||
} | ||
|
||
type JoinRoom struct { | ||
UserID string | ||
RoomID string | ||
JoinedAt time.Time | ||
} | ||
|
||
type UserChatRoom struct { | ||
ID int64 `field:"id" json:"id"` | ||
UserID int64 `field:"userID" json:"userID"` | ||
RoomID int64 `field:"roomID" json:"roomID"` | ||
JoinedAt time.Time `field:"joinedAt" json:"joinedAt"` | ||
LeftAt time.Time `field:"leftAt" json:"leftAt"` | ||
// 조회 시 Room 정보를 반환하는 View | ||
type JoinRoomsView struct { | ||
Items []RoomSimpleInfo `field:"items" json:"items"` | ||
} | ||
|
||
type UserChatRoomList []*UserChatRoom | ||
type UserChatRoomMessageView struct { | ||
ID string `field:"id" json:"id"` | ||
MessageType string `field:"messageType" json:"messageType"` | ||
} | ||
|
||
type Message struct { | ||
ID int64 `field:"id" json:"id"` | ||
UserID int64 `field:"userID" json:"userID"` | ||
RoomID int64 `field:"roomID" json:"roomID"` | ||
MessageType string `field:"messageType" json:"messageType"` | ||
Content string `field:"content" json:"content"` | ||
CreatedAt time.Time `field:"createdAt" json:"createdAt"` | ||
} | ||
|
||
type MessageCursorView struct { | ||
HasNext *bool `field:"hasNext" json:"hasNext"` | ||
HasPrev *bool `field:"hasPrev" json:"hasPrev"` | ||
Items []Message `field:"items" json:"items,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
package chat | ||
|
||
// FIXME : 정책상 채팅방 생성시 필요 정보가 있을 경우 추가 해야함 | ||
type CreateRoomRequest struct { | ||
RoomName string `json:"roomName" validate:"required"` | ||
// FIXME : Model 항목을 상속받고 있는데 위계질서에 어긋남 수정 필요 | ||
RoomType RoomType `json:"roomType" validate:"required"` | ||
RoomName string `json:"roomName" validate:"required"` | ||
RoomType string `json:"roomType" validate:"required"` | ||
JoinUserIds *[]int64 `json:"joinUsers"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package chat | ||
|
||
import "errors" | ||
|
||
// Validate to validate CreateRoomRequest | ||
func (r CreateRoomRequest) RoomTypeValidate() error { | ||
// RoomType이 Model에 정의된 값인지 확인 | ||
switch r.RoomType { | ||
case EVENT_ROOM_TYPE: | ||
return nil | ||
default: | ||
return errors.New("invalid room type. please check room type") | ||
} | ||
} |
Oops, something went wrong.