Skip to content

Commit

Permalink
feat: 제출 상태 확인 api 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsh153 committed Jul 11, 2024
1 parent 4a733aa commit 6d8115b
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public protocol AuthenticationDomainBuildable {
var fetchAuthenticationFormUseCase: any FetchAuthenticationFormUseCase { get }
var inputAuthenticationUseCase: any InputAuthenticationUseCase { get }
var fetchAuthenticationStateUseCase: any FetchAuthenticationStateUseCase { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public protocol RemoteAuthenticationDataSource {
func fetchAuthenticationForm() async throws -> AuthenticationFormEntity

func inputAuthentication(req: InputAuthenticationRequestDTO) async throws

func fetchAuthenticationState() async throws -> AuthenticationStateEntity
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public struct AuthenticationStateEntity {
public let name: String
public let score: Double
public let grader: String?
public let markingBoardType: MarkingBoardType

public init(name: String, score: Double, grader: String?, markingBoardType: MarkingBoardType) {
self.name = name
self.score = score
self.grader = grader
self.markingBoardType = markingBoardType
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public enum MarkingBoardType: String, Codable {
case notSubmitted = "NOT_SUBMITTED"
case pendingReview = "PENDING_REVIEW"
case underReview = "UNDER_REVIEW"
case completed = "COMPLETED"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import Foundation
public protocol AuthenticationRepository {
func fetchAuthenticationForm() async throws -> AuthenticationFormEntity
func inputAuthentication(req: InputAuthenticationRequestDTO) async throws
func fetchAuthenticationState() async throws -> AuthenticationStateEntity
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public protocol FetchAuthenticationStateUseCase {
func execute() async throws -> AuthenticationStateEntity
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public final class AuthenticationDomainComponent: Component<AuthenticationDomain
public var fetchAuthenticationFormUseCase: any FetchAuthenticationFormUseCase {
FetchAuthenticationFormUseCaseImpl(authenticationRepository: authenticationRepository)
}
public var fetchAuthenticationStateUseCase: any FetchAuthenticationStateUseCase {
FetchAuthenticationStateUseCaseImpl(authenticationRepository: authenticationRepository)
}
public var authenticationRepository: any AuthenticationRepository {
AuthenticationRepositoryImpl(remoteAuthenticationDataSource: remoteAuthenticationDataSource)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation
import AuthenticationDomainInterface

public struct AuthenticationStateResponseDTO: Decodable {
public let name: String
public let score: Double
public let grader: String?
public let markingBoardType: MarkingBoardType

public init(name: String, score: Double, grader: String?, markingBoardType: MarkingBoardType) {
self.name = name
self.score = score
self.grader = grader
self.markingBoardType = markingBoardType
}
}

extension AuthenticationStateResponseDTO {
func toDomain() -> AuthenticationStateEntity {
AuthenticationStateEntity(
name: name,
score: score,
grader: grader,
markingBoardType: markingBoardType
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ final class RemoteAuthenticationDataSourceImpl: BaseRemoteDataSource<Authenticat
func inputAuthentication(req: InputAuthenticationRequestDTO) async throws {
try await request(.inputAuthentication(req: req))
}

func fetchAuthenticationState() async throws -> AuthenticationStateEntity {
try await request(.fetchAuthenticationState, dto: AuthenticationStateResponseDTO.self).toDomain()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Emdpoint
enum AuthenticationEndpoint {
case fetchAuthenticationForm
case inputAuthentication(req: InputAuthenticationRequestDTO)
case fetchAuthenticationState
}

extension AuthenticationEndpoint: SMSEndpoint {
Expand All @@ -20,6 +21,8 @@ extension AuthenticationEndpoint: SMSEndpoint {
return .get("/form")
case .inputAuthentication:
return .post("/submit")
case .fetchAuthenticationState:
return .get("/verify")
}
}

Expand All @@ -31,6 +34,9 @@ extension AuthenticationEndpoint: SMSEndpoint {
case let .inputAuthentication(req):
return .requestJSONEncodable(req)

case .fetchAuthenticationState:
return .requestPlain

default:
return .requestPlain
}
Expand All @@ -44,6 +50,9 @@ extension AuthenticationEndpoint: SMSEndpoint {
case .inputAuthentication:
return .accessToken

case .fetchAuthenticationState:
return .accessToken

default:
return .none
}
Expand All @@ -59,6 +68,10 @@ extension AuthenticationEndpoint: SMSEndpoint {
return [
500: .internalServerError
]
case .fetchAuthenticationState:
return [
500: .internalServerError
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ struct AuthenticationRepositoryImpl: AuthenticationRepository {
func inputAuthentication(req: InputAuthenticationRequestDTO) async throws {
try await remoteAuthenticationDataSource.inputAuthentication(req: req)
}

func fetchAuthenticationState() async throws -> AuthenticationStateEntity {
try await remoteAuthenticationDataSource.fetchAuthenticationState()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import AuthenticationDomainInterface

struct FetchAuthenticationStateUseCaseImpl: FetchAuthenticationStateUseCase {
private let authenticationRepository: any AuthenticationRepository

init(authenticationRepository: any AuthenticationRepository) {
self.authenticationRepository = authenticationRepository
}

func execute() async throws -> AuthenticationStateEntity {
try await authenticationRepository.fetchAuthenticationState()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import AuthenticationDomainInterface

public final class FetchAuthenticationStateUseCaseSpy: FetchAuthenticationStateUseCase {
public var callCount = 0
public var handler: (() async throws -> AuthenticationStateEntity)? = {
return AuthenticationStateEntity(name: "ASDFsa", score: 0, grader: nil, markingBoardType: .notSubmitted)
}

public init() {}

public func execute() async throws -> AuthenticationStateEntity {
guard let handler else { fatalError() }
return try await handler()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class DemoMakable {
model: GSMAuthenticationFormModel(),
fetchAuthenticationFormUseCase: FetchAuthenticationFormUseCaseSpy(),
inputAuthenticationUseCase: InputAuthenticationUseCaseSpy(),
fileUploadUseCase: FileUploadUseCaseSpy()
fileUploadUseCase: FileUploadUseCaseSpy(), fetchAuthenticationStateUseCase: FetchAuthenticationStateUseCaseSpy()
),
uiModel: uiModel
) { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class GSMAuthenticationComponent: Component<GSMAuthenticationDepend
model: model,
fetchAuthenticationFormUseCase: dependency.authenticationDomainBuildable.fetchAuthenticationFormUseCase,
inputAuthenticationUseCase: dependency.authenticationDomainBuildable.inputAuthenticationUseCase,
fileUploadUseCase: dependency.fileDomainBuildable.fileUploadUseCase
fileUploadUseCase: dependency.fileDomainBuildable.fileUploadUseCase, fetchAuthenticationStateUseCase: dependency.authenticationDomainBuildable.fetchAuthenticationStateUseCase
)
let container = MVIContainer(
intent: intent as GSMAuthenticationFormIntentProtocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,40 @@ final class GSMAuthenticationFormIntent: GSMAuthenticationFormIntentProtocol {
private let fetchAuthenticationFormUseCase: any FetchAuthenticationFormUseCase
private let inputAuthenticationUseCase: any InputAuthenticationUseCase
private let fileUploadUseCase: any FileUploadUseCase
private let fetchAuthenticationStateUseCase: any FetchAuthenticationStateUseCase

init(
model: any GSMAuthenticationFormActionProtocol,
fetchAuthenticationFormUseCase: any FetchAuthenticationFormUseCase,
inputAuthenticationUseCase: any InputAuthenticationUseCase,
fileUploadUseCase: any FileUploadUseCase
fileUploadUseCase: any FileUploadUseCase,
fetchAuthenticationStateUseCase: FetchAuthenticationStateUseCase
) {
self.model = model
self.fetchAuthenticationFormUseCase = fetchAuthenticationFormUseCase
self.inputAuthenticationUseCase = inputAuthenticationUseCase
self.fileUploadUseCase = fileUploadUseCase
self.fetchAuthenticationStateUseCase = fetchAuthenticationStateUseCase
}

func viewOnAppear() {
Task {
do {
let authenticationStateEntity = try await fetchAuthenticationStateUseCase.execute()

model?.updateAuthenticationStateEntity(authenticationStateEntity: authenticationStateEntity)

model?.updateAuthenticationStateModel(
stateModel:
.init(
name: authenticationStateEntity.name,
score: authenticationStateEntity.score,
grader: authenticationStateEntity.grader,
markingBoardType: authenticationStateEntity.markingBoardType
)
)
}
}
}

func appendField(
Expand All @@ -38,7 +61,7 @@ final class GSMAuthenticationFormIntent: GSMAuthenticationFormIntentProtocol {
model?.deleteField(area: area, sectionIndex: sectionIndex, groupIndex: groupIndex)
}

func onAppear() {
func formOnAppear() {
Task {
do {
let authenticationEntity = try await fetchAuthenticationFormUseCase.execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation

protocol GSMAuthenticationFormIntentProtocol {
func onAppear()
func viewOnAppear()
func formOnAppear()
func saveButtonDidTap(state: any GSMAuthenticationFormStateProtocol)
func appendField(
area: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import FoundationUtil
final class GSMAuthenticationFormModel: ObservableObject, GSMAuthenticationFormStateProtocol {
@Published var uiModel: GSMAuthenticationFormUIModel = .init(areas: [], files: [])
@Published var fieldContents: [GSMAuthenticationFormFieldModel] = []
@Published var stateModel: GSMAuthenticationStateModel = .init(name: "", score: 0, markingBoardType: .notSubmitted)
var authenticationEntity: AuthenticationFormEntity?
var authenticationStateEntity: AuthenticationStateEntity?
}

extension GSMAuthenticationFormModel: GSMAuthenticationFormActionProtocol {
Expand All @@ -21,6 +23,16 @@ extension GSMAuthenticationFormModel: GSMAuthenticationFormActionProtocol {
self.fieldContents = fields
}

func updateAuthenticationStateEntity(
authenticationStateEntity: AuthenticationStateEntity
) {
self.authenticationStateEntity = authenticationStateEntity
}

func updateAuthenticationStateModel(stateModel: GSMAuthenticationStateModel) {
self.stateModel = stateModel
}

func appendField(
area: Int,
sectionIndex: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import Foundation
protocol GSMAuthenticationFormStateProtocol {
var uiModel: GSMAuthenticationFormUIModel { get }
var authenticationEntity: AuthenticationFormEntity? { get }
var authenticationStateEntity: AuthenticationStateEntity? { get }
var stateModel: GSMAuthenticationStateModel { get }
}

protocol GSMAuthenticationFormActionProtocol: AnyObject {
func updateGSMAuthenticationFormUIModel(uiModel: GSMAuthenticationFormUIModel)
func updateAuthenticationEntity(authenticationEntity: AuthenticationFormEntity)

func updateAuthenticationStateEntity(
authenticationStateEntity: AuthenticationStateEntity
)

func updateAuthenticationStateModel(stateModel: GSMAuthenticationStateModel)

func appendField(
area: Int,
sectionIndex: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import AuthenticationDomainInterface

struct GSMAuthenticationStateModel {
var name: String
var score: Double
var grader: String?
var markingBoardType: MarkingBoardType
}
Loading

0 comments on commit 6d8115b

Please sign in to comment.