Skip to content

Commit

Permalink
[#129] 카테고리 뷰 수정
Browse files Browse the repository at this point in the history
- (updatedAt) 공고 업데이트된 순서대로 정렬
- 이미지 API 연결(새 공고 작성, 카테고리)
  • Loading branch information
ubeeni committed Feb 18, 2024
1 parent d68d7a9 commit 0d88cfe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Spon-us.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
100D38B82B4EF54100498977 /* CategoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 100D38B72B4EF54100498977 /* CategoryView.swift */; };
100D38BA2B4EF54C00498977 /* MyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 100D38B92B4EF54C00498977 /* MyView.swift */; };
1031EC7C2B68B9F20016655B /* AnnouncementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1031EC7B2B68B9F20016655B /* AnnouncementView.swift */; };
10584CC02B81EE84007F7A3F /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 10584CBF2B81EE84007F7A3F /* GoogleService-Info.plist */; };
106720022B5835FA00493354 /* SendOfferView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 106720012B5835FA00493354 /* SendOfferView.swift */; };
107D6E692B7A8273005B6261 /* OrganizationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 107D6E682B7A8273005B6261 /* OrganizationModel.swift */; };
107D6E6B2B7A83AB005B6261 /* MyOrganizationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 107D6E6A2B7A83AB005B6261 /* MyOrganizationViewModel.swift */; };
Expand Down Expand Up @@ -121,7 +122,6 @@
DF498F2C2B7CDDB200ADE078 /* MyAnnouncementsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2B2B7CDDB200ADE078 /* MyAnnouncementsViewModel.swift */; };
DF498F2E2B7DF4F600ADE078 /* LogoutModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */; };
DF498F302B7DF50200ADE078 /* LogoutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */; };
DF5AB1522B81ED890061F421 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DF5AB1512B81ED880061F421 /* GoogleService-Info.plist */; };
DF5B7E922B7FA430001C009C /* PortfolioOfferViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5B7E912B7FA430001C009C /* PortfolioOfferViewModel.swift */; };
DF5B7E942B808DF1001C009C /* EditAnnouncementViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5B7E932B808DF0001C009C /* EditAnnouncementViewModel.swift */; };
DF5B7E962B809257001C009C /* EditAnnouncementModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5B7E952B809257001C009C /* EditAnnouncementModel.swift */; };
Expand Down Expand Up @@ -169,6 +169,7 @@
100D38B72B4EF54100498977 /* CategoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryView.swift; sourceTree = "<group>"; };
100D38B92B4EF54C00498977 /* MyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyView.swift; sourceTree = "<group>"; };
1031EC7B2B68B9F20016655B /* AnnouncementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnouncementView.swift; sourceTree = "<group>"; };
10584CBF2B81EE84007F7A3F /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../Desktop/GoogleService-Info.plist"; sourceTree = "<group>"; };
106720012B5835FA00493354 /* SendOfferView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendOfferView.swift; sourceTree = "<group>"; };
107D6E682B7A8273005B6261 /* OrganizationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrganizationModel.swift; sourceTree = "<group>"; };
107D6E6A2B7A83AB005B6261 /* MyOrganizationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyOrganizationViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -223,7 +224,6 @@
DF498F2B2B7CDDB200ADE078 /* MyAnnouncementsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyAnnouncementsViewModel.swift; sourceTree = "<group>"; };
DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutModel.swift; sourceTree = "<group>"; };
DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutViewModel.swift; sourceTree = "<group>"; };
DF5AB1512B81ED880061F421 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
DF5B7E912B7FA430001C009C /* PortfolioOfferViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortfolioOfferViewModel.swift; sourceTree = "<group>"; };
DF5B7E932B808DF0001C009C /* EditAnnouncementViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAnnouncementViewModel.swift; sourceTree = "<group>"; };
DF5B7E952B809257001C009C /* EditAnnouncementModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAnnouncementModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -364,7 +364,7 @@
100D387F2B44826500498977 /* Spon-us */ = {
isa = PBXGroup;
children = (
DF5AB1512B81ED880061F421 /* GoogleService-Info.plist */,
10584CBF2B81EE84007F7A3F /* GoogleService-Info.plist */,
80B41FFF2B77F0DF0021DD90 /* Spon-us.entitlements */,
100D389F2B44833F00498977 /* Info.plist */,
3B36F09F2B6FEBCB0000ACFB /* PortOne */,
Expand Down Expand Up @@ -740,11 +740,11 @@
files = (
3B81BCC02B6231680067E9CB /* ProductList.plist in Resources */,
100D389C2B44833500498977 /* SUIT-Medium.otf in Resources */,
DF5AB1522B81ED890061F421 /* GoogleService-Info.plist in Resources */,
3B81BCBE2B62312C0067E9CB /* Product.storekit in Resources */,
100D38A32B44834700498977 /* Preview Assets.xcassets in Resources */,
100D389E2B44833500498977 /* Pretendard-SemiBold.otf in Resources */,
100D38AD2B44844F00498977 /* Assets.xcassets in Resources */,
10584CC02B81EE84007F7A3F /* GoogleService-Info.plist in Resources */,
100D389B2B44833500498977 /* SUIT-Bold.otf in Resources */,
100D389D2B44833500498977 /* Pretendard-Medium.otf in Resources */,
);
Expand Down
28 changes: 14 additions & 14 deletions Spon-us/Model/Category/CategoryModelData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ class CategoryModelData: ObservableObject {
provider.request(.getCategory(category: category, type: type)) { result in
switch result {
case .success(let response):
if let jsonString = String(data: response.data, encoding: .utf8) {
print("서버 응답 JSON 데이터: \(jsonString)")
}

do {
let categoryModelData = try JSONDecoder().decode(CategoryModel.self, from: response.data)
DispatchQueue.main.async {
self.categoryModelDatas = categoryModelData.content
self.isLoading = false
print(self.categoryModelDatas)
}
} catch {
print("JSON 디코딩 오류: \(error)")
if let jsonString = String(data: response.data, encoding: .utf8) {
print("서버 응답 JSON 데이터: \(jsonString)")
}

do {
let categoryModelData = try JSONDecoder().decode(CategoryModel.self, from: response.data)
DispatchQueue.main.async {
self.categoryModelDatas = categoryModelData.content
.sorted(by: { $0.updatedAt > $1.updatedAt }) // 최신 업데이트순으로 정렬
self.isLoading = false
print(self.categoryModelDatas)
}
} catch {
print("JSON 디코딩 오류: \(error)")
}
case .failure(let error):
print(error)
}
}
}

}
28 changes: 21 additions & 7 deletions Spon-us/View/Category/CategoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct CategoryView: View {
)
.foregroundColor(Color.sponusBlack)
.padding(.bottom, 20)

ZStack(alignment: .top) {
SponUsDivider()
.foregroundColor(.sponusGrey100)
Expand Down Expand Up @@ -67,6 +68,7 @@ struct CategoryView: View {
.padding(.bottom, 10)
}
.padding(.leading, 20)

if categoryModelData.isLoading {
VStack(){
Spacer()
Expand All @@ -75,15 +77,15 @@ struct CategoryView: View {
}
} else {
ScrollView{
VStack{
VStack {
Spacer().frame(height: 30)

ForEach(categoryModelData.categoryModelDatas, id: \.id) { categoryContent in
CategoryCell(categoryContent: categoryContent)
}
}
.padding(.horizontal, 20)
}

}
}
.navigationBarItems(trailing: Image("ic_search"))
Expand Down Expand Up @@ -133,8 +135,8 @@ struct CategoryListCell: View {
}

struct CategoryListDetailCell: View {

var categoryDetailList: String

@Binding var selectedCategoryList: String
@Binding var selectedCategoryDetailList: String

Expand Down Expand Up @@ -169,11 +171,19 @@ struct CategoryCell: View {
NavigationLink{SearchPostView(announcementId: categoryContent.id, selectedSaveButton: $isBookmarked)} label: {
VStack(spacing: 0){
HStack(alignment: .top, spacing: 0){
Image("musinsa").resizable().frame(width: 95, height: 95).padding(.trailing, 16)
AsyncImageView(url: URL(string: categoryContent.mainImage.url))
.aspectRatio(contentMode: .fill)
.frame(width: 95, height: 95)
.clipped()
.padding(.trailing, 16)

VStack(alignment: .leading, spacing: 0){
Text(categoryContent.writerName).font(.Caption04).foregroundColor(.sponusGrey700).padding(.bottom, 4)

Text(categoryContent.title).font(.Body10).multilineTextAlignment(.leading).padding(.bottom, 8).foregroundColor(.sponusBlack)

Spacer()

HStack{
Text(changeToKorean(category: categoryContent.category) ?? "전체")
.font(
Expand All @@ -187,6 +197,7 @@ struct CategoryCell: View {
Rectangle()
.fill(Color.sponusSecondary)
)

Text(changeToKorean(type: categoryContent.type) ?? "전체")
.font(
Font.custom("Pretendard", size: 10)
Expand All @@ -203,16 +214,21 @@ struct CategoryCell: View {
Spacer()
}
}.frame(width: 160, height: 95).padding(.trailing, 36)

Button(action: {toggleBookmark()
print(categoryContent.id)}){
Image(isBookmarked ? "ic_saved_check" : "ic_saved")
.frame(width: 28, height: 28)
}
}.padding(.bottom, 16)
}
.padding(.bottom, 16)
.padding(.top, 7)

SponUsDivider().foregroundColor(.sponusGrey100)
}
}
}

func toggleBookmark(){
isBookmarked.toggle()
if isBookmarked {
Expand All @@ -223,8 +239,6 @@ struct CategoryCell: View {
}
}


#Preview {
CategoryView()
}

2 changes: 1 addition & 1 deletion Spon-us/View/Post/NewPostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct NewPostView: View {
.toolbar(.hidden, for: .tabBar)
.onDisappear{
let provider = MoyaProvider<SponusAPI>(session: Session(interceptor: AuthInterceptor.shared))
provider.request(.postAnnouncement(title: postTitle, type: changeToEnglish(type: postSelectedCategory) ?? "ㄹㄹ" , category: changeToEnglish(category: postSelectedField) ?? "ㄹㅇ" , content: postDetail, images: [UIImage()])) { result
provider.request(.postAnnouncement(title: postTitle, type: changeToEnglish(type: postSelectedCategory) ?? "ㄹㄹ" , category: changeToEnglish(category: postSelectedField) ?? "ㄹㅇ" , content: postDetail, images: selectedImages)) { result
in
switch result {
case .success(let response):
Expand Down

0 comments on commit 0d88cfe

Please sign in to comment.