-
Notifications
You must be signed in to change notification settings - Fork 3
[API] 모집중인 모임방 및 모임방 화면 API 연결 #69
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
Changes from all commits
45fa16b
56ab7a9
75fedbb
be112fc
b45b079
f86acc5
3da5d89
67b877c
65284f7
1470a64
828801b
4078c52
ead0598
cc80ac7
c8b900d
927a90f
a0167a9
9307e86
6ef1fb0
5c4f770
a5dc49e
9f6c346
7c5bf8e
574c79c
691ce6d
4f85a0f
da20f63
66ff952
e86901d
b16fbd4
5929c86
029ec80
0a9667c
71c1e52
c22f24a
4dcc361
5ba2364
b50375e
b184d3b
822b41e
31279fd
d81d8c3
4b3f371
35a59a8
1fe4947
31374cb
8b691e2
7bec1f8
f8b087a
c7f1077
8f05f31
41246e7
4f55458
5b0e16b
94ca51c
dc94a55
2a1e8dd
b3e28e8
f179552
0fc0b92
79deb2e
12e9c65
c38559d
4c666d1
91a2b21
3bef4b6
888d7d8
5a5a340
e05e425
347b21a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.texthip.thip.data.manager | ||
|
|
||
| /** | ||
| * 도서 장르를 나타내는 enum class | ||
| */ | ||
| enum class Genre( | ||
| val displayKey: String, | ||
| val apiCategory: String, | ||
| val networkApiCategory: String = apiCategory | ||
| ) { | ||
| LITERATURE("literature", "문학"), | ||
| SCIENCE_IT("science_it", "과학·IT", "과학/IT"), | ||
| SOCIAL_SCIENCE("social_science", "사회과학"), | ||
| HUMANITIES("humanities", "인문학"), | ||
| ART("art", "예술"); | ||
|
|
||
| companion object { | ||
| fun getDefault() = LITERATURE | ||
|
|
||
| fun fromDisplayKey(displayKey: String): Genre? { | ||
| return entries.find { it.displayKey == displayKey } | ||
| } | ||
| } | ||
| } |
|
Member
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. 흠 .. 저는 장르를 enum으로 관리했는데 이방법도 좋아보이네여 .. 어떤 방식으로 통일하는게 좋을까요?
Collaborator
Author
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. 이게 장르를 관리하는 코드긴한데 "과학·IT" -> "과학/IT" 이거 처리하려고 만든 코드인데 겸사겸사 장르까지 관리하려고 헀습니다 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.texthip.thip.data.manager | ||
|
|
||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class GenreManager @Inject constructor() { | ||
|
|
||
| fun getGenres(): List<Genre> { | ||
| return Genre.entries | ||
| } | ||
|
|
||
| fun mapGenreToApiCategory(genre: Genre): String { | ||
| return genre.networkApiCategory | ||
| } | ||
|
|
||
| fun getDefaultGenre(): Genre { | ||
| return Genre.getDefault() | ||
| } | ||
|
|
||
| fun getGenreByDisplayKey(displayKey: String): Genre? { | ||
| return Genre.fromDisplayKey(displayKey) | ||
| } | ||
| } |
|
Member
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. 이건 사용자의 닉네임을 캐싱해두기 위한 코드인가여? 서버에서 닉네임을 보내주는걸로 알고있는데 조금 더 빨리 로딩하기 위해서 만든 코드인가요?
Collaborator
Author
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. 닉네임을 보내주는 API도 있고 안보내주는 API도 있어서 한번 받으면 캐싱해두고 사용하려고 했습니다! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.texthip.thip.data.manager | ||
|
|
||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class UserDataManager @Inject constructor() { | ||
|
|
||
| private var cachedUserName: String? = null | ||
|
|
||
| fun getUserName(): String { | ||
| return cachedUserName ?: "사용자" | ||
| } | ||
|
|
||
| fun cacheUserName(name: String) { | ||
| cachedUserName = name | ||
| } | ||
|
Comment on lines
+15
to
+17
Member
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. 오옹 캐싱 처리도 해주셨네용 👍👍 |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.texthip.thip.data.model.book.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
|
|
||
| @Serializable | ||
| data class BookListResponse( | ||
| @SerialName("bookList") val bookList: List<BookSavedResponse> | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class BookSavedResponse( | ||
| @SerialName("isbn") val isbn: String, | ||
| @SerialName("bookTitle") val bookTitle: String, | ||
| @SerialName("authorName") val authorName: String, | ||
| @SerialName("publisher") val publisher: String, | ||
| @SerialName("imageUrl") val imageUrl: String? | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.texthip.thip.data.model.group.request | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CreateRoomRequest( | ||
| @SerialName("isbn") val isbn: String, | ||
| @SerialName("category") val category: String, | ||
| @SerialName("roomName") val roomName: String, | ||
| @SerialName("description") val description: String, | ||
| @SerialName("progressStartDate") val progressStartDate: String, | ||
| @SerialName("progressEndDate") val progressEndDate: String, | ||
| @SerialName("recruitCount") val recruitCount: Int, | ||
| @SerialName("password") val password: String? = null, | ||
| @SerialName("isPublic") val isPublic: Boolean | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.texthip.thip.data.model.group.request | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class RoomJoinRequest( | ||
| @SerialName("type") val type: String | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.texthip.thip.data.model.group.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CreateRoomResponse( | ||
| @SerialName("roomId") val roomId: Int | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.texthip.thip.data.model.group.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
|
|
||
| @Serializable | ||
| data class JoinedRoomListResponse( | ||
| @SerialName("roomList") val roomList: List<JoinedRoomResponse>, | ||
| @SerialName("nickname") val nickname: String, | ||
| @SerialName("page") val page: Int, | ||
| @SerialName("size") val size: Int, | ||
| @SerialName("last") val last: Boolean, | ||
| @SerialName("first") val first: Boolean | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class JoinedRoomResponse( | ||
| @SerialName("roomId") val roomId: Int, | ||
| @SerialName("bookImageUrl") val bookImageUrl: String?, | ||
| @SerialName("bookTitle") val bookTitle: String, | ||
| @SerialName("memberCount") val memberCount: Int, | ||
| @SerialName("userPercentage") val userPercentage: Int | ||
| ) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.texthip.thip.data.model.group.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class MyRoomListResponse( | ||
| @SerialName("roomList") val roomList: List<MyRoomResponse>, | ||
| @SerialName("nextCursor") val nextCursor: String?, | ||
| @SerialName("isLast") val isLast: Boolean | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class MyRoomResponse( | ||
| @SerialName("roomId") val roomId: Int, | ||
| @SerialName("bookImageUrl") val bookImageUrl: String, | ||
| @SerialName("roomName") val roomName: String, | ||
| @SerialName("recruitCount") val recruitCount: Int, | ||
| @SerialName("memberCount") val memberCount: Int, | ||
| @SerialName("endDate") val endDate: String, | ||
| @SerialName("type") val type: String | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.texthip.thip.data.model.group.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class RoomJoinResponse( | ||
| @SerialName("roomId") val roomId: Int, | ||
| @SerialName("type") val type: String | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.texthip.thip.data.model.group.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
|
|
||
| @Serializable | ||
| data class RoomMainResponse( | ||
| @SerialName("roomId") val roomId: Int, | ||
| @SerialName("bookImageUrl") val bookImageUrl: String?, | ||
| @SerialName("roomName") val roomName: String, | ||
| @SerialName("recruitCount") val recruitCount: Int, | ||
| @SerialName("memberCount") val memberCount: Int, | ||
| @SerialName("deadlineDate") val deadlineDate: String | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class RoomMainList( | ||
| @SerialName("deadlineRoomList") val deadlineRoomList: List<RoomMainResponse> = emptyList(), | ||
| @SerialName("popularRoomList") val popularRoomList: List<RoomMainResponse> = emptyList() | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.texthip.thip.data.model.group.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class RoomRecruitingResponse( | ||
| @SerialName("isHost") val isHost: Boolean, | ||
| @SerialName("isJoining") val isJoining: Boolean, | ||
| @SerialName("roomId") val roomId: Int, | ||
| @SerialName("roomName") val roomName: String, | ||
| @SerialName("roomImageUrl") val roomImageUrl: String?, | ||
| @SerialName("isPublic") val isPublic: Boolean, | ||
| @SerialName("progressStartDate") val progressStartDate: String, | ||
| @SerialName("progressEndDate") val progressEndDate: String, | ||
| @SerialName("recruitEndDate") val recruitEndDate: String, | ||
| @SerialName("category") val category: String, | ||
| @SerialName("roomDescription") val roomDescription: String, | ||
| @SerialName("memberCount") val memberCount: Int, | ||
| @SerialName("recruitCount") val recruitCount: Int, | ||
| @SerialName("isbn") val isbn: String, | ||
| @SerialName("bookImageUrl") val bookImageUrl: String, | ||
| @SerialName("bookTitle") val bookTitle: String, | ||
| @SerialName("authorName") val authorName: String, | ||
| @SerialName("bookDescription") val bookDescription: String, | ||
| @SerialName("publisher") val publisher: String, | ||
| @SerialName("recommendRooms") val recommendRooms: List<RecommendRoomResponse> | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class RecommendRoomResponse( | ||
| @SerialName("roomId") val roomId: Int, | ||
| @SerialName("roomImageUrl") val roomImageUrl: String?, | ||
| @SerialName("roomName") val roomName: String, | ||
| @SerialName("memberCount") val memberCount: Int, | ||
| @SerialName("recruitCount") val recruitCount: Int, | ||
| @SerialName("recruitEndDate") val recruitEndDate: String | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.texthip.thip.data.repository | ||
|
|
||
| import com.texthip.thip.data.model.base.handleBaseResponse | ||
| import com.texthip.thip.data.service.BookService | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class BookRepository @Inject constructor( | ||
| private val bookService: BookService | ||
| ) { | ||
|
|
||
| /** 저장된 책 또는 모임 책 목록 조회 */ | ||
| suspend fun getBooks(type: String) = runCatching { | ||
| bookService.getBooks(type) | ||
| .handleBaseResponse() | ||
| .getOrThrow() | ||
| ?.bookList ?: emptyList() | ||
| } | ||
| } |
|
Member
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. 우왓 .. 코드가 완전 복잡하네요 ..! 제가 평소에 작성하던 repository랑은 다른 감이 있는데 Mapper가 추가돼서 그런걸까요 ..!? 데이터가 없는 경우를 하나하나 생각해서 작업한건가요 ..!? 코드의 전반적인 로직이 궁금합니두
Collaborator
Author
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. 비슷해요 요청하고 BaseResponse처리하고 성공하면 데이터 처리하는건데 Mapper랑 Manager 코드가 들어가서 매핑하는 로직이 추가되서 좀 복잡해 보이는겁니다! 일단 runCatchint으로 수정할게요 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package com.texthip.thip.data.repository | ||
|
|
||
| import com.texthip.thip.data.manager.GenreManager | ||
| import com.texthip.thip.data.manager.UserDataManager | ||
| import com.texthip.thip.data.manager.Genre | ||
| import com.texthip.thip.data.model.base.handleBaseResponse | ||
| import com.texthip.thip.data.model.group.request.CreateRoomRequest | ||
| import com.texthip.thip.data.model.group.request.RoomJoinRequest | ||
| import com.texthip.thip.data.model.group.response.JoinedRoomListResponse | ||
| import com.texthip.thip.data.model.group.response.MyRoomListResponse | ||
| import com.texthip.thip.data.model.group.response.RoomMainList | ||
| import com.texthip.thip.data.model.group.response.RoomRecruitingResponse | ||
| import com.texthip.thip.data.service.GroupService | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class GroupRepository @Inject constructor( | ||
| private val groupService: GroupService, | ||
| private val genreManager: GenreManager, | ||
| private val userDataManager: UserDataManager | ||
| ) { | ||
|
|
||
| /** 장르 목록 조회 */ | ||
| fun getGenres(): Result<List<Genre>> { | ||
| return Result.success(genreManager.getGenres()) | ||
| } | ||
|
|
||
| /** 사용자 이름 조회(캐싱 데이터 사용)*/ | ||
| fun getUserName(): Result<String> { | ||
| return Result.success(userDataManager.getUserName()) | ||
| } | ||
|
|
||
| /** 내가 참여 중인 모임방 목록 조회 */ | ||
| suspend fun getMyJoinedRooms(page: Int): Result<JoinedRoomListResponse?> = runCatching { | ||
| val response = groupService.getJoinedRooms(page) | ||
| .handleBaseResponse() | ||
| .getOrThrow() | ||
|
|
||
| response?.let { joinedRoomsDto -> | ||
| userDataManager.cacheUserName(joinedRoomsDto.nickname) | ||
| } | ||
|
|
||
| response | ||
| } | ||
|
|
||
| /** 카테고리별 모임방 섹션 조회 (마감임박/인기) */ | ||
| suspend fun getRoomSections(genre: Genre? = null): Result<RoomMainList?> = runCatching { | ||
| val selectedGenre = genre ?: genreManager.getDefaultGenre() | ||
| val apiCategory = genreManager.mapGenreToApiCategory(selectedGenre) | ||
|
|
||
| groupService.getRooms(apiCategory) | ||
| .handleBaseResponse() | ||
| .getOrThrow() | ||
| } | ||
|
|
||
| /** 타입별 내 모임방 목록 조회 */ | ||
| suspend fun getMyRoomsByType(type: String?, cursor: String? = null): Result<MyRoomListResponse?> = runCatching { | ||
| groupService.getMyRooms(type, cursor) | ||
| .handleBaseResponse() | ||
| .getOrThrow() | ||
| } | ||
|
|
||
| /** 모집중인 모임방 상세 정보 조회 */ | ||
| suspend fun getRoomRecruiting(roomId: Int): Result<RoomRecruitingResponse> = runCatching { | ||
| groupService.getRoomRecruiting(roomId) | ||
| .handleBaseResponse() | ||
| .getOrThrow()!! | ||
| } | ||
|
Comment on lines
+65
to
+69
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. 널 가능성 방어 코드 필요
🤖 Prompt for AI Agents |
||
|
|
||
| /** 새 모임방 생성 */ | ||
| suspend fun createRoom(request: CreateRoomRequest): Result<Int> = runCatching { | ||
| groupService.createRoom(request) | ||
| .handleBaseResponse() | ||
| .getOrThrow()!! | ||
| .roomId | ||
| } | ||
|
|
||
| /** 모임방 참여 또는 취소 */ | ||
| suspend fun joinOrCancelRoom(roomId: Int, type: String): Result<String> = runCatching { | ||
| val request = RoomJoinRequest(type = type) | ||
| groupService.joinOrCancelRoom(roomId, request) | ||
| .handleBaseResponse() | ||
| .getOrThrow()!! | ||
| .type | ||
| } | ||
| } | ||
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.
ㅎㅎㅋㅋㅎㅎㅋㅎㅋ아놔 저는 이거 RoomsService로 했는데 .. 합쳐야겠네여 ..
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.
오히려 좋을지도... 충돌은 안날거 같네요