Skip to content

Commit

Permalink
[refactor] #12 SendProfileUseCase 구현
Browse files Browse the repository at this point in the history
Co-Authored-By: YOON JI SEONG <[email protected]>
  • Loading branch information
Kelly-Chui and green-yoon87 committed Jan 14, 2025
1 parent ec0bfc7 commit 7ec5950
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// SendProfileUseCase.swift
// SniffMeet
//
// Created by Kelly Chui on 1/14/25.
//

import Foundation

protocol SendProfileUseCase {
func execute()
}

struct SendProfileUseCaseImpl: SendProfileUseCase {
let dataManager: DataLoadable
let niManager: NIManager
let encoder: JSONEncoder

init(
dataManager: DataLoadable,
niManager: NIManager
) {
self.dataManager = dataManager
self.niManager = niManager
self.encoder = JSONEncoder()
}

func execute() {
do {
let dog = try dataManager.loadData(forKey: "dogInfo", type: UserInfo.self)
guard let userID = SessionManager.shared.session?.user?.userID else { return }
let dogProfileDTO = DogProfileDTO(
id: userID,
name: dog.name,
keywords: dog.keywords,
profileImage: dog.profileImage
)
let dataToSend = MPCProfileDropDTO(token: nil, profile: dogProfileDTO, transitionMessage: nil)
let encodedData = try encoder.encode(dataToSend)
niManager.mpcManager.sendData(data: encodedData)


} catch {
SNMLogger.error("loadData error : \(error)")
}
}
}

0 comments on commit 7ec5950

Please sign in to comment.