[2024 GDSC] Wetox-iOS Project API ์—ฐ๋™

2024. 2. 22. 21:52ใ†Experiences/Competition

 

 

 

 

 

2024 Google Solution Challenge

https://github.com/GDSC-Wetox/Wetox-iOS

 

GitHub - GDSC-Wetox/Wetox-iOS: GDSC-Hongik Wetox iOS

GDSC-Hongik Wetox iOS . Contribute to GDSC-Wetox/Wetox-iOS development by creating an account on GitHub.

github.com

๋งค์ผ๋งค์ผ ๊ฐœ๋ฐœ๋กœ ๋ถˆํƒœ์šฐ๋Š” ์ค‘์ž…๋‹ˆ๋‹ค. . ๐Ÿ‘ฉ‍๐Ÿš’๐Ÿ”ฅ

๋“œ๋””์–ด ์„œ๋ฒ„ API ์—ฐ๋™์„ ์™„๋ฃŒํ–ˆ๋‹ต๋‹ˆ๋‹ค!! ๊บ„์šธ 

๋‚จ์€ ๊ฒƒ์€ ๋ฐœํ‘œ ์˜์ƒ ์ค€๋น„ ๋ฟ . 

์ •๋ง ๋„คํŠธ์›Œํฌ ์—ฐ๋™ ์ฝ”๋“œ ์งœ๋Š” ๊ธฐ๊ณ„๊ฐ€ ๋˜์—ˆ์–ด์š” . . 

์ œ์ถœ ๋๋‚ด๊ณ , MVVM ๋ฆฌํŒฉํ† ๋ง๋„ ๊ผฌ์˜ฅ ํ•ด์•ผ์ง‘ 

๋ฆฌ์•กํŠธ ์ฝ”๋“œ๋„ ์ œ๋Œ€๋กœ ๊ณต๋ถ€ํ•˜๊ณ  ๋‹ค์‹œ ์งœ๊ณ  ์‹ถ์–ด์š”

 

 

 

 

 

# ์ž”๋””๋ฐญ ํ’๋…„ ๐ŸŒฑ

2์›”์„ ํƒœ์› ์–ด์š” โ„๏ธ

 

 

 

 

 

# ๋‹‰๋„ค์ž„ ์ค‘๋ณต ๊ฒ€์‚ฌ API 

UI Button๋„ ๋„คํŠธ์›Œํฌ response์— ๋”ฐ๋ผ ์ƒ‰์ƒ ๋ฐ”๋€Œ๊ฒŒ ๊ตฌํ˜„ํ–ˆ๊ตฌ์š”,, 

 

 

 

 

 

# ์นœ๊ตฌ ์š”์ฒญ ๋ฐ ์ˆ˜๋ฝ  API

๐Ÿ•บ ์นœ๊ตฌ ์š”์ฒญ ์ˆ˜๋ฝ๋„ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค (๊ฑฐ์ ˆ์€ ์—†๋‹ค.)

 

 

 

 

 

# AI ์ƒ์„ฑ ํ”„๋กœํ•„ ๊ฐ€์ ธ์˜ค๊ธฐ API

 

 

 

์ด ์นœ๊ตฌ ๊ตฌํ˜„ํ•˜๋Š”๋ฐ ๊ฝค๋‚˜ ๊ณ ๋ฏผํ–ˆ์ˆ˜ ๐Ÿค”

์„œ๋ฒ„์—์„œ ๋ณด๋‚ด๋Š” ๊ฐ’์ด URL ์ฃผ์†Œ๋‚˜ JSON์ด ์•„๋‹ˆ๋ผ,

PNG ๋ฐ์ดํ„ฐ๋ฅผ ๊ทธ๋Œ€๋กœ ์˜๋Š”๋ฐ, ์ด๊ฑธ ๋ฐ›์•„์˜ฌ ๋•Œ,

Observable์— response ๊ฐ์ฒด๋ฅผ ์„ ์–ธํ•ด์„œ ๋ฐ›๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ

Data ๋ฐ”๋กœ ๋ฐ›์•„์˜ค๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•ด์•ผ ํ–ˆ์–ด์š” 

 

 

 

public class RegisterAPI {
    static let registerProvider = MoyaProvider<RegisterService>(plugins: [MoyaLoggerPlugin()])
    
    static func postNicknameValidRequest(nickname: NicknameValidRequest) -> Observable<NicknameValidResponse> {
        let decoder = JSONDecoder()
        decoder.dateDecodingStrategy = .formatted(DateFormatter().mapDateFormat())
        
        return registerProvider.rx.request(.postNicknameValidRequest(nickname: nickname))
            .map(NicknameValidResponse.self, using: decoder)
            .asObservable()
            .catch { error in
                if let moyaError = error as? MoyaError {
                    switch moyaError {
                    case .statusCode(let response):
                        print("HTTP Status Code: \(response.statusCode)")
                    case .jsonMapping(let response):
                        print("JSON Mapping Error for Response: \(response)")
                    default:
                        print("Other MoyaError: \(moyaError.localizedDescription)")
                    }
                }
                return Observable.error(error)
            }
    }
    
    static func getAIProfileImage() -> Observable<Data> {
            return registerProvider.rx.request(.getAIImage)
                .map { response -> Data in
                    return response.data
                }
                .asObservable()
                .catch { error in
                    if let moyaError = error as? MoyaError {
                        switch moyaError {
                        case .statusCode(let response):
                            print("HTTP Status Code: \(response.statusCode)")
                        default:
                            print("Other MoyaError: \(moyaError.localizedDescription)")
                        }
                    }
                    return Observable.error(error)
                }
        }
}

 

๋ญ”๊ฐ€. . ๋‘ func ์˜ ์ฐจ์ด๊ฐ€ ๋Š๊ปด์ง€์ง€์š” . . ๐Ÿ‘ฉ‍๐Ÿš€

๊ธฐ๊ณ„์‹ ์ฝ”๋”ฉํ•˜๋‹ค๊ฐ€ ํ•œ ๋ฐœ ์ฃผ์ถคํ–ˆ๋˜ ํŒŒํŠธ 

ํ•œ ๋‘ ๋ฒˆ ๊ตฌํ˜„ํ•ด๋‘๋ฉด ๋‹ค๋ฅธ์• ๋“ค์€ ์„œ๋กœ ๊ตฌ์กฐ๊ฐ€ ์Šท๋น„์Šท๋น„ ํ–ˆ๊ฑฐ๋“ฑ์š” 

 

 

 

 

 

๋ฉ”์ธ UI ๋ฒ„ํŠผ ์ปฌ๋Ÿฌ๋„ ์ชผ๋” ๋ฐ”๊ฟจ๊ตฌ์š”,, ์•ฑ ์•„์ด์ฝ˜ ๋„˜๋‚˜ ๊ท€์—ฝ์ฃ ? 

 

 

 

 

 

๋งˆ๊ฐ๊นŒ์ง€ ํ™”์ดํŒ…ํŒ…!!