Skip to content

Commit

Permalink
Merge pull request #240 from GSM-MSG/239-input-dreambook-file-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsh153 authored Aug 10, 2023
2 parents 6dca869 + 612683d commit 63d8ac9
Show file tree
Hide file tree
Showing 21 changed files with 1 addition and 166 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
public protocol FileDomainBuildable {
var dreamBookUploadUseCase: any DreamBookUploadUseCase { get }
var imageUploadUseCase: any ImageUploadUseCase { get }
var fileRepository: any FileRepository { get }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation

public protocol RemoteFileDataSource {
func dreamBookUpload(file: Data, fileName: String) async throws -> String
func imageUpload(image: Data, fileName: String) async throws -> String
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation

public protocol FileRepository {
func dreamBookUpload(file: Data, fileName: String) async throws -> String
func imageUpload(image: Data, fileName: String) async throws -> String
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ public final class FileDomainComponent: Component<FileDomainDependency>, FileDom
public var imageUploadUseCase: any ImageUploadUseCase {
ImageUploadUseCaseImpl(fileRepository: fileRepository)
}
public var dreamBookUploadUseCase: any DreamBookUploadUseCase {
DreamBookUploadUseCaseImpl(fileRepository: fileRepository)
}
public var fileRepository: any FileRepository {
FileRepositoryImpl(remoteFileDataSource: remoteFileDataSource)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import Foundation
import BaseDomain

final class RemoteFileDataSourceImpl: BaseRemoteDataSource<FileEndpoint>, RemoteFileDataSource {
func dreamBookUpload(file: Data, fileName: String) async throws -> String {
try await request(
.dreamBookUpload(file: file, fileName: fileName),
dto: DreamBookUploadResponseDTO.self
)
.fileURL
}

func imageUpload(image: Data, fileName: String) async throws -> String {
try await request(
.imageUpload(image: image, fileName: fileName),
Expand Down
17 changes: 1 addition & 16 deletions Projects/Domain/FileDomain/Sources/Endpoint/FileEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import FileDomainInterface
import Foundation

enum FileEndpoint {
case dreamBookUpload(file: Data, fileName: String)
case imageUpload(image: Data, fileName: String)
}

Expand All @@ -17,21 +16,13 @@ extension FileEndpoint: SMSEndpoint {

var route: Route {
switch self {
case .dreamBookUpload:
return .post("")

case .imageUpload:
return .post("/image")
}
}

var task: HTTPTask {
switch self {
case let .dreamBookUpload(file, fileName):
return .uploadMultipart([
MultiPartFormData(field: "file", data: file, fileName: fileName)
])

case let .imageUpload(image, fileName):
return .uploadMultipart([
MultiPartFormData(field: "file", data: image, fileName: fileName)
Expand All @@ -44,7 +35,7 @@ extension FileEndpoint: SMSEndpoint {

var jwtTokenType: JwtTokenType {
switch self {
case .dreamBookUpload, .imageUpload:
case .imageUpload:
return .accessToken

default:
Expand All @@ -58,12 +49,6 @@ extension FileEndpoint: SMSEndpoint {

var errorMap: [Int: ErrorType]? {
switch self {
case .dreamBookUpload:
return [
400: .notHwpFile,
500: .internalServerError
]

case .imageUpload:
return [
400: .notImageType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ struct FileRepositoryImpl: FileRepository {
self.remoteFileDataSource = remoteFileDataSource
}

func dreamBookUpload(file: Data, fileName: String) async throws -> String {
try await remoteFileDataSource.dreamBookUpload(file: file, fileName: fileName)
}

func imageUpload(image: Data, fileName: String) async throws -> String {
try await remoteFileDataSource.imageUpload(image: image, fileName: fileName)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Foundation
public struct InputStudentInformationRequestDTO: Encodable {
public let certificate: [String]
public let contactEmail: String
public let dreamBookFileURL: String
public let formOfEmployment: FormOfEmployment
public let gsmAuthenticationScore: Int
public let introduce: String
Expand All @@ -21,7 +20,6 @@ public struct InputStudentInformationRequestDTO: Encodable {
public init(
certificate: [String],
contactEmail: String,
dreamBookFileURL: String,
formOfEmployment: FormOfEmployment,
gsmAuthenticationScore: Int,
introduce: String,
Expand All @@ -38,7 +36,6 @@ public struct InputStudentInformationRequestDTO: Encodable {
) {
self.certificate = certificate
self.contactEmail = contactEmail
self.dreamBookFileURL = dreamBookFileURL
self.formOfEmployment = formOfEmployment
self.gsmAuthenticationScore = gsmAuthenticationScore
self.introduce = introduce
Expand All @@ -57,7 +54,6 @@ public struct InputStudentInformationRequestDTO: Encodable {
enum CodingKeys: String, CodingKey {
case certificate
case contactEmail
case dreamBookFileURL = "dreamBookFileUrl"
case formOfEmployment
case gsmAuthenticationScore
case introduce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ extension StudentDetailEntity {
}

public struct DetailInfoByTeacher: Equatable {
public let dreamBookFileURL: String?
public let portfolioURL: String?
public let grade: Int
public let `class`: Int
Expand All @@ -66,7 +65,6 @@ extension StudentDetailEntity {
public let certificate: [String]

public init(
dreamBookFileURL: String?,
portfolioURL: String?,
grade: Int,
class: Int,
Expand All @@ -81,7 +79,6 @@ extension StudentDetailEntity {
languageCertificate: [LanguageCertificateEntity],
certificate: [String]
) {
self.dreamBookFileURL = dreamBookFileURL
self.portfolioURL = portfolioURL
self.grade = grade
self.class = `class`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Foundation
public struct FetchStudentDetailByTeacherResponseDTO: Decodable {
public let name: String
public let introduce: String
public let dreamBookFileUrl: String?
public let portfolioUrl: String?
public let grade: Int
public let classNum: Int
Expand Down Expand Up @@ -54,7 +53,6 @@ public extension FetchStudentDetailByTeacherResponseDTO {
projects: projects.map { $0.toDomain() },
prizes: prizes.map { $0.toDomain() },
detailInfoByTeacher: .init(
dreamBookFileURL: dreamBookFileUrl,
portfolioURL: portfolioUrl,
grade: grade,
class: classNum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public final class InputInformationComponent:
let intent = InputInformationIntent(
model: model,
inputInformationDelegate: delegate,
dreamBookUploadUseCase: dependency.fileDomainBuildable.dreamBookUploadUseCase,
imageUploadUseCase: dependency.fileDomainBuildable.imageUploadUseCase,
inputInformationUseCase: dependency.studentDomainBuildable.inputInformationUseCase
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@ import DateUtil
final class InputInformationIntent: InputInformationIntentProtocol {
private weak var model: (any InputInformationActionProtocol)?
private weak var inputInformationDelegate: (any InputInformationDelegate)?
private let dreamBookUploadUseCase: any DreamBookUploadUseCase
private let imageUploadUseCase: any ImageUploadUseCase
private let inputInformationUseCase: any InputInformationUseCase

init(
model: any InputInformationActionProtocol,
inputInformationDelegate: any InputInformationDelegate,
dreamBookUploadUseCase: any DreamBookUploadUseCase,
imageUploadUseCase: any ImageUploadUseCase,
inputInformationUseCase: any InputInformationUseCase
) {
self.model = model
self.inputInformationDelegate = inputInformationDelegate
self.dreamBookUploadUseCase = dreamBookUploadUseCase
self.imageUploadUseCase = imageUploadUseCase
self.inputInformationUseCase = inputInformationUseCase
}
Expand All @@ -52,15 +49,10 @@ final class InputInformationIntent: InputInformationIntentProtocol {
image: inputProfileInfo.profileImageData,
fileName: inputProfileInfo.profileImageFilename
)
async let dreamBookURL = dreamBookUploadUseCase.execute(
file: inputSchoolLifeInfo.hwpData,
fileName: inputSchoolLifeInfo.hwpFilename
)

let inputInformationRequest = try await InputStudentInformationRequestDTO(
certificate: state.certificates,
contactEmail: inputProfileInfo.contactEmail,
dreamBookFileURL: dreamBookURL,
formOfEmployment: FormOfEmployment(rawValue: inputWorkInfo.formOfEmployment) ?? .fullTime,
gsmAuthenticationScore: inputSchoolLifeInfo.gsmAuthenticationScore,
introduce: inputProfileInfo.introduce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,9 @@ final class StudentDetailIntent: StudentDetailIntentProtocol {
}
}

func dreamBookDownloadButtonDidTap(dreamBookFileURL: String) {
guard let url = URL(string: dreamBookFileURL) else { return }
throttler {
self.model?.updateIsDownloading(isDownloading: true)
Task(priority: .background) {
do {
let (dreamBookFileData, _) = try await URLSession.shared.data(from: url)
let hwpDocument = HWPDocument(hwpData: dreamBookFileData)
self.model?.updateHWPDocument(hwpDocument: hwpDocument)
try await Task.sleep(nanoseconds: 1_000_000_000)
self.model?.updateIsDownloading(isDownloading: false)
self.model?.updateIsPresentedDreamBookExporter(isPresented: true)
} catch {
self.model?.updateIsDownloading(isDownloading: false)
}
}
}
}

deinit {
print("DEIIN")
}

func dreamBookFileExporterDismissed() {
model?.updateIsPresentedDreamBookExporter(isPresented: false)
}
}

private extension UserRoleType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ import Foundation

protocol StudentDetailIntentProtocol {
func onAppear()
func dreamBookDownloadButtonDidTap(dreamBookFileURL: String)
func dreamBookFileExporterDismissed()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ final class StudentDetailModel: ObservableObject, StudentDetailStateProtocol {
@Published var _studentDetailEntity: StudentDetailEntity?
@Published var isLoading: Bool = false
@Published var isDownloading: Bool = false
@Published var isPresentedDreamBookExporter: Bool = false
@Published var hwpDocument: HWPDocument?
var hwpFilename: String {
guard let studentDetailEntity, let info = studentDetailEntity.detailInfoByTeacher else { return "" }
let number = info.number >= 10 ? "\(info.number)" : "0\(info.number)"
return "\(info.grade)\(info.class)\(number)\(studentDetailEntity.name)-드림북.hwp"
}
}
// swiftlint: enable identifier_name

Expand All @@ -52,12 +45,4 @@ extension StudentDetailModel: StudentDetailActionProtocol {
func updateIsDownloading(isDownloading: Bool) {
self.isDownloading = isDownloading
}

func updateIsPresentedDreamBookExporter(isPresented: Bool) {
self.isPresentedDreamBookExporter = isPresented
}

func updateHWPDocument(hwpDocument: HWPDocument) {
self.hwpDocument = hwpDocument
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ protocol StudentDetailStateProtocol {
var studentDetailEntity: StudentDetailEntity? { get }
var isLoading: Bool { get }
var isDownloading: Bool { get }
var isPresentedDreamBookExporter: Bool { get }
var hwpDocument: HWPDocument? { get }
var hwpFilename: String { get }
}

protocol StudentDetailActionProtocol: AnyObject {
func updateUserRole(role: UserRoleType)
func updateStudentDetailEntity(entity: StudentDetailEntity)
func updateIsLoading(isLoading: Bool)
func updateIsDownloading(isDownloading: Bool)
func updateIsPresentedDreamBookExporter(isPresented: Bool)
func updateHWPDocument(hwpDocument: HWPDocument)
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,6 @@ struct StudentDetailView: View {
.frame(width: 24, height: 24)
}
.navigationBarHidden(true)
.fileExporter(
isPresented: Binding(
get: { state.isPresentedDreamBookExporter },
set: { _ in intent.dreamBookFileExporterDismissed() }
),
document: state.hwpDocument,
contentType: UTType(filenameExtension: "hwp") ?? .pdf,
defaultFilename: state.hwpFilename
) { result in
print(result)
}
}

// swiftlint: disable function_body_length
Expand All @@ -130,13 +119,6 @@ struct StudentDetailView: View {

Spacer()

SMSIcon(.book)
.buttonWrapper {
guard
let dreamBookURLString = studentDetail?.detailInfoByTeacher?.dreamBookFileURL
else { return }
intent.dreamBookDownloadButtonDidTap(dreamBookFileURL: dreamBookURLString)
}
}
} else {
SMSText(studentDetail?.major ?? "전공", font: .body1)
Expand Down

0 comments on commit 63d8ac9

Please sign in to comment.