diff --git a/app/threadline/TagView.swift b/app/threadline/TagView.swift index a9201bc..fd5bc60 100644 --- a/app/threadline/TagView.swift +++ b/app/threadline/TagView.swift @@ -8,12 +8,29 @@ import SwiftUI struct TagView: View { + @AppStorage("username") private var username: String = "" + @Environment(UrlStore.self) private var urlStore + @State private var tags: [String] = [] @State private var newTag: String = "" @State private var selectedCategory: String? = nil + @State private var selectedSubtype: String? = nil + @State private var selectedFit: String? = nil + @State private var selectedOccasion: String? = nil + @State private var selectedPrecip: String? = nil + @State private var isWinter: String? = nil let image: UIImage let categories = ["TOP", "BOTTOM", "OUTERWEAR", "DRESS", "SHOES"] + let topSubtypes = ["ACTIVE", "T-SHIRT", "POLO", "BUTTON DOWN", "HOODIE", "SWEATER"] + let bottomSubtypes = ["ACTIVE", "JEANS", "PANTS", "SHORTS", "SKIRT"] + let outerwearSubtypes = ["JACKET", "COAT"] + let dressSubtypes = ["MINI", "MIDI", "MAXI"] + let shoesSubtypes = ["ACTIVE", "SNEAKERS", "BOOTS", "SANDALS & SLIDES"] + let fits = ["LOOSE", "FITTED", "TIGHT"] + let occasions = ["ACTIVE", "CASUAL", "FORMAL"] + let precips = ["RAIN", "SNOW"] + let winterOptions = ["Winter", "Not Winter"] var body: some View { VStack { @@ -23,8 +40,6 @@ struct TagView: View { .frame(height: 200) .padding() - - HStack { TextField("Enter tag", text: $newTag) .textFieldStyle(RoundedBorderTextFieldStyle()) @@ -55,6 +70,53 @@ struct TagView: View { .pickerStyle(MenuPickerStyle()) .padding() + if let selectedCategory = selectedCategory { + Picker("Select Subtype", selection: $selectedSubtype) { + Text("Select Subtype").tag(String?.none) + ForEach(getSubtypes(for: selectedCategory), id: \.self) { subtype in + Text(subtype).tag(String?.some(subtype)) + } + } + .pickerStyle(MenuPickerStyle()) + .padding() + + Picker("Select Fit", selection: $selectedFit) { + Text("Select Fit").tag(String?.none) + ForEach(fits, id: \.self) { fit in + Text(fit).tag(String?.some(fit)) + } + } + .pickerStyle(MenuPickerStyle()) + .padding() + + Picker("Select Occasion", selection: $selectedOccasion) { + Text("Select Occasion").tag(String?.none) + ForEach(occasions, id: \.self) { occasion in + Text(occasion).tag(String?.some(occasion)) + } + } + .pickerStyle(MenuPickerStyle()) + .padding() + + Picker("Select Precipitation", selection: $selectedPrecip) { + Text("Select Precipitation").tag(String?.none) + ForEach(precips, id: \.self) { precip in + Text(precip).tag(String?.some(precip)) + } + } + .pickerStyle(MenuPickerStyle()) + .padding() + + Picker("Winter", selection: $isWinter) { + Text("Select Winter Option").tag(String?.none) + ForEach(winterOptions, id: \.self) { option in + Text(option).tag(option == "Winter" ? "True" : "False") + } + } + .pickerStyle(MenuPickerStyle()) + .padding() + } + ScrollView(.horizontal) { HStack { ForEach(tags, id: \.self) { tag in @@ -83,8 +145,7 @@ struct TagView: View { Button(action: { // Handle done action - print("Tags: \(tags)") - print("Selected Category: \(selectedCategory ?? "None")") + sendClothingData() }) { Text("Done") .padding(.horizontal) @@ -97,10 +158,74 @@ struct TagView: View { .disabled(selectedCategory == nil) } } + + func getSubtypes(for category: String) -> [String] { + switch category { + case "TOP": + return topSubtypes + case "BOTTOM": + return bottomSubtypes + case "OUTERWEAR": + return outerwearSubtypes + case "DRESS": + return dressSubtypes + case "SHOES": + return shoesSubtypes + default: + return [] + } + } + + func sendClothingData() { + guard let selectedCategory = selectedCategory, + let selectedFit = selectedFit, + let selectedOccasion = selectedOccasion else { + print("Required fields are missing") + return + } + + let payload: [String: Any] = [ + "type": selectedCategory, + "subtype": selectedSubtype ?? "", + "fit": selectedFit, + "occasion": selectedOccasion, + "precip": selectedPrecip ?? "", + "winter": isWinter ?? "False", + "tags": tags, + "username": username + ] + + guard let url = URL(string: "\(urlStore.serverUrl)/clothing/create") else { + print("Invalid URL") + return + } + var request = URLRequest(url: url) + request.httpMethod = "POST" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + + do { + request.httpBody = try JSONSerialization.data(withJSONObject: payload, options: []) + } catch { + print("Error serializing JSON: \(error)") + return + } + + URLSession.shared.dataTask(with: request) { data, response, error in + if let error = error { + print("Error sending clothing data: \(error)") + return + } + if let response = response as? HTTPURLResponse, response.statusCode == 200 { + print("Clothing data sent successfully") + } else { + print("Failed to send clothing data") + } + }.resume() + } } struct TagView_Previews: PreviewProvider { static var previews: some View { TagView(image: UIImage(named: "sampleImage") ?? UIImage()) } -} +} \ No newline at end of file diff --git a/backend/apps/core/views.py b/backend/apps/core/views.py index 15bfba4..1f53ca4 100644 --- a/backend/apps/core/views.py +++ b/backend/apps/core/views.py @@ -17,7 +17,8 @@ @require_method('POST') def create_clothing(request): ## Validate and extract request fields - fields = request.POST + fields = json.loads(request.body.decode('utf-8')) + print(fields) if "username" in fields: username = fields["username"]