This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
438 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
Service/Sources/Data/DataSource/Remote/API/ClubAttendAPI.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import Moya | ||
import Foundation | ||
|
||
enum ClubAttendAPI { | ||
case fetchAttendList(clubID: Int, date: String?, period: Period?) | ||
case createAttendance(clubID: Int, name: String, date: String, period: [Period]) | ||
case changeAllAttendStatus(attendanceID: String, attendanceStatus: AttendanceStatus) | ||
case statusAllApply(attendanceIDs: [String], attendanceStatus: AttendanceStatus) | ||
} | ||
|
||
extension ClubAttendAPI: GCMSAPI { | ||
var domain: GCMSDomain { | ||
return .attend | ||
} | ||
|
||
var urlPath: String { | ||
switch self { | ||
case let .fetchAttendList(clubID, _, _): | ||
return "/\(clubID)" | ||
|
||
case let .createAttendance(clubID, _, _, _): | ||
return "/\(clubID)/club" | ||
|
||
case .changeAllAttendStatus(_, _): | ||
return "" | ||
|
||
case .statusAllApply(_, _): | ||
return "/batch" | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .fetchAttendList: | ||
return .get | ||
|
||
case .changeAllAttendStatus, .statusAllApply: | ||
return .patch | ||
|
||
case .createAttendance: | ||
return .post | ||
} | ||
} | ||
|
||
var task: Task { | ||
switch self { | ||
case let .fetchAttendList(_, date, period): | ||
return .requestParameters(parameters: [ | ||
"date": date, | ||
"period": period | ||
], encoding: URLEncoding.queryString) | ||
|
||
case let .createAttendance(_, name, date, period): | ||
return .requestPlain | ||
|
||
case .changeAllAttendStatus(_, _): | ||
return .requestPlain | ||
|
||
case .statusAllApply(_, _): | ||
return .requestPlain | ||
} | ||
} | ||
|
||
var jwtTokenType: JWTTokenType? { | ||
switch self { | ||
default: | ||
return .accessToken | ||
} | ||
} | ||
|
||
typealias ErrorType = ClubAttendError | ||
var errorMapper: [Int: ClubAttendError]? { | ||
switch self { | ||
case .fetchAttendList: | ||
return [ | ||
401: .unauthorized, | ||
403: .notClubMember, | ||
404: .notFoundClub, | ||
500: .serverError | ||
] | ||
|
||
case .statusAllApply: | ||
return [ | ||
401: .unauthorized, | ||
403: .notClubHeadOrClubTeacher, | ||
404: .notFoundClub, | ||
500: .serverError | ||
] | ||
|
||
case .createAttendance: | ||
return [:] | ||
|
||
case .changeAllAttendStatus: | ||
return [:] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../Sources/Data/DataSource/Remote/DataMapping/Club/Attend/FetchClubAttendListResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Foundation | ||
|
||
public struct FetchClubAttendListResponse: Decodable { | ||
let date: String? | ||
let period: String? | ||
let users: [UsersResponse] | ||
|
||
public struct UsersResponse: Decodable { | ||
public let uuid: UUID | ||
public let attendanceID: String | ||
public let name: String | ||
public let grade: Int | ||
public let classNum: Int | ||
public let number: Int | ||
public let attendanceStatus: AttendanceStatus | ||
|
||
enum CodingKeys: String, CodingKey, Decodable { | ||
case uuid | ||
case attendanceID = "attendanceId" | ||
case name | ||
case grade | ||
case classNum | ||
case number | ||
case attendanceStatus | ||
} | ||
} | ||
} | ||
|
||
extension FetchClubAttendListResponse.UsersResponse { | ||
func toDomain() -> ClubAttend { | ||
ClubAttend( | ||
uuid: uuid, | ||
attendanceID: attendanceID, | ||
name: name, | ||
grade: grade, | ||
classNum: classNum, | ||
number: number, | ||
attendanceStatus: attendanceStatus | ||
) | ||
} | ||
} | ||
|
||
extension FetchClubAttendListResponse { | ||
func toDomain() -> [ClubAttend] { | ||
self.users.map { $0.toDomain() } | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Service/Sources/Data/DataSource/Remote/DataSource/ClubAttendRemote.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import RxSwift | ||
import Foundation | ||
|
||
protocol ClubAttendRemoteProtocol { | ||
func fetchAttendList(clubID: Int, date: String?, period: Period?) -> Single<[ClubAttend]> | ||
func createAttendance(clubID: Int, name: String, date: String, period: [Period]) -> Completable | ||
func changeAllAttendStatus(attendanceID: String, attendanceStatus: AttendanceStatus) -> Completable | ||
func statusAllApply(attendanceIDs: [String], attendanceStatus: AttendanceStatus) -> Completable | ||
} | ||
|
||
final class ClubAttendRemote: BaseRemote<ClubAttendAPI>, ClubAttendRemoteProtocol { | ||
func fetchAttendList(clubID: Int, date: String?, period: Period?) -> Single<[ClubAttend]> { | ||
self.request(.fetchAttendList(clubID: clubID, date: date, period: period)) | ||
.map(FetchClubAttendListResponse.self) | ||
.map { $0.toDomain() } | ||
} | ||
|
||
func createAttendance(clubID: Int, name: String, date: String, period: [Period]) -> Completable { | ||
self.request(.createAttendance(clubID: clubID, name: name, date: date, period: period)) | ||
.asCompletable() | ||
} | ||
|
||
func changeAllAttendStatus(attendanceID: String, attendanceStatus: AttendanceStatus) -> Completable { | ||
self.request(.changeAllAttendStatus(attendanceID: attendanceID, attendanceStatus: attendanceStatus)) | ||
.asCompletable() | ||
} | ||
|
||
func statusAllApply(attendanceIDs: [String], attendanceStatus: AttendanceStatus) -> Completable { | ||
self.request(.statusAllApply(attendanceIDs: attendanceIDs, attendanceStatus: attendanceStatus)) | ||
.asCompletable() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Service/Sources/Data/Repositories/DefaultClubAttendRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
import RxSwift | ||
|
||
final class DefaultClubAttendRepository: ClubAttendRepository { | ||
private let clubAttendRemote: any ClubAttendRemoteProtocol | ||
|
||
init(clubAttendRemote: any ClubAttendRemoteProtocol) { | ||
self.clubAttendRemote = clubAttendRemote | ||
} | ||
|
||
func fetchAttendList(clubID: Int, date: String?, period: Period?) -> Single<[ClubAttend]> { | ||
clubAttendRemote.fetchAttendList(clubID: clubID, date: date, period: period) | ||
} | ||
|
||
func createAttendance(clubID: Int, name: String, date: String, period: [Period]) -> Completable { | ||
clubAttendRemote.createAttendance(clubID: clubID, name: name, date: date, period: period) | ||
} | ||
|
||
func changeAllAttendStatus(attendanceID: String, attendanceStatus: AttendanceStatus) -> Completable { | ||
clubAttendRemote.changeAllAttendStatus(attendanceID: attendanceID, attendanceStatus: attendanceStatus) | ||
} | ||
|
||
func statusAllApply(attendanceIDs: [String], attendanceStatus: AttendanceStatus) -> Completable { | ||
clubAttendRemote.statusAllApply(attendanceIDs: attendanceIDs, attendanceStatus: attendanceStatus) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Foundation | ||
|
||
public struct ClubAttend: Equatable { | ||
public let uuid: UUID | ||
public let attendanceID: String | ||
public let name: String | ||
public let grade: Int | ||
public let classNum: Int | ||
public let number: Int | ||
public let attendanceStatus: AttendanceStatus | ||
|
||
public init( | ||
uuid: UUID, | ||
attendanceID: String, | ||
name: String, | ||
grade: Int, | ||
classNum: Int, | ||
number: Int, | ||
attendanceStatus: AttendanceStatus | ||
) { | ||
self.uuid = uuid | ||
self.attendanceID = attendanceID | ||
self.name = name | ||
self.grade = grade | ||
self.classNum = classNum | ||
self.number = number | ||
self.attendanceStatus = attendanceStatus | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public enum AttendanceStatus: String, Codable { | ||
case attendance = "ATTENDANCE" | ||
case late = "LATE" | ||
case reasonableAbsent = "REASONABLE_ABSENT" | ||
case absent = "ABSENT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public enum Period: String, Codable, CaseIterable { | ||
case first = "FIRST" | ||
case second = "SECOND" | ||
case third = "THIRD" | ||
case fourth = "FOURTH" | ||
case fifth = "FIFTH" | ||
case sixth = "SIXTH" | ||
case seventh = "SEVENTH" | ||
case eighth = "EIGHTH" | ||
case ninth = "NINTH" | ||
case tenth = "TENTH" | ||
case eleventh = "ELEVENTH" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.