Skip to content

Commit

Permalink
Merge pull request #214 from Namo-log/feat/personalDiary/#206
Browse files Browse the repository at this point in the history
[Feat] 개인 기록 구현
  • Loading branch information
FpRaArNkK authored Dec 10, 2024
2 parents 297724f + d4bdee1 commit 306d2d8
Show file tree
Hide file tree
Showing 19 changed files with 1,022 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Foundation
import CoreNetwork

protocol DiaryRepository {
func createDiary(scheduleId: Int, content: String, images: [Data?]) async -> CreateDiaryResponseDTO?
func getMonthDiary(request: GetDiaryRequestDTO) async -> GetDiaryResponseDTO?
func getOneDiary(scheduleId: Int) async -> GetOneDiaryResponseDTO?
func changeDiary(scheduleId: Int, content: String, images: [Data?], deleteImageIds: [Int]) async -> Bool
func deleteDiary(scheduleId: Int) async -> Bool
// func createDiary(scheduleId: Int, content: String, images: [Data?]) async -> CreateDiaryResponseDTO?
// func getMonthDiary(request: GetDiaryRequestDTO) async -> GetDiaryResponseDTO?
// func getOneDiary(scheduleId: Int) async -> GetOneDiaryResponseDTO?
// func changeDiary(scheduleId: Int, content: String, images: [Data?], deleteImageIds: [Int]) async -> Bool
// func deleteDiary(scheduleId: Int) async -> Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ protocol MoimDiaryRepository {
func deleteMoimDiary(moimScheduleId: Int) async -> Bool
func getMonthMoimDiary(req: GetMonthMoimDiaryReqDTO) async -> GetMonthMoimDiaryResDTO?
func getOneMoimDiary(moimScheduleId: Int) async -> GetOneMoimDiaryResDTO?
func getOneMoimDiaryDetail(moimScheduleId: Int) async -> Diary?
func getOneMoimDiaryDetail(moimScheduleId: Int) async -> Diary_Old?
func deleteMoimDiaryOnPersonal(scheduleId: Int) async -> Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,66 @@ import SharedUtil
public enum DiaryEndPoint {
case getCalendarByMonth(ym: YearMonth)
case getDiaryByDate(ymd: YearMonthDay)
case getDiaryBySchedule(id: Int)
case patchDiary(id: Int, reqDto: DiaryPatchRequestDTO)
case postDiary(reqDto: DiaryPostRequestDTO)
case deleteDiary(id: Int)
}

extension DiaryEndPoint: EndPoint {
public var baseURL: String {
return "\(SecretConstants.baseURL)/diaries"
}

public var path: String {
switch self {
case .getCalendarByMonth(let ym):
return "/calendar/\(ym.year)-\(String(format: "%02d", ym.month))"
case .getDiaryByDate(let ymd):
return "/date/\(ymd.year)-\(String(format: "%02d", ymd.month))-\(String(format: "%02d", ymd.day))"
}
}

public var method: Alamofire.HTTPMethod {
switch self {
case .getCalendarByMonth:
return .get
case .getDiaryByDate:
return .get
}
}

public var task: APITask {
switch self {
case .getCalendarByMonth:
return .requestPlain
case .getDiaryByDate:
return .requestPlain
}
}


public var baseURL: String {
return "\(SecretConstants.baseURL)/diaries"
}

public var path: String {
switch self {
case .getCalendarByMonth(let ym):
return "/calendar/\(ym.year)-\(String(format: "%02d", ym.month))"
case .getDiaryByDate(let ymd):
return "/date/\(ymd.year)-\(String(format: "%02d", ymd.month))-\(String(format: "%02d", ymd.day))"
case .getDiaryBySchedule(let id):
return "/\(id)"
case .patchDiary(let id, _):
return "/\(id)"
case .postDiary:
return ""
case .deleteDiary(let id):
return "/\(id)"
}
}

public var method: Alamofire.HTTPMethod {
switch self {
case .getCalendarByMonth:
return .get
case .getDiaryByDate:
return .get
case .getDiaryBySchedule:
return .get
case .patchDiary:
return .patch
case .postDiary:
return .post
case .deleteDiary:
return .delete
}
}

public var task: APITask {
switch self {
case .getCalendarByMonth:
return .requestPlain
case .getDiaryByDate:
return .requestPlain
case .getDiaryBySchedule:
return .requestPlain
case .patchDiary(_, let reqDto):
return .requestJSONEncodable(parameters: reqDto)
case .postDiary(let reqDto):
return .requestJSONEncodable(parameters: reqDto)
case .deleteDiary:
return .requestPlain
}
}

}
58 changes: 55 additions & 3 deletions Namo_SwiftUI/Projects/Core/Network/Sources/DTO/DiaryDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,63 @@
// Namo_SwiftUI
//
// Created by 서은수 on 3/16/24.
// Updated by 박민서 on 11/13/24.
//

import Foundation

public struct Diary: Decodable {
public struct DiaryResponseDTO: Decodable {
public let diaryId: Int
public let content: String
public let enjoyRating: Int
public let diaryImages: [DiaryImageResponseDTO]
}

public struct DiaryImageResponseDTO: Decodable {
public let orderNumber: Int
public let diaryImageId: Int
public let imageUrl: String
}

public struct DiaryPatchRequestDTO: Encodable {
public let content: String
public let enjoyRating: Int
public let diaryImages: [DiaryImageRequestDTO]
public let deleteImages: [Int]

public init(content: String, enjoyRating: Int, diaryImages: [DiaryImageRequestDTO], deleteImages: [Int]) {
self.content = content
self.enjoyRating = enjoyRating
self.diaryImages = diaryImages
self.deleteImages = deleteImages
}
}

public struct DiaryPostRequestDTO: Encodable {
public let scheduleId: Int
public let content: String
public let enjoyRating: Int
public let diaryImages: [DiaryImageRequestDTO]

public init(scheduleId: Int, content: String, enjoyRating: Int, diaryImages: [DiaryImageRequestDTO]) {
self.scheduleId = scheduleId
self.content = content
self.enjoyRating = enjoyRating
self.diaryImages = diaryImages
}
}

public struct DiaryImageRequestDTO: Encodable {
public let orderNumber: Int
public let imageUrl: String

public init(orderNumber: Int, imageUrl: String) {
self.orderNumber = orderNumber
self.imageUrl = imageUrl
}
}

public struct Diary_Old: Decodable {
public var scheduleId: Int
public var name: String
public var startDate: Int
Expand Down Expand Up @@ -45,15 +97,15 @@ public struct GetDiaryRequestDTO: Encodable {
}

public struct GetDiaryResponseDTO: Decodable {
public init(content: [Diary], currentPage: Int, size: Int, first: Bool, last: Bool) {
public init(content: [Diary_Old], currentPage: Int, size: Int, first: Bool, last: Bool) {
self.content = content
self.currentPage = currentPage
self.size = size
self.first = first
self.last = last
}

public var content: [Diary]
public var content: [Diary_Old]
public var currentPage: Int
public var size: Int
public var first: Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,59 @@ extension DiaryScheduleParticipantDTO {
)
}
}

extension DiaryResponseDTO {
func toEntity() -> Diary {
return Diary(
id: diaryId,
content: content,
enjoyRating: enjoyRating,
images: mapAndSortDiaryImages(from: diaryImages)
)
}

func mapAndSortDiaryImages(from responseDTOs: [DiaryImageResponseDTO]) -> [DiaryImage] {
return responseDTOs
.sorted(by: { $0.orderNumber < $1.orderNumber })
.map { DiaryImage(id: $0.diaryImageId, orderNumber: $0.orderNumber, imageUrl: $0.imageUrl) }
}
}

extension Diary {
func toPostDTO(scheduleId: Int) -> DiaryPostRequestDTO {
return DiaryPostRequestDTO(
scheduleId: scheduleId,
content: content,
enjoyRating: enjoyRating,
diaryImages: images.map { $0.toDTO() }
)
}

func toPatchDTO(deleteImages: [Int]) -> DiaryPatchRequestDTO {
return DiaryPatchRequestDTO(
content: self.content,
enjoyRating: self.enjoyRating,
diaryImages: self.images.map { $0.toDTO() },
deleteImages: deleteImages
)
}
}

extension DiaryImageResponseDTO {
func toEntity() -> DiaryImage {
return DiaryImage(
id: diaryImageId,
orderNumber: orderNumber,
imageUrl: imageUrl
)
}
}

extension DiaryImage {
func toDTO() -> DiaryImageRequestDTO {
return DiaryImageRequestDTO(
orderNumber: orderNumber,
imageUrl: imageUrl
)
}
}
41 changes: 41 additions & 0 deletions Namo_SwiftUI/Projects/Domain/Diary/Sources/Model/Diary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Diary.swift
// DomainDiary
//
// Created by 박민서 on 11/14/24.
//

public struct Diary: Equatable {
public let id: Int?
public var content: String
public var enjoyRating: Int
public var images: [DiaryImage]

public init(
id: Int? = nil,
content: String = "",
enjoyRating: Int = 0,
images: [DiaryImage] = []
) {
self.id = id
self.content = content
self.enjoyRating = enjoyRating
self.images = images
}
}

public struct DiaryImage: Equatable {
public let id: Int?
public var orderNumber: Int
public let imageUrl: String

public init(
id: Int? = nil,
orderNumber: Int,
imageUrl: String
) {
self.id = id
self.orderNumber = orderNumber
self.imageUrl = imageUrl
}
}
Loading

0 comments on commit 306d2d8

Please sign in to comment.