Skip to content

Commit f52be0e

Browse files
authored
Merge pull request #29 from GPle-Team/27-PopularityRanking-Function
🔀 :: [#27] 인기순위 기능 구현
2 parents 5d6ceb6 + 3bee39a commit f52be0e

File tree

7 files changed

+303
-110
lines changed

7 files changed

+303
-110
lines changed

Projects/App/Sources/Application/GPleApp.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import SwiftUI
44
struct GPleApp: App {
55
var body: some Scene {
66
WindowGroup {
7-
// RankView(detailViewModel: DetailViewModel(), postViewModel: PostViewModel())
8-
RankView(detailViewModel: DetailViewModel())
7+
RankView(postViewModel: PostViewModel())
8+
//MyPageView(viewModel: MyPageViewModel(),postViewModel: PostViewModel())
99
}
1010
}
1111
}

Projects/App/Sources/Feature/DetailFeature/Sources/DetailView.swift

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -143,46 +143,48 @@ struct DetailView: View {
143143
}
144144
.frame(maxWidth: .infinity, alignment: .leading)
145145
.padding(.top, 8)
146-
}
147-
}
148146

149-
Spacer()
150-
}
151-
.padding(.top, 8)
152-
153-
if graySmileState {
154-
HStack(spacing: 25) {
155-
ForEach(0..<6) { tag in
156-
Button(action: {
157-
Haptic.impact(style: .soft)
158-
postViewModel.setupPostId(postId: postId)
159-
postViewModel.setupEmojiType(emojiType: emojiServerName[tag])
160-
161-
postViewModel.postEmoji { success in
162-
print("\(emojiName[tag]) 성공")
163-
164-
if checkEmojiList[tag] == true {
165-
emojiList[tag] -= 1
166-
checkEmojiList[tag].toggle()
167-
} else {
168-
emojiList[tag] = 1
169-
checkEmojiList[tag].toggle()
147+
if graySmileState {
148+
HStack(spacing: 25) {
149+
ForEach(0..<6) { tag in
150+
Button(action: {
151+
Haptic.impact(style: .soft)
152+
postViewModel.setupPostId(postId: postId)
153+
postViewModel.setupEmojiType(emojiType: emojiServerName[tag])
154+
155+
postViewModel.postEmoji { success in
156+
print("\(emojiName[tag]) 성공")
157+
158+
if checkEmojiList[tag] == true {
159+
emojiList[tag] -= 1
160+
checkEmojiList[tag].toggle()
161+
} else {
162+
emojiList[tag] = 1
163+
checkEmojiList[tag].toggle()
164+
}
165+
}
166+
}) {
167+
Image(emojiName[tag])
168+
}
170169
}
171170
}
172-
}) {
173-
Image(emojiName[tag])
171+
.padding(.horizontal, 16)
172+
.padding(.vertical, 10)
173+
.background(
174+
RoundedRectangle(cornerRadius: 5)
175+
.foregroundStyle(GPleAsset.Color.gray1000.swiftUIColor)
176+
)
177+
.padding(.leading, 20)
178+
.padding(.top, 10)
174179
}
180+
175181
}
176182
}
177-
.padding(.horizontal, 16)
178-
.padding(.vertical, 10)
179-
.background(
180-
RoundedRectangle(cornerRadius: 5)
181-
.foregroundStyle(GPleAsset.Color.gray1000.swiftUIColor)
182-
)
183-
.padding(.leading, 20)
184-
.padding(.top, 490)
183+
184+
185+
Spacer()
185186
}
187+
.padding(.top, 8)
186188
}
187189
}
188190
.navigationBarBackButtonHidden(true)

Projects/App/Sources/Feature/PostCreateFeature/Sources/PostViewModel.swift

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public final class PostViewModel: ObservableObject {
2020
private var postId: Int = 0
2121
private var emojiType: String = ""
2222
@Published public var allUserList: [UserListResponse] = []
23+
@Published public var popularityUserList: [PopularityRankingUserListResponse] = []
2324
@Published var myPostList: [MyPostListResponse] = []
2425
@Published var myReactionPostList: [MyReactionPostListResponse] = []
26+
@Published var popularityPostList: [PopularityResponse] = []
2527
private var imageUploadResponse: ImageUploadResponse?
2628

2729

@@ -104,7 +106,6 @@ public final class PostViewModel: ObservableObject {
104106
}
105107
}
106108

107-
108109
public func myPostList(completion: @escaping (Bool) -> Void) {
109110
authProvider.request(.myPostList(authorization: accessToken)) { result in
110111
switch result {
@@ -130,6 +131,31 @@ public final class PostViewModel: ObservableObject {
130131
}
131132
}
132133

134+
public func popularityPostList(completion: @escaping (Bool) -> Void) {
135+
authProvider.request(.popularityPostList(authorization: accessToken)) { result in
136+
switch result {
137+
case let .success(response):
138+
do {
139+
let decodedResponse = try JSONDecoder().decode([PopularityResponse].self, from: response.data)
140+
self.popularityPostList = decodedResponse
141+
142+
for post in decodedResponse {
143+
print("게시물 ID: \(post.id), 위치: \(post.location)")
144+
print("이미지: \(post.imageUrl)")
145+
}
146+
147+
completion(true)
148+
} catch {
149+
print("JSON 디코딩 실패: \(error)")
150+
completion(false)
151+
}
152+
case let .failure(err):
153+
print("네트워크 요청 실패: \(err)")
154+
completion(false)
155+
}
156+
}
157+
}
158+
133159
public func allUserList(completion: @escaping (Bool) -> Void) {
134160
authProvider.request(.allUserList(authorization: accessToken)) { result in
135161
switch result {
@@ -149,6 +175,33 @@ public final class PostViewModel: ObservableObject {
149175
}
150176
}
151177

178+
public func popularityUserList(completion: @escaping (Bool) -> Void) {
179+
authProvider.request(.popularityUserList(authorization: accessToken)) { result in
180+
switch result {
181+
case let .success(response):
182+
do {
183+
print("성공: 유저 리스트 불러오기")
184+
185+
self.popularityUserList = try JSONDecoder().decode([PopularityRankingUserListResponse].self, from: response.data)
186+
187+
print("불러온 유저 리스트:")
188+
for (index, user) in self.popularityUserList.enumerated() {
189+
print("[\(index)] \(user)")
190+
}
191+
192+
completion(true)
193+
} catch {
194+
print("Failed to decode JSON response: \(error)")
195+
completion(false)
196+
}
197+
case let .failure(err):
198+
print("Network request failed: \(err)")
199+
completion(false)
200+
}
201+
}
202+
}
203+
204+
152205

153206
public func uploadImages(completion: @escaping (Bool) -> Void) {
154207
authProvider.request(.uploadImage(files: imageDataArray, authorization: accessToken)) { result in

0 commit comments

Comments
 (0)