Skip to content

Commit

Permalink
Image
Browse files Browse the repository at this point in the history
  • Loading branch information
doyeonk429 committed Aug 16, 2024
1 parent 7a1a9ac commit 58560ff
Show file tree
Hide file tree
Showing 21 changed files with 610 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Drink-EG/Drink-EG/Resources/APIs/SearchAPI 2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// SearchAPI.swift
// Drink-EG
//
// Created by 이현주 on 8/16/24.
//

import Foundation
import Moya

// JWT 토큰을 받을 수 있도록 BasicAPI 정의
/// 기능 하나 당 API 1개씩 만들기
/// - API 명세서 기준으로 1 명세서 당 1 API enum 정의하기
/// - 변경을 한 번 더 해보자.

enum SearchAPI {
case getWineName(wineName: String)
case getWineInfo(wineId: Int)
case getWineReview(wineId: Int)
}

extension SearchAPI: TargetType {
var baseURL: URL {
/// 기본 URL 작성
return URL(string: "https://drinkeg.com/")!

}

var path: String {
/// 기본 URL + path 로 URL 구성
switch self {
/// 동일한 path는 한 case로 처리 가능
case .getWineName:
return "wine"
case .getWineInfo(let wineId):
return "wine/\(wineId)"
case .getWineReview(let wineId):
return "wine/review/\(wineId)"
}
}

var method: Moya.Method {
/// 각 case 별로 적합한 method 배정
switch self {
case .getWineName, .getWineInfo, .getWineReview:
return .get
}
}

var task: Task {
switch self {
case .getWineName(let wineName):
return .requestParameters(parameters: ["searchName": wineName], encoding: URLEncoding.queryString)
case .getWineInfo, .getWineReview:
return .requestPlain
}
}

// API 호출 시, header에 token 넣어서 전달
var headers: [String : String]? {
let jwtToken = "jwt_token_here"
return [
"Authorization": "Bearer \(jwtToken)",
"Content-type": "application/json"
]
}

var validationType: ValidationType {
return .successCodes
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Group 415.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Group [email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Group [email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Group 415.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Group [email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Group [email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Vector.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions Drink-EG/Drink-EG/Sources/Datas/Search/WineInfoResponse 2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// WineInfoResponse.swift
// Drink-EG
//
// Created by 이현주 on 8/16/24.
//

import Foundation

struct WineInfo: Decodable {
let wineId: Int
let name: String
let imageUrl: String?
let price: Int
let sort: String
let area: String
let sugarContent: Int
let acidity: Int
let tannin: Int
let body: Int
let alcohol: Int
let scentAroma: [String]
let scentTaste: [String]
let scentFinish: [String]
let rating: Double
}
16 changes: 16 additions & 0 deletions Drink-EG/Drink-EG/Sources/Datas/Search/WineSearchResponse 2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// WineSearchResponse.swift
// Drink-EG
//
// Created by 이현주 on 8/16/24.
//

import Foundation

struct Wine: Decodable {
let wineId: Int
let name: String
let imageUrl: String?
let rating: Double
let price: Int
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// APIResponseWineInfoResponse.swift
// Drink-EG
//
// Created by 이현주 on 8/16/24.
//

import Foundation

struct APIResponseWineInfoResponse: Decodable {
let isSuccess: Bool
let code: String
let message: String
let result: WineInfo
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// APIResponseWineSearchResponse.swift
// Drink-EG
//
// Created by 이현주 on 8/16/24.
//

import Foundation

struct APIResponseWineSearchResponse: Decodable {
let isSuccess: Bool
let code: String
let message: String
let result: [Wine]
}
49 changes: 49 additions & 0 deletions Drink-EG/Drink-EG/Sources/Models/SelectionManager 2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SelectionManager.swift
// Drink-EG
//
// Created by 김도연 on 8/14/24.
//

import Foundation

class SelectionManager {
static let shared = SelectionManager()

var isNewbie : Bool = false
var monthPrice : Int = 0
var userName : String = ""
var userAddr : String = ""

var wineSort : [String] = []
var wineNation : [String] = []
var wineVariety : [String] = []

private init() {}

func setNewbie(answer : Bool) {
isNewbie = answer
}

func setPrice(answer : Int) {
monthPrice = answer
}

func setName(answer : String) {
userName = answer
}

func setWineSort(answer : [String]) {
wineSort = answer
}

func setWineNation(anser: [String]) {
wineNation = anser
}

func setWineVariety(anser: [String]) {
wineVariety = anser
}

// func setWine(answer : )
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//
// ReviewListCollectionViewCell.swift
// Drink-EG
//
// Created by 이현주 on 8/15/24.
//

import UIKit
import SnapKit

class ReviewListCollectionViewCell: UICollectionViewCell {

var score = 4.5
private let scoreLabel = UILabel()

private let name: UILabel = {
let l = UILabel()
l.font = .boldSystemFont(ofSize: 16)
l.textColor = .black
l.numberOfLines = 1 // 한 줄로 표시
l.adjustsFontSizeToFitWidth = true // 텍스트가 레이블 너비에 맞도록 크기 조정
l.minimumScaleFactor = 0.5 // 텍스트 크기가 최소 50% 까지 줄어들 수 있음
return l
}()

private let stick: UIView = {
let v = UIView()
v.backgroundColor = UIColor(hex: "#FA735B")
return v
}()

private let content: UILabel = {
let l = UILabel()
l.font = .boldSystemFont(ofSize: 12)
l.textColor = UIColor(hex: "767676")
l.text = "맛있어요."
l.numberOfLines = 0
return l
}()

private func configureScore() {
scoreLabel.text = "\(score)"
scoreLabel.font = .boldSystemFont(ofSize: 14)
scoreLabel.textColor = UIColor(hex: "#FB5133")
}

override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

//레이아웃까지
private func setupUI() {
configureScore()

self.contentView.addSubview(name)
self.contentView.addSubview(stick)
self.contentView.addSubview(scoreLabel)
self.contentView.addSubview(content)
self.contentView.backgroundColor = UIColor(hex: "F8F8FA")
self.contentView.layer.borderWidth = 0
self.contentView.layer.cornerRadius = 10
self.contentView.layer.masksToBounds = true

stick.snp.makeConstraints { make in
make.top.bottom.equalToSuperview().inset(13)
make.leading.equalToSuperview().offset(94)
make.width.equalTo(1)
}

name.snp.makeConstraints { make in
make.top.equalToSuperview().offset(15)
make.centerX.equalTo(contentView.snp.leading).offset(47)
make.width.lessThanOrEqualTo(70)
}

content.snp.makeConstraints { make in
make.top.equalToSuperview().offset(13)
make.leading.equalTo(stick.snp.trailing).offset(22)
make.width.lessThanOrEqualTo(234)
make.height.lessThanOrEqualTo(88)
}

scoreLabel.snp.makeConstraints { make in
make.bottom.equalToSuperview().inset(14)
make.centerX.equalTo(name)
}
}

func configure(name: String) {
self.name.text = name
}
}
Loading

0 comments on commit 58560ff

Please sign in to comment.