Skip to content

Commit

Permalink
[Init] #520 - 기능 및 모델 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
yju0808 committed Apr 3, 2024
1 parent a2591c5 commit 3e8b5c8
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 0 deletions.
33 changes: 33 additions & 0 deletions HappyAnding/HappyAnding/Model/Answer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Answer.swift
// HappyAnding
//
// Created by 임정욱 on 4/4/24.
//

import Foundation

struct Answer: Identifiable, Codable, Equatable, Hashable {
var id = UUID().uuidString
var body: String = ""
var postedBy: String = ""
var postedAt:[String] = [Date().getDate()]
var images: [String] = []
var likesCount: Int = 0
var isAccepted: Bool = false
var comments: [String] = []

var dictionary: [String: Any] {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}

init(body: String, postedBy: String, images: [String] = [], likesCount: Int = 0, isAccepted: Bool = false, comments: [String] = []) {
self.body = body
self.postedBy = postedBy
self.images = images
self.likesCount = likesCount
self.isAccepted = isAccepted
self.comments = comments
}
}
34 changes: 34 additions & 0 deletions HappyAnding/HappyAnding/Model/CommunityComment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// CommunityComment.swift
// HappyAnding
//
// Created by 임정욱 on 4/4/24.
//

import Foundation


struct CommunityComment: Identifiable, Codable, Equatable, Hashable {
var id: String = UUID().uuidString
var body: String
var author: String
var postedAt: String = Date().getDate()
var likesCount: Int = 0
var isAccepted: Bool = false
var comments: [String] = []


var dictionary: [String: Any] {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]) ?? [:]
}


init(body: String, author: String, images: [String] = [], likesCount: Int = 0, isAccepted: Bool = false, comments: [String] = []) {
self.body = body
self.author = author
self.likesCount = likesCount
self.isAccepted = isAccepted
self.comments = comments
}
}
42 changes: 42 additions & 0 deletions HappyAnding/HappyAnding/Model/Post.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Post.swift
// HappyAnding
//
// Created by 임정욱 on 4/4/24.
//

import Foundation

struct Post: Identifiable, Codable, Equatable, Hashable {
var id = UUID().uuidString
var type: String = ""
var title: String = ""
var body: String = ""
var postedBy: String
var postedAt:[String] = [Date().getDate()]
var images: [String] = []
var likesCount: Int = 0
var commentsCount: Int
var tags: [String] = []
var comments: [String] = []
var answers: [String] = []


var dictionary: [String: Any] {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}

init(type: String, title: String, body: String, postedBy: String, images: [String], likesCount: Int, commentsCount: Int, tags: [String], comments: [String], answers: [String]) {
self.type = type
self.title = title
self.body = body
self.postedBy = postedBy
self.images = images
self.likesCount = likesCount
self.commentsCount = commentsCount
self.tags = tags
self.comments = comments
self.answers = answers
}
}
75 changes: 75 additions & 0 deletions HappyAnding/HappyAnding/Repository/CommunityRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// File.swift
// HappyAnding
//
// Created by 임정욱 on 4/3/24.
//

import Foundation
import FirebaseCore
import FirebaseFirestore
import FirebaseFirestoreSwift
import FirebaseAuth



class CommunityRepository {

private let db = Firestore.firestore()




//MARK: - 글 관련 함수

func getPosts() {

}

func createPost() {

}

func updatePost() {

}

func deletePost() {

}

func likePost() {

}

func unLikePost() {

}


//MARK: - 댓글 관련 함수

func getComments() {

}

func createComment() {

}

func updateComment() {

}

func deleteComment() {

}

func likeComment() {

}

func unLikeComment() {

}
}

0 comments on commit 3e8b5c8

Please sign in to comment.