Skip to content

Commit

Permalink
merge: 데이터 모델 리팩토링 (#860)
Browse files Browse the repository at this point in the history
Related to: #719
  • Loading branch information
ki960213 authored Dec 1, 2023
1 parent 92deec7 commit b3efcb0
Show file tree
Hide file tree
Showing 40 changed files with 238 additions and 360 deletions.
2 changes: 1 addition & 1 deletion android/2023-emmsale/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".presentation.ui.myPostList.MyPostActivity" />
<activity android:name=".presentation.ui.myRecruitmentList.MyRecruitmentActivity" />
<activity android:name=".presentation.ui.notificationTagConfig.NotificationTagConfigActivity" />
<activity android:name=".presentation.ui.myCommentList.MyCommentsActivity" />
<activity android:name=".presentation.ui.blockMemberList.MemberBlockActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.emmsale.data.mapper
import com.emmsale.data.apiModel.response.CommentFamilyApiModel
import com.emmsale.data.apiModel.response.CommentResponse
import com.emmsale.data.model.Comment
import com.emmsale.data.model.Feed
import com.emmsale.data.model.Member
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

Expand All @@ -11,16 +13,20 @@ fun List<CommentFamilyApiModel>.toData(): List<Comment> = map(CommentFamilyApiMo

fun CommentFamilyApiModel.toData() = Comment(
id = parentComment.commentId,
feedId = parentComment.feedId,
feedTitle = parentComment.feedTitle,
authorId = parentComment.memberId,
authorName = parentComment.memberName,
authorImageUrl = parentComment.memberImageUrl,
parentId = parentComment.parentId,
feed = Feed(
id = parentComment.feedId,
title = parentComment.feedTitle,
),
writer = Member(
id = parentComment.memberId,
name = parentComment.memberName,
profileImageUrl = parentComment.memberImageUrl,
),
parentCommentId = parentComment.parentId,
content = parentComment.content,
createdAt = LocalDateTime.parse(parentComment.createdAt, dateTimeFormatter),
updatedAt = LocalDateTime.parse(parentComment.updatedAt, dateTimeFormatter),
deleted = parentComment.deleted,
isDeleted = parentComment.deleted,
childComments = childComments.toData(),
)

Expand All @@ -29,16 +35,20 @@ fun List<CommentResponse>.toData(): List<Comment> = map(CommentResponse::toData)

fun CommentResponse.toData() = Comment(
id = commentId,
feedId = feedId,
feedTitle = feedTitle,
authorId = memberId,
authorName = memberName,
authorImageUrl = memberImageUrl,
parentId = parentId,
feed = Feed(
id = feedId,
title = feedTitle,
),
writer = Member(
id = memberId,
name = memberName,
profileImageUrl = memberImageUrl,
),
parentCommentId = parentId,
content = content,
createdAt = LocalDateTime.parse(createdAt, dateTimeFormatter),
updatedAt = LocalDateTime.parse(updatedAt, dateTimeFormatter),
deleted = deleted,
isDeleted = deleted,
childComments = listOf(),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.MyPostResponse
import com.emmsale.data.model.MyPost
import com.emmsale.data.model.Event
import com.emmsale.data.model.Member
import com.emmsale.data.model.Recruitment
import java.time.LocalDate
import java.time.format.DateTimeFormatter

fun List<MyPostResponse>.toData(): List<MyPost> = map { it.toData() }
fun MyPostResponse.toData(): MyPost {
return MyPost(
postId = postId,
eventId = eventId,
eventName = eventName,
content = content,
updatedAt = updatedAt.toLocalDate(),
)
}
fun List<MyPostResponse>.toData(): List<Recruitment> = map { it.toData() }
fun MyPostResponse.toData() = Recruitment(
id = postId,
writer = Member(),
event = Event(id = eventId, name = eventName),
content = content,
updatedDate = updatedAt.toLocalDate(),
)

private fun String.toLocalDate(): LocalDate {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.emmsale.data.apiModel.response.CommentTypeNotificationResponse
import com.emmsale.data.apiModel.response.EventTypeNotificationResponse
import com.emmsale.data.apiModel.response.NotificationResponse
import com.emmsale.data.apiModel.response.NotificationResponse.NotificationType
import com.emmsale.data.apiModel.response.RecruitmentNotificationResponse
import com.emmsale.data.model.RecruitmentNotification
import com.emmsale.data.model.updatedNotification.ChildCommentNotification
import com.emmsale.data.model.updatedNotification.InterestEventNotification
import com.emmsale.data.model.updatedNotification.UpdatedNotification
Expand Down Expand Up @@ -55,18 +53,3 @@ private fun String.toLocalDateTime(): LocalDateTime {
val formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd:HH:mm:ss")
return LocalDateTime.parse(this, formatter)
}

fun RecruitmentNotificationResponse.toData(): RecruitmentNotification = RecruitmentNotification(
id = id,
senderUid = senderUid,
receiverUid = receiverUid,
message = message,
eventId = eventId,
status = status.toRecruitmentStatus(),
isRead = isRead,
notificationDate = createdAt.toLocalDateTime(),
)

@JvmName("RecruitmentNotificationResponse")
fun List<RecruitmentNotificationResponse>.toData(): List<RecruitmentNotification> =
map { it.toData() }

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import java.time.LocalDateTime

data class Comment(
val id: Long,
val feedId: Long,
val feedTitle: String,
val authorId: Long,
val authorName: String,
val authorImageUrl: String,
val parentId: Long?,
val content: String,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime,
val deleted: Boolean,
val childComments: List<Comment>,
val feed: Feed = Feed(),
val writer: Member = Member(),
val parentCommentId: Long? = null,
val content: String = "",
val createdAt: LocalDateTime = LocalDateTime.MAX,
val updatedAt: LocalDateTime = LocalDateTime.MAX,
val isDeleted: Boolean = false,
val childComments: List<Comment> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.emmsale.data.model
import java.time.LocalDateTime

data class Feed(
val id: Long,
val eventId: Long,
val title: String,
val content: String,
val writer: Member,
val imageUrls: List<String>,
val commentCount: Int,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime,
val id: Long = -1,
val eventId: Long = -1,
val title: String = "",
val content: String = "",
val writer: Member = Member(),
val imageUrls: List<String> = emptyList(),
val commentCount: Int = 0,
val createdAt: LocalDateTime = LocalDateTime.MAX,
val updatedAt: LocalDateTime = LocalDateTime.MAX,
) {
val titleImageUrl = imageUrls.firstOrNull()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ data class Recruitment(
val id: Long,
val writer: Member,
val event: Event,
val content: String?,
val content: String,
val updatedDate: LocalDate,
)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package com.emmsale.data.repository.concretes
import com.emmsale.data.apiModel.request.NotificationListDeleteRequest
import com.emmsale.data.apiModel.request.RecruitmentNotificationReportCreateRequest
import com.emmsale.data.apiModel.response.NotificationResponse
import com.emmsale.data.apiModel.response.RecruitmentNotificationResponse
import com.emmsale.data.common.retrofit.callAdapter.ApiResponse
import com.emmsale.data.mapper.toData
import com.emmsale.data.mapper.toRequestModel
import com.emmsale.data.model.RecruitmentNotification
import com.emmsale.data.model.RecruitmentStatus
import com.emmsale.data.model.updatedNotification.UpdatedNotification
import com.emmsale.data.repository.interfaces.NotificationRepository
import com.emmsale.data.service.NotificationService
Expand All @@ -21,23 +17,6 @@ class DefaultNotificationRepository @Inject constructor(
@IoDispatcher private val dispatcher: CoroutineDispatcher,
private val notificationService: NotificationService,
) : NotificationRepository {
override suspend fun getRecruitmentNotifications(
memberId: Long,
): ApiResponse<List<RecruitmentNotification>> = withContext(dispatcher) {
notificationService
.getRecruitmentNotifications(memberId)
.map(List<RecruitmentNotificationResponse>::toData)
}

override suspend fun updateRecruitmentStatus(
notificationId: Long,
recruitmentStatus: RecruitmentStatus,
): ApiResponse<Unit> = withContext(dispatcher) {
notificationService.updateRecruitmentStatus(
notificationId = notificationId,
newStatus = recruitmentStatus.toRequestModel(),
)
}

override suspend fun updateNotificationReadStatus(
notificationId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class DefaultRecruitmentRepository @Inject constructor(
.getRecruitment(eventId, recruitmentId)
.map(RecruitmentResponse::toData)

override suspend fun getMemberRecruitments(
memberId: Long,
): ApiResponse<List<Recruitment>> = recruitmentService
.getMemberRecruitments(memberId)
.map { it.toData() }

override suspend fun postRecruitment(
eventId: Long,
content: String,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package com.emmsale.data.repository.interfaces

import com.emmsale.data.common.retrofit.callAdapter.ApiResponse
import com.emmsale.data.model.RecruitmentNotification
import com.emmsale.data.model.RecruitmentStatus
import com.emmsale.data.model.updatedNotification.UpdatedNotification

interface NotificationRepository {

suspend fun getRecruitmentNotifications(memberId: Long): ApiResponse<List<RecruitmentNotification>>

suspend fun updateRecruitmentStatus(
notificationId: Long,
recruitmentStatus: RecruitmentStatus,
): ApiResponse<Unit>

suspend fun updateNotificationReadStatus(notificationId: Long): ApiResponse<Unit>

suspend fun getUpdatedNotifications(memberId: Long): ApiResponse<List<UpdatedNotification>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface RecruitmentRepository {
eventId: Long,
): ApiResponse<List<Recruitment>>

suspend fun getMemberRecruitments(memberId: Long): ApiResponse<List<Recruitment>>

suspend fun getEventRecruitment(
eventId: Long,
recruitmentId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.emmsale.data.service
import com.emmsale.data.apiModel.request.RecruitmentCreateRequest
import com.emmsale.data.apiModel.request.RecruitmentDeleteRequest
import com.emmsale.data.apiModel.request.RecruitmentReportCreateRequest
import com.emmsale.data.apiModel.response.MyPostResponse
import com.emmsale.data.apiModel.response.RecruitmentReportResponse
import com.emmsale.data.apiModel.response.RecruitmentResponse
import com.emmsale.data.common.retrofit.callAdapter.ApiResponse
Expand All @@ -27,6 +28,11 @@ interface RecruitmentService {
@Path("recruitment-post-id") recruitmentId: Long,
): ApiResponse<RecruitmentResponse>

@GET("/events/recruitment-posts")
suspend fun getMemberRecruitments(
@Query("member-id") memberId: Long,
): ApiResponse<List<MyPostResponse>>

@POST("/events/{eventId}/recruitment-posts")
suspend fun postRecruitment(
@Path("eventId") eventId: Long,
Expand Down
Loading

0 comments on commit b3efcb0

Please sign in to comment.