Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #153- 출석 조회하기 API 연결 #157

Merged
merged 19 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions SOPT-iOS/Projects/Core/Sources/Enum/AttendanceScheduleType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// AttendanceScheduleType.swift
// Core
//
// Created by devxsby on 2023/04/15.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

public enum AttendanceScheduleType {
case unscheduledDay /// 일정 없는 날
case scheduledDay /// 일정(세미나, 행사) 있는 날
}
16 changes: 16 additions & 0 deletions SOPT-iOS/Projects/Core/Sources/Enum/AttendanceStateType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AttendanceStateType.swift
// Core
//
// Created by devxsby on 2023/04/15.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

public enum AttendanceStateType: String, CaseIterable {
case all = "전체"
case attendance = "출석"
case tardy = "지각"
case absent = "결석"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,60 @@ import Network

public class ShowAttendanceRepository {

private let networkService: AttendanceService
private let attendanceService: AttendanceService
private let cancelBag = CancelBag()

public init(service: AttendanceService) {
self.networkService = service
self.attendanceService = service
}
}

extension ShowAttendanceRepository: ShowAttendanceRepositoryInterface {
public func fetchAttendanceScheduleModel() -> AnyPublisher<AttendanceScheduleModel, Error> {
return Future<AttendanceScheduleModel, Error> { promise in
// promise(.success(AttendanceScheduleModel(type: "HAS_ATTENDANCE",
// location: "단국대학교 혜당관",
// name: "3차 세미나",
// startDate: "2023-04-06T14:14:00", endDate: "2023-04-06T18:00:00", message: "",
// attendances: [TodayAttendanceModel(status: "ATTENDANCE", attendedAt: "2023-04-13T14:12:09"),
// TodayAttendanceModel(status: "ABSENT", attendedAt:
// "2023-04-13T14:10:04")])))
Comment on lines +29 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 친구들은 토큰 받아오면 없어질 예정이겠죠..?


promise(.success(AttendanceScheduleModel(type: "HAS_ATTENDANCE",
location: "한국대학교 혜당관",
name: "2차 행사",
startDate: "2023-04-06T14:14:00", endDate: "2023-04-06T18:00:00",
message: "행사도 참여하고, 출석점수도 받고, 일석이조!",
attendances: [TodayAttendanceModel(status: "ATTENDANCE", attendedAt: "2023-04-13T14:12:09"),
TodayAttendanceModel(status: "ABSENT", attendedAt: "2023-04-13T14:10:04")])))

// promise(.success(AttendanceScheduleModel(type: "NO_SESSION",
// location: "",
// name: "",
// startDate: "", endDate: "", message: "",
// attendances: [TodayAttendanceModel(status: "", attendedAt: ""),
// TodayAttendanceModel(status: "", attendedAt: "")])))
}
.eraseToAnyPublisher()
// return self.attendanceService.fetchAttendanceSchedule()
// .map { $0.toDomain() }
// .eraseToAnyPublisher()
}

public func fetchAttendanceScoreModel() -> AnyPublisher<Domain.AttendanceScoreModel, Error> {
return Future<AttendanceScoreModel, Error> { promise in
promise(.success(AttendanceScoreModel.init(part: "iOS",
generation: 31,
name: "윤수빈",
score: 2.0,
total: TotalScoreModel(attendance: 2, absent: 0, tardy: 1, participate: 1),
attendances: [AttendanceModel(attribute: "ETC", name: "솝커톤", status: "TARDY", date: "4월 22일"),
AttendanceModel(attribute: "SEMINAR", name: "iOS 2차 세미나", status: "ATTENDANCE", date: "4월 15일"),
AttendanceModel(attribute: "SEMINAR", name: "iOS 1차 세미나", status: "ATTENDANCE", date: "4월 8일"),
AttendanceModel(attribute: "ETC", name: "OT", status: "PARTICIPATE", date: "4월 1일")])))
}.eraseToAnyPublisher()
// return self.attendanceService.fetchAttendanceScore()
// .map { $0.toDomain() }
// .eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// AttendanceScheduleTransform.swift
// Data
//
// Created by devxsby on 2023/04/11.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

import Domain
import Network

extension AttendanceScheduleEntity {

public func toDomain() -> AttendanceScheduleModel {
return .init(type: self.type,
location: self.location,
name: self.name,
startDate: self.startDate,
endDate: self.endDate,
message: self.message,
attendances: self.attendances.map { $0.toDomain() })
}
}

extension TodayAttendance {

public func toDomain() -> TodayAttendanceModel {
return .init(status: self.status,
attendedAt: self.attendedAt)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// AttendanceScoreTransform.swift
// Data
//
// Created by devxsby on 2023/04/15.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

import Domain
import Network

extension AttendanceScoreEntity {

public func toDomain() -> AttendanceScoreModel {
.init(part: self.part,
generation: self.generation,
name: self.name,
score: self.score,
total: self.total.toDomain(),
attendances: self.attendances.map { $0.toDomain() } )
}
}

extension TotalScore {
public func toDomain() -> TotalScoreModel {
.init(attendance: self.attendance,
absent: self.absent,
tardy: self.tardy,
participate: self.participate)
}
}

extension Attendance {
public func toDomain() -> AttendanceModel {
.init(attribute: self.attribute,
name: self.name,
status: self.status,
date: self.date)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// AttendanceScheduleModel.swift
// Domain
//
// Created by devxsby on 2023/04/11.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

public struct AttendanceScheduleModel: Codable, Hashable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hashable을 채택한 이유가 궁금합니다!

public let type: String
public let location, name, startDate, endDate: String
public let message: String
public let attendances: [TodayAttendanceModel]

public init(type: String, location: String, name: String, startDate: String, endDate: String, message: String, attendances: [TodayAttendanceModel]) {
self.type = type
self.location = location
self.name = name
self.startDate = startDate
self.endDate = endDate
self.message = message
self.attendances = attendances
}
}

public struct TodayAttendanceModel: Codable, Hashable {
public let status, attendedAt: String

public init(status: String, attendedAt: String) {
self.status = status
self.attendedAt = attendedAt
}
}
50 changes: 50 additions & 0 deletions SOPT-iOS/Projects/Domain/Sources/Model/AttendanceScoreModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// AttendanceScoreModel.swift
// Domain
//
// Created by devxsby on 2023/04/15.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

public struct AttendanceScoreModel: Codable, Hashable {
public let part: String
public let generation: Int
public let name: String
public let score: Double
public let total: TotalScoreModel
public let attendances: [AttendanceModel]

public init(part: String, generation: Int, name: String, score: Double, total: TotalScoreModel, attendances: [AttendanceModel]) {
self.part = part
self.generation = generation
self.name = name
self.score = score
self.total = total
self.attendances = attendances
}

}

public struct TotalScoreModel: Codable, Hashable {
public let attendance, absent, tardy, participate: Int

public init(attendance: Int, absent: Int, tardy: Int, participate: Int) {
self.attendance = attendance
self.absent = absent
self.tardy = tardy
self.participate = participate
}
}

public struct AttendanceModel: Codable, Hashable {
public let attribute, name, status, date: String

public init(attribute: String, name: String, status: String, date: String) {
self.attribute = attribute
self.name = name
self.status = status
self.date = date
}
}
16 changes: 0 additions & 16 deletions SOPT-iOS/Projects/Domain/Sources/Model/ShowAttendanceModel.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
import Combine

public protocol ShowAttendanceRepositoryInterface {

func fetchAttendanceScheduleModel() -> AnyPublisher<AttendanceScheduleModel, Error>
func fetchAttendanceScoreModel() -> AnyPublisher<AttendanceScoreModel, Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,43 @@ import Combine
import Core

public protocol ShowAttendanceUseCase {

func fetchAttendanceSchedule()
func fetchAttendanceScore()
var attendanceScheduleFetched: PassthroughSubject<AttendanceScheduleModel, Error> { get set }
var attendanceScoreFetched: PassthroughSubject<AttendanceScoreModel, Error> { get set }
}

public class DefaultShowAttendanceUseCase {

private let repository: ShowAttendanceRepositoryInterface
private var cancelBag = CancelBag()

public var attendanceScheduleFetched = PassthroughSubject<AttendanceScheduleModel, Error>()
public var attendanceScoreFetched = PassthroughSubject<AttendanceScoreModel, Error>()

public init(repository: ShowAttendanceRepositoryInterface) {
self.repository = repository
}
}

extension DefaultShowAttendanceUseCase: ShowAttendanceUseCase {

public func fetchAttendanceSchedule() {
self.repository.fetchAttendanceScheduleModel()
.sink(receiveCompletion: { event in
print("completion: \(event)")
}, receiveValue: { model in
self.attendanceScheduleFetched.send(model)
})
.store(in: cancelBag)
}

public func fetchAttendanceScore() {
self.repository.fetchAttendanceScoreModel()
.sink(receiveCompletion: { event in
print("completion: \(event)")
}, receiveValue: { model in
self.attendanceScoreFetched.send(model)
})
.store(in: cancelBag)
}
}
Loading