Skip to content

Commit a948def

Browse files
authored
[Feat] #801 - 앱잼 랭킹 뷰 API 연결
[Feat] #801 - 앱잼 랭킹 뷰 API 연결
2 parents 7ecec2f + 0fced95 commit a948def

File tree

28 files changed

+650
-166
lines changed

28 files changed

+650
-166
lines changed

SOPT-iOS/Projects/Core/Sources/Enum/TabBarItemType.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ public extension TabBarItemType {
2929
func getTabIndex(userType: UserType) -> Int {
3030
switch userType {
3131
case .active:
32-
return self.rawValue
32+
switch self {
33+
case .home:
34+
return 0
35+
case .soptamp:
36+
return 1
37+
case .soptlog:
38+
return 2
39+
default: return 0 // poke 탭이 비활성화 상태이므로 0으로 처리
40+
}
3341
case .visitor, .inactive:
3442
switch self {
3543
case .home, .soptamp:
@@ -46,7 +54,12 @@ public extension TabBarItemType {
4654
static func from(index: Int, userType: UserType) -> TabBarItemType? {
4755
switch userType {
4856
case .active:
49-
return TabBarItemType(rawValue: index)
57+
switch index {
58+
case 0: return .home
59+
case 1: return .soptamp
60+
case 2: return .soptlog
61+
default: return nil
62+
}
5063
case .visitor, .inactive:
5164
switch index {
5265
case 0: return .home

SOPT-iOS/Projects/Core/Sources/Utils/calculatePastTime.swift

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,26 @@
77

88
import Foundation
99

10-
public func calculatePastTime(date: String) -> String {
11-
10+
public func calculatePastTime(date: String, dateFormat: String = "yyyy-MM-dd HH:mm:ss") -> String {
11+
1212
let minute = 60
1313
let hour = minute * 60
1414
let day = hour * 60
1515
let week = day * 7
16-
16+
1717
var message: String = ""
18-
19-
let UTCDate = Date()
20-
let formatter = DateFormatter()
21-
formatter.timeZone = TimeZone(secondsFromGMT: 32400)
22-
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
23-
let defaultTimeZoneStr = formatter.string(from: UTCDate)
24-
18+
2519
let format = DateFormatter()
26-
format.dateFormat = "yyyy-MM-dd HH:mm:ss"
20+
format.dateFormat = dateFormat
2721
format.locale = Locale(identifier: "ko_KR")
28-
22+
format.timeZone = TimeZone(identifier: "Asia/Seoul")
23+
2924
guard let tempDate = format.date(from: date) else {return ""}
30-
let krTime = format.date(from: defaultTimeZoneStr)
31-
25+
26+
let now = Date()
27+
let useTime = Int(now.timeIntervalSince(tempDate))
28+
3229
let articleDate = format.string(from: tempDate)
33-
var useTime = Int(krTime!.timeIntervalSince(tempDate))
34-
useTime = useTime - 32400
3530

3631
if useTime < minute {
3732
message = "방금 전"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// AppjamRankingRepository.swift
3+
// Data
4+
//
5+
// Created by 강윤서 on 1/5/26.
6+
// Copyright © 2026 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
import Domain
12+
import Networks
13+
14+
public class AppjamRankingRepository {
15+
16+
private let appJamRankingService: AppJamRankingService
17+
18+
public init(service: AppJamRankingService) {
19+
self.appJamRankingService = service
20+
}
21+
}
22+
23+
extension AppjamRankingRepository: AppjamRankingRepositoryInterface {
24+
public func fetchTodayRanking(size: Int) async throws -> [AppjamRankTodayModel] {
25+
let entity = try await appJamRankingService.fetchTodayRanking(size: size)
26+
return entity.ranks.map { $0.toDomain() }
27+
}
28+
29+
public func fetchRecentRanking(size: Int) async throws -> [AppjamRankRecentModel] {
30+
let entity = try await appJamRankingService.fetchRecentRanking(size: size)
31+
return entity.ranks.map { $0.toDomain() }
32+
}
33+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// AppjamRankRecentTransform.swift
3+
// Data
4+
//
5+
// Created by 강윤서 on 1/5/26.
6+
// Copyright © 2026 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
import Domain
12+
import Networks
13+
14+
extension AppjamRankRecent {
15+
public func toDomain() -> AppjamRankRecentModel {
16+
return AppjamRankRecentModel(
17+
stampId: self.stampId,
18+
missionId: self.missionId,
19+
userId: self.userId,
20+
imageUrl: self.imageUrl,
21+
createdAt: self.createdAt,
22+
userName: self.userName,
23+
userProfileImage: self.userProfileImage,
24+
teamName: self.teamName,
25+
teamNumber: self.teamNumber
26+
)
27+
}
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// AppjamRankTodayTransform.swift
3+
// Data
4+
//
5+
// Created by 강윤서 on 1/5/26.
6+
// Copyright © 2026 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
import Domain
12+
import Networks
13+
14+
extension AppjamRankToday {
15+
public func toDomain() -> AppjamRankTodayModel {
16+
return AppjamRankTodayModel(
17+
rank: self.rank,
18+
teamName: self.teamName,
19+
todayPoints: self.todayPoints,
20+
totalPoints: self.totalPoints
21+
)
22+
}
23+
}

SOPT-iOS/Projects/Demo/Sources/Dependency/RegisterDependencies.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,11 @@ extension AppDelegate {
239239
SoptlogRepository(userService: DefaultUserService.standard)
240240
}
241241
)
242+
container.register(
243+
interface: AppjamRankingRepositoryInterface.self,
244+
implement: {
245+
AppjamRankingRepository(service: DefaultAppJamRankingService.standard)
246+
}
247+
)
242248
}
243249
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// AppjamRankRecentModel.swift
3+
// Domain
4+
//
5+
// Created by 강윤서 on 1/5/26.
6+
// Copyright © 2026 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct AppjamRankRecentModel {
12+
public let stampId: Int
13+
public let missionId: Int
14+
public let userId: Int
15+
public let imageUrl: String
16+
public let createdAt: String
17+
public let userName: String
18+
public let userProfileImage: String
19+
public let teamName: String
20+
public let teamNumber: String
21+
22+
public init(
23+
stampId: Int,
24+
missionId: Int,
25+
userId: Int,
26+
imageUrl: String,
27+
createdAt: String,
28+
userName: String,
29+
userProfileImage: String,
30+
teamName: String,
31+
teamNumber: String
32+
) {
33+
self.stampId = stampId
34+
self.missionId = missionId
35+
self.userId = userId
36+
self.imageUrl = imageUrl
37+
self.createdAt = createdAt
38+
self.userName = userName
39+
self.userProfileImage = userProfileImage
40+
self.teamName = teamName
41+
self.teamNumber = teamNumber
42+
}
43+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// AppjamRankTodayModel.swift
3+
// Domain
4+
//
5+
// Created by 강윤서 on 1/5/26.
6+
// Copyright © 2026 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct AppjamRankTodayModel {
12+
public let rank: Int
13+
public let teamName: String
14+
public let todayPoints: Int
15+
public let totalPoints: Int
16+
17+
public init(rank: Int, teamName: String, todayPoints: Int, totalPoints: Int) {
18+
self.rank = rank
19+
self.teamName = teamName
20+
self.todayPoints = todayPoints
21+
self.totalPoints = totalPoints
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// AppjamRankingRepositoryInterface.swift
3+
// Domain
4+
//
5+
// Created by 강윤서 on 1/5/26.
6+
// Copyright © 2026 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol AppjamRankingRepositoryInterface {
12+
func fetchTodayRanking(size: Int) async throws -> [AppjamRankTodayModel]
13+
func fetchRecentRanking(size: Int) async throws -> [AppjamRankRecentModel]
14+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// AppjamRankingUseCase.swift
3+
// Domain
4+
//
5+
// Created by 강윤서 on 1/5/26.
6+
// Copyright © 2026 SOPT-iOS. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol AppjamRankingUseCase {
12+
func fetchTodayRanking(size: Int) async throws -> [AppjamRankTodayModel]
13+
func fetchRecentRanking(size: Int) async throws -> [AppjamRankRecentModel]
14+
}
15+
16+
public class DefaultAppjamRankingUseCase {
17+
18+
private let repository: AppjamRankingRepositoryInterface
19+
20+
public init(repository: AppjamRankingRepositoryInterface) {
21+
self.repository = repository
22+
}
23+
}
24+
25+
extension DefaultAppjamRankingUseCase: AppjamRankingUseCase {
26+
public func fetchTodayRanking(size: Int) async throws -> [AppjamRankTodayModel] {
27+
try await repository.fetchTodayRanking(size: size)
28+
}
29+
30+
public func fetchRecentRanking(size: Int) async throws -> [AppjamRankRecentModel] {
31+
try await repository.fetchRecentRanking(size: size)
32+
}
33+
}

0 commit comments

Comments
 (0)