Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 개인 기록 구현 #214

Merged
merged 28 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c0889e
Feat: RecordEditView 추가
FpRaArNkK Oct 30, 2024
9169dc4
Fix: 기록 추가 이미지 이름 noPic으로 변경
FpRaArNkK Oct 31, 2024
da5ae74
Chore: NamoNavBarModifier - content 위 아래 Spacer minLength 0 설정
FpRaArNkK Oct 31, 2024
b983308
Feat: HomeDiaryEditView UI 작성
FpRaArNkK Oct 31, 2024
6d8a805
Feat: HomeDiaryEditStore 추가
FpRaArNkK Oct 31, 2024
6d1c438
Feat: HomeDiaryEditStore 임시 구현, 뷰 연결
FpRaArNkK Nov 8, 2024
f5cd497
Feat: HomeDiaryEdit 기획 수정 사항 반영
FpRaArNkK Nov 13, 2024
0f79d54
Feat: Toast 로직 추가
FpRaArNkK Nov 13, 2024
20bd0e0
Feat: NamoAlertContent 모델 추가
FpRaArNkK Nov 13, 2024
03d6e1d
Feat: Alert 관련 로직 구현
FpRaArNkK Nov 13, 2024
e5dad23
Merge remote-tracking branch 'origin/develop' into feat/AppFlow/#199
FpRaArNkK Nov 13, 2024
85377ed
Feat: Content Validating 추가
FpRaArNkK Nov 13, 2024
e06a19b
Feat: Alert, Action 추가 작성
FpRaArNkK Nov 13, 2024
6ac64d6
Merge remote-tracking branch 'origin/develop' into feat/AppFlow/#199
FpRaArNkK Nov 13, 2024
56c3c20
Feat: Diary DTO, Repo 수정
FpRaArNkK Nov 14, 2024
08234fd
Feat: Diary Domain 작성
FpRaArNkK Nov 14, 2024
300434b
Feat: Diary 관련 API 작성
FpRaArNkK Nov 14, 2024
3aeaef1
Feat: HomeDiaryEditStore State 수정
FpRaArNkK Nov 15, 2024
f0a54b3
Feat: HomeDiaryEdit - DIary Get 관련 로직 작성
FpRaArNkK Nov 15, 2024
841831e
Feat: Diary DTO 관련 내용 수정
FpRaArNkK Nov 15, 2024
81b9181
Feat: 일기 이미지 병렬 업로드 로직 작성
FpRaArNkK Nov 15, 2024
4ecf71f
Feat: Diary Post 관련 Store 로직 작성
FpRaArNkK Nov 15, 2024
4fbefaa
Feat: HomeDiaryEdit Toast 로직 구조 추가
FpRaArNkK Nov 15, 2024
335c7f3
Feat: show Alert 로직 Toast와 같이 수정
FpRaArNkK Nov 15, 2024
d15dd1d
Feat: loadDiaryIamges 로직 구현
FpRaArNkK Nov 15, 2024
31d2637
Feat: 이미지 처리 관련 API 로직 작성
FpRaArNkK Nov 15, 2024
e68b92e
Feat: Delete, Patch Diary API 작업
FpRaArNkK Nov 16, 2024
d4bdee1
Chore: 주석 추가 + extension 위치 이동
FpRaArNkK Nov 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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