Skip to content

Commit

Permalink
Merge pull request #123 from DeveloperAcademy-POSTECH/hofix/auth/ZES-175
Browse files Browse the repository at this point in the history
[Hotfix] ์„œ๋ฒ„API ๋ณ€๋™์— ๋”ฐ๋ฅธ ์˜ค๋ฅ˜ ์ˆ˜์ •
  • Loading branch information
chaneeii authored Nov 23, 2022
2 parents 498acc6 + 1767bcc commit 6c3a9e3
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class VerifingCodeUseCase {
func postSignUp(email: String, orgnization: Organization) {
guard let authorization = KeyChainManager.read(key: .authToken) else { return }

let userDTO = SignUpUserDTO(id: orgnization.id, email: email, organizationName: orgnization.name)
let userDTO = SignUpUserDTO(email: email, organizationName: orgnization.name)

UserAPI.postSignUp(authorization: authorization, userDTO: userDTO)
.sink { [weak self] error in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Network

protocol AddPlaceUseCaseType {
func searchKakaoPlaces(with name: String) -> AnyPublisher<[KakaoPlace], Error>
// func checkRegisterdPlace(with kakaoPlaceId: Int) -> AnyPublisher<Bool, Error>
func checkRegisterdPlace(with kakaoPlaceId: Int) -> AnyPublisher<Bool, AddPlaceError>
func fetchCategories() -> AnyPublisher<[Category], Error>
func addNewPlace(with place: KakaoPlace, category: Int) -> AnyPublisher<PlaceResult, Error>
Expand All @@ -29,7 +28,7 @@ final class AddPlaceUseCase: AddPlaceUseCaseType {
func addNewPlace(with place: KakaoPlace, category: Int) -> AnyPublisher<PlaceResult, Error> {

let user = UserInfoManager.userInfo?.userID ?? 64
let org = UserInfoManager.userInfo?.userOrganization ?? 400
let org = UserInfoManager.userInfo?.userOrganization[0] ?? 400
let placeDTO = PlacePostDTO(address: place.address,
name: place.placeName,
latitude: place.lat,
Expand Down Expand Up @@ -91,7 +90,9 @@ final class AddPlaceUseCase: AddPlaceUseCaseType {
*/

func checkRegisterdPlace(with kakaoPlaceId: Int) -> AnyPublisher<Bool, AddPlaceError> {
PlaceAPI.checkRegisterdPlace(kakaoPlaceId: kakaoPlaceId)
guard let orgId = UserInfoManager.userInfo?.userOrganization else { return Fail(error: AddPlaceError.none).eraseToAnyPublisher() }

return PlaceAPI.checkRegisterdPlace(kakaoPlaceId: kakaoPlaceId, orgId: orgId[0])
.mapError { _ -> AddPlaceError in
return .none
}.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ final class PlaceSearchUseCase: PlaceSearchUseCaseType {

func searchPlaces(with placeName: String) -> AnyPublisher<[Place], Error> {

// TODO: ORG-ID ๋„ฃ๊ณ  ๊ต์ฒด ํ•„์š”
let orgId = UserInfoManager.userInfo?.userOrganization ?? 400
let orgId = UserInfoManager.userInfo?.userOrganization[0] ?? 400

PlaceAPI.fetchSearchPlaceResults(orgId: orgId, placeName: placeName)
.sink { error in
Expand Down
6 changes: 4 additions & 2 deletions Projects/App/Sources/Domain/Place/PlaceUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ final class PlaceListUseCase {
func fetchPlaceList(with page: Int, type: PlaceType) -> AnyPublisher<[Place], NetworkError> {
let api: AnyPublisher<PlaceListDTO, NetworkError>

guard let authorization = KeyChainManager.read(key: .authToken) else { return Fail(error: NetworkError.unauthorized("๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค")).eraseToAnyPublisher() }

switch type {
case .whole:
api = PlaceAPI.fetchPlaceList(with: page)
api = PlaceAPI.fetchPlaceList(with: page, authorization: authorization)
case .hot:
api = PlaceAPI.fetchHotPlaceList(with: page)
api = PlaceAPI.fetchHotPlaceList(with: page, authorization: authorization)
}

return api
Expand Down
10 changes: 5 additions & 5 deletions Projects/App/Sources/Domain/User/UserInfoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class UserInfoManager {

struct UserInfo: Codable {

init(userNickname: String? = nil, userID: Int? = nil, userOrganization: Int? = nil, userOrgName: String? = nil ) {
init(userNickname: String? = nil, userID: Int? = nil, userOrganization: [Int] = [], userOrgName: String? = nil ) {
UserInfoManager.userInfo?.userNickname = userNickname
UserInfoManager.userInfo?.userID = userID
UserInfoManager.userInfo?.userOrganization = userOrganization
Expand Down Expand Up @@ -48,10 +48,10 @@ final class UserInfoManager {
UserDefaults.standard.set(newValue, forKey: UserInfoKeys.userID.rawValue)
}
}
var userOrganization: Int? {
var userOrganization: [Int] {
get {
guard let userOrganization = UserDefaults.standard.value(forKey: UserInfoKeys.userOrganization.rawValue) as? Int else {
return nil
guard let userOrganization = UserDefaults.standard.value(forKey: UserInfoKeys.userOrganization.rawValue) as? [Int] else {
return []
}
return userOrganization
}
Expand Down Expand Up @@ -93,7 +93,7 @@ final class UserInfoManager {
UserInfoManager.userInfo = UserInfo()
}

static func initialUserInfo(userNickname: String?, userID: Int?, userOrganization: Int?, userOrgName: String?) {
static func initialUserInfo(userNickname: String?, userID: Int?, userOrganization: [Int], userOrgName: String?) {
UserInfoManager.userInfo = UserInfo()
UserInfoManager.userInfo?.userNickname = userNickname
UserInfoManager.userInfo?.userID = userID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class DomainSettingViewController: UIViewController {
let orgID = viewModel.organization.id
let orgName = viewModel.organization.name
UserInfoManager.userInfo?.userOrgName = orgName
UserInfoManager.userInfo?.userOrganization = orgID
UserInfoManager.userInfo?.userOrganization = [orgID]
navigationController?.pushViewController(DomainSettingCompleteViewController(), animated: true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class OrgDetailViewController: UIViewController {
private let orgInformationStackView3 = UIStackView()
private let orgInfoImageView1 = UIImageView()
private let orgInfoImageView2 = UIImageView()
private let orgInfoImageView3 = UIImageView()
// private let orgInfoImageView3 = UIImageView()
private let orgInviteButton = FullWidthBlackButton()

private var orgDetailInformationView1 = OrgDetailInformationView()
Expand Down Expand Up @@ -121,7 +121,7 @@ extension OrgDetailViewController {
orgDetailInformationView2 = OrgDetailInformationView()
orgDetailInformationView3 = OrgDetailInformationView()

orgNameLabel.text = "์• ํ”Œ ๋””๋ฒจ๋กœํผ ์•„์นด๋ฐ๋ฏธ"
orgNameLabel.text = UserInfoManager.userInfo?.userOrgName ?? "(์ธ์ฆ๋Œ€ํ•™์—†์Œ)"
orgNameLabel.textColor = .black
orgNameLabel.font = UIFont.systemFont(ofSize: CGFloat(26), weight: .bold)
orgNameLabel.textAlignment = .center
Expand Down Expand Up @@ -158,11 +158,12 @@ extension OrgDetailViewController {
orgDetailInformationView2.informationLabel.text = "๋“ฑ๋ก๋œ ๋ง›์ง‘"
orgDetailInformationView2.numberLabel.text = "0๊ณณ"

orgInfoImageView3.image = UIImage(.img_reviewfriends_photo)
orgInfoImageView3.contentMode = .scaleAspectFit
orgInfoImageView3.layer.applyFigmaShadow(color: .black, opacity: 0.1, xCoord: 0, yCoord: 0, blur: 5, spread: 0)
orgDetailInformationView3.informationLabel.text = "์—…๋กœ๋“œ๋œ ์‚ฌ์ง„"
orgDetailInformationView3.numberLabel.text = "0๊ฐœ"
// TODO: - ๋ฐฑ์—”๋“œ ์ž‘์—… ์™„๋ฃŒ ํ›„ ๋ณต๊ตฌ
// orgInfoImageView3.image = UIImage(.img_reviewfriends_photo)
// orgInfoImageView3.contentMode = .scaleAspectFit
// orgInfoImageView3.layer.applyFigmaShadow(color: .black, opacity: 0.1, xCoord: 0, yCoord: 0, blur: 5, spread: 0)
// orgDetailInformationView3.informationLabel.text = "์—…๋กœ๋“œ๋œ ์‚ฌ์ง„"
// orgDetailInformationView3.numberLabel.text = "0๊ฐœ"

orgInviteButton.setTitle("์šฐ๋ฆฌํ•™๊ต ์‚ฌ๋žŒ๋“ค ์ดˆ๋Œ€ํ•˜๊ธฐ", for: .normal)
orgInviteButton.addTarget(self, action: #selector(shareAppStoreLink), for: .touchUpInside)
Expand All @@ -173,7 +174,7 @@ extension OrgDetailViewController {
orgInformationSuperStackView.addArrangedSubviews([orgInformationStackView1, orgInformationStackView2, orgInformationStackView3])
orgInformationStackView1.addArrangedSubviews([orgInfoImageView1, orgDetailInformationView1])
orgInformationStackView2.addArrangedSubviews([orgInfoImageView2, orgDetailInformationView2])
orgInformationStackView3.addArrangedSubviews([orgInfoImageView3, orgDetailInformationView3])
// orgInformationStackView3.addArrangedSubviews([orgInfoImageView3, orgDetailInformationView3])

orgNameLabel.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide).inset(30)
Expand Down Expand Up @@ -206,9 +207,9 @@ extension OrgDetailViewController {
make.width.height.equalTo(60)
}

orgInfoImageView3.snp.makeConstraints { make in
make.width.height.equalTo(60)
}
// orgInfoImageView3.snp.makeConstraints { make in
// make.width.height.equalTo(60)
// }

orgInviteButton.snp.makeConstraints { make in
make.horizontalEdges.bottom.equalTo(view.safeAreaLayoutGuide).inset(20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extension VerifingCodeViewModel {
let orgID = self.organization.id
let orgName = self.organization.name
UserInfoManager.userInfo?.userOrgName = orgName
UserInfoManager.userInfo?.userOrganization = orgID
UserInfoManager.userInfo?.userOrganization = (UserInfoManager.userInfo?.userOrganization ?? []) + [orgID]
}
self.isEmailOverlapedSubject.send(isEmailOverlaped)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,21 @@ extension PlaceListViewController: QuestionButtonTapDelegate, UIAdaptivePresenta
func addPlaceButtonTapped() {
navigationController?.pushViewController(AddPlaceSearchViewController(viewModel: AddPlaceSearchViewModel()), animated: true)
}

@objc func orgDetailButtonTapped() {
navigationController?.pushViewController(OrgDetailViewController(viewModel: OrgDetailViewModel(orgId: UserInfoManager.userInfo?.userOrganization ?? 400)), animated: true)

@objc func orgDetailButtonTapped() throws {

if let orgId = UserInfoManager.userInfo?.userOrganization.first {
navigationController?.pushViewController(OrgDetailViewController(viewModel: OrgDetailViewModel(orgId: orgId)),
animated: true)
} else {
let alert = UIAlertController(title: "์ธ์ฆ๋Œ€ํ•™์—†์Œ",
message: "๋“ฑ๋ก๋˜์–ด ์žˆ๋Š” ๋Œ€ํ•™ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "๋‹ซ๊ธฐ", style: .default)
alert.addAction(okAction)
self.present(alert, animated: false)
}

FirebaseAnalytics.Analytics.logEvent(AnalyticsEventSelectItem, parameters: [
AnalyticsParameterItemListName: "org_detail_button"
])
Expand Down Expand Up @@ -241,7 +253,7 @@ extension PlaceListViewController {
let placeTitle = UILabel()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(orgDetailButtonTapped))

placeTitle.text = "์• ํ”Œ๋””๋ฒจ๋กœํผ์•„์นด๋ฐ๋ฏธ"
placeTitle.text = UserInfoManager.userInfo?.userOrgName ?? "(์ธ์ฆ๋Œ€ํ•™์—†์Œ)"
placeTitle.font = .systemFont(ofSize: 17, weight: .bold)
placeTitle.isUserInteractionEnabled = true
placeTitle.addGestureRecognizer(tapGesture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class ExplanationPopOverViewController: UIViewController {
// MARK: - Properties
private var explanationLabel = UILabel()


// MARK: - LifeCycle

override func viewDidLoad() {
Expand Down
13 changes: 7 additions & 6 deletions Projects/Network/Sources/API/PlaceAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public struct PlaceAPI {

static let networkService = NetworkService()

public static func fetchPlaceList(with page: Int) -> AnyPublisher<PlaceListDTO, NetworkError> {
let header = ["Content-Type": "application/json"]
public static func fetchPlaceList(with page: Int, authorization: String) -> AnyPublisher<PlaceListDTO, NetworkError> {
let header = ["Content-Type": "application/json", "Authorization": "\(authorization)"]
let query = ["cursor": "\(page)"]
let endpoint = Endpoint(path: "/api/places", queryParams: query, headers: header)

return networkService.request(with: endpoint, responseType: PlaceListDTO.self)
}

public static func fetchHotPlaceList(with page: Int) -> AnyPublisher<PlaceListDTO, NetworkError> {
let header = ["Content-Type": "application/json"]
public static func fetchHotPlaceList(with page: Int, authorization: String) -> AnyPublisher<PlaceListDTO, NetworkError> {
let header = ["Content-Type": "application/json", "Authorization": "\(authorization)"]
let query = ["cursor": "\(page)"]
let endpoint = Endpoint(path: "/api/places/goods", queryParams: query, headers: header)

Expand All @@ -37,10 +37,11 @@ public struct PlaceAPI {
return networkService.request(with: endpoint, responseType: KakaoPlaceListDTO.self)
}

public static func checkRegisterdPlace(kakaoPlaceId: Int) -> AnyPublisher<Bool, NetworkError> {
public static func checkRegisterdPlace(kakaoPlaceId: Int, orgId: Int) -> AnyPublisher<Bool, NetworkError> {

let header = ["Content-Type": "application/json"]
let endpoint = Endpoint(path: "/api/places/kakaoPlace/\(kakaoPlaceId)/registered", headers: header)
let query = ["organizationId": "\(orgId)"]
let endpoint = Endpoint(path: "/api/places/kakaoPlace/\(kakaoPlaceId)/registered", queryParams: query, headers: header)

return networkService.request(with: endpoint, responseType: Bool.self)
}
Expand Down
2 changes: 0 additions & 2 deletions Projects/Network/Sources/API/UserAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public struct UserAPI {
let header = ["Content-Type": "application/json", "Authorization": "\(authorization)"]
let user = ["email": userDTO.email, "organizationName": userDTO.organizationName]
let endpoint = Endpoint(path: "/api/users", method: .post, bodyParams: user, headers: header)

return networkService.request(with: endpoint)
}

Expand Down Expand Up @@ -77,7 +76,6 @@ public struct UserAPI {
public static func postSendCode(email: String) -> AnyPublisher<Bool, NetworkError> {
let header = ["Content-Type": "application/json"]
let endpoint = Endpoint(path: "/api/users/send/verifyCode", method: .post, bodyParams: ["email": email], headers: header)

return networkService.request(with: endpoint)
}

Expand Down
4 changes: 1 addition & 3 deletions Projects/Network/Sources/DTO/RequestDTO/SignUpUserDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import Foundation

public struct SignUpUserDTO: Encodable {
public let id: Int
public let email: String
public let organizationName: String

public init(id: Int, email: String, organizationName: String) {
self.id = id
public init(email: String, organizationName: String) {
self.email = email
self.organizationName = organizationName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct UserProfileDTO: Decodable {
public let nickname: String?
public let email: String?
public let social: String
public let organization: Int?
public let organization: [Int]
public let deletedAt: String?
public let createdAt: String
public let updatedAt: String
Expand Down
2 changes: 1 addition & 1 deletion Projects/Network/Sources/Service/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension NetworkService {
-> AnyPublisher<T, NetworkError> {
do {
let request = try endpoint.urlRequest()

return session.dataTaskPublisher(for: request)
.tryMap({ (data, response) in
if let error = self.checkError(data: data, response: response) {
Expand Down

0 comments on commit 6c3a9e3

Please sign in to comment.