Skip to content

Commit

Permalink
[Feat] sopt-makers#159 - 출석하기 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
0inn committed Apr 17, 2023
1 parent b03e68f commit cb3faf4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
17 changes: 15 additions & 2 deletions SOPT-iOS/Projects/Modules/Network/Sources/API/AttendanceAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public enum AttendanceAPI {
case lecture
case score
case total
case lectureRound(lectureId: Int)
case attend(lectureRoundId: Int, code: Int)
}

extension AttendanceAPI: BaseAPI {
Expand All @@ -39,22 +41,33 @@ extension AttendanceAPI: BaseAPI {
return "score"
case .total:
return "total"
case .lectureRound(let lectureId):
return "lecture/round/\(lectureId)"
case .attend:
return "attend"
}
}

// MARK: - Method
public var method: Moya.Method {
switch self {
case .lecture, .score, .total:
case .lecture, .score, .total, .lectureRound:
return .get
case .attend:
return .post
}
}

// MARK: - Parameters
private var bodyParameters: Parameters? {
var params: Parameters = [:]

switch self {
default: break
case let .attend(lectureRoundId: id, code: code):
params["subLectureId"] = id
params["code"] = code
default:
break
}
return params
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// AttendanceRoundEntity.swift
// Network
//
// Created by 김영인 on 2023/04/16.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

public struct AttendanceRoundEntity: Decodable {
public let id: Int
public let round: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public typealias DefaultAttendanceService = BaseService<AttendanceAPI>
public protocol AttendanceService {
func fetchAttendanceSchedule() -> AnyPublisher<AttendanceScheduleEntity, Error>
func fetchAttendanceScore() -> AnyPublisher<AttendanceScoreEntity, Error>
func fetchAttendanceRound(lectureId: Int) -> AnyPublisher<BaseEntity<AttendanceRoundEntity>, Error>
func postAttendance(lectureRoundId: Int, code: Int) -> AnyPublisher<BaseEntity<Int>, Error>
}

extension DefaultAttendanceService: AttendanceService {
Expand All @@ -28,4 +30,12 @@ extension DefaultAttendanceService: AttendanceService {
public func fetchAttendanceScore() -> AnyPublisher<AttendanceScoreEntity, Error> {
requestObjectInCombine(AttendanceAPI.lecture)
}

public func fetchAttendanceRound(lectureId: Int) -> AnyPublisher<BaseEntity<AttendanceRoundEntity>, Error> {
requestObjectInCombine(AttendanceAPI.lectureRound(lectureId: lectureId))
}

public func postAttendance(lectureRoundId: Int, code: Int) -> AnyPublisher<BaseEntity<Int>, Error> {
requestObjectInCombine(AttendanceAPI.attend(lectureRoundId: lectureRoundId, code: code))
}
}

0 comments on commit cb3faf4

Please sign in to comment.