Skip to content

Commit

Permalink
feat: StoryApi 구현 #52
Browse files Browse the repository at this point in the history
  • Loading branch information
bamin0422 committed Jul 1, 2024
1 parent b60111d commit e4e9799
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 13 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/com/owori/android/core/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.owori.android.data.api.keyword.KeywordApi
import com.owori.android.data.api.member.MemberApi
import com.owori.android.data.api.saying.SayingApi
import com.owori.android.data.api.schedule.ScheduleApi
import com.owori.android.data.api.story.StoryApi
import com.owori.android.module.HttpRequestInterceptor
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -106,6 +107,12 @@ object NetworkModule {
return retrofit.buildService()
}

@Provides
@Singleton
fun provideStoryApi(retrofit: Retrofit): StoryApi {
return retrofit.buildService()
}

private inline fun <reified T> Retrofit.buildService(): T {
return this.create(T::class.java)
}
Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/com/owori/android/data/api/story/StoryApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.owori.android.data.api.story

import com.owori.android.data.model.story.StoryItem
import com.owori.android.data.model.story.StoryListPageResponse
import com.owori.android.data.model.story.StoryResponse
import com.owori.android.module.DataResult
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface StoryApi {

// 이야기 등록
@POST("/stories")
fun postStory(@Body data: StoryItem): DataResult<StoryResponse>

// 이야기 수정
@POST("/stories/update")
fun editStory(@Body data: StoryItem): DataResult<StoryResponse>

// 이야기 삭제
@DELETE("/stories/{storyId}")
fun deleteStory(@Path(value = "storyId") storyId: String): DataResult<Any>

// 이야기 전체 조회
@GET("/stories")
fun getAllStories(@Query("sort") sortType: String, @Query("page") page: Int, @Query("size") size: Int): DataResult<StoryListPageResponse>

// 이야기 상세 조회
@GET("/stories/{storyId}")
fun getDetailStory(@Path(value = "storyId") storyId: String): DataResult<StoryItem>

// 이야기 검색
@GET("/stories/search")
fun searchStory(@Query("keyword") keyword: String): DataResult<List<StoryItem>>

// 유저가 작성한 이야기 조회
@GET("/stories/member")
fun getStoryWithMember(@Query("sort") sortType: String, @Query("page") page: Int, @Query("size") size: Int): DataResult<StoryListPageResponse>

// 유저가 좋아한 이야기 조회
@GET("/stories/heart")
fun getLikedStoryWithMember(@Query("sort") sortType: String, @Query("page") page: Int, @Query("size") size: Int): DataResult<StoryListPageResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ data class SchedulePostRequest(
@SerializedName("end_date")
val endDate: String?,
@SerializedName("schedule_type")
val scheduleType: ScheduleType,
val nickname: String,
val color: String,
val scheduleType: ScheduleType?,
val nickname: String?,
val color: String?,
@SerializedName("dday_option")
val dDayOption: Boolean,
val dDayOption: Boolean?,
@SerializedName("alarm_options")
val alarmOptions: List<String>,
val alarmOptions: List<String>?,
@SerializedName("is_mine")
val isMine: Boolean,
val isMine: Boolean?,
)

data class ScheduleItem(
@SerializedName("schedule_id")
val scheduleId: String,
val scheduleId: String?,
val title: String,
val content: String,
@SerializedName("start_date")
val startDate: String?,
@SerializedName("end_date")
val endDate: String?,
@SerializedName("schedule_type")
val scheduleType: ScheduleType,
val nickname: String,
val color: String,
val scheduleType: ScheduleType?,
val nickname: String?,
val color: String?,
@SerializedName("dday_option")
val dDayOption: Boolean,
val dDayOption: Boolean?,
@SerializedName("alarm_options")
val alarmOptions: List<String>,
val alarmOptions: List<String>?,
@SerializedName("is_mine")
val isMine: Boolean,
val isMine: Boolean?,
)

enum class ScheduleType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.owori.android.data.model.story

import com.google.gson.annotations.SerializedName

data class StoryItem(
@SerializedName("story_id")
val storyId: String?,
@SerializedName("start_date")
val startDate: String?,
@SerializedName("end_date")
val endDate: String?,
val title: String,
val content: String,
@SerializedName("story_images")
val storyImages: List<String>?,
val writer: String?,
val thumbnail: String?,
val isMultipleImages: Boolean?,
@SerializedName("heart_count")
val heartCount: Int?,
@SerializedName("comment_count")
val commentCount: Int?,
val comments: List<CommentItem>?,
)

data class CommentItem(
@SerializedName("parent_comment_id")
val parentCommentId: String,
@SerializedName("comment_id")
val commentId: String,
val comment: String,
val writer: String,
@SerializedName("time_before_writing")
val timeBeforeWriting: String,
@SerializedName("delete_comment_check")
val deleteCommentCheck: Boolean,
)

enum class SortType(val value: String) {
CREATED_AT("created_at"),
START_DATE("start_date")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.owori.android.data.model.story

import com.google.gson.annotations.SerializedName

data class StoryResponse(
@SerializedName("story_id")
val storyId: String?,
)

data class StoryListPageResponse(
val stories: List<StoryItem>?,
@SerializedName("next_page")
val nextPage: Int,
@SerializedName("last_page")
val lastPage: Int,
)

0 comments on commit e4e9799

Please sign in to comment.