generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from Team-Ampersand/122-notice-detail-feature
🔀 :: [#122] 공지 상세 Feature 구현
- Loading branch information
Showing
48 changed files
with
966 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Projects/Domain/NoticeDomain/Interface/DataSource/RemoteNoticeDataSource.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
public protocol RemoteNoticeDataSource { | ||
func fetchNoticeList() async throws -> [NoticeEntity] | ||
func fetchNotice(id: Int) async throws -> DetailNoticeEntity | ||
func removeNotice(id: Int) async throws | ||
} |
40 changes: 40 additions & 0 deletions
40
Projects/Domain/NoticeDomain/Interface/Entity/DetailNoticeEntity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import BaseDomainInterface | ||
import Foundation | ||
|
||
public struct DetailNoticeEntity: Equatable { | ||
public let id: Int | ||
public let title: String | ||
public let content: String | ||
public let role: UserRoleType | ||
public let images: [NoticeImage] | ||
public let createdDate: Date | ||
public let modifiedDate: Date? | ||
|
||
public init( | ||
id: Int, | ||
title: String, | ||
content: String, | ||
role: UserRoleType, | ||
images: [DetailNoticeEntity.NoticeImage], | ||
createdDate: Date, | ||
modifiedDate: Date? = nil | ||
) { | ||
self.id = id | ||
self.title = title | ||
self.content = content | ||
self.role = role | ||
self.images = images | ||
self.createdDate = createdDate | ||
self.modifiedDate = modifiedDate | ||
} | ||
|
||
public struct NoticeImage: Equatable { | ||
public let id: Int | ||
public let imageURL: String | ||
|
||
public init(id: Int, imageURL: String) { | ||
self.id = id | ||
self.imageURL = imageURL | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Projects/Domain/NoticeDomain/Interface/Model/DetailNoticeModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
public typealias DetailNoticeModel = DetailNoticeEntity |
2 changes: 2 additions & 0 deletions
2
Projects/Domain/NoticeDomain/Interface/Repository/NoticeRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
public protocol NoticeRepository { | ||
func fetchNoticeList() async throws -> [NoticeEntity] | ||
func fetchNotice(id: Int) async throws -> DetailNoticeEntity | ||
func removeNotice(id: Int) async throws | ||
} |
3 changes: 3 additions & 0 deletions
3
Projects/Domain/NoticeDomain/Interface/UseCase/FetchNoticeUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public protocol FetchNoticeUseCase { | ||
func callAsFunction(id: Int) async throws -> DetailNoticeModel | ||
} |
3 changes: 3 additions & 0 deletions
3
Projects/Domain/NoticeDomain/Interface/UseCase/RemoveNoticeUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public protocol RemoveNoticeUseCase { | ||
func callAsFunction(id: Int) async throws | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Projects/Domain/NoticeDomain/Sources/DTO/Response/FetchNoticeResponseDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import BaseDomainInterface | ||
import DateUtility | ||
import Foundation | ||
import NoticeDomainInterface | ||
|
||
struct FetchNoticeResponseDTO: Decodable { | ||
let id: Int | ||
let title: String | ||
let content: String | ||
let role: UserRoleType | ||
let boardImage: [BoardImage] | ||
let createdDate: String | ||
let modifiedDate: String? | ||
|
||
struct BoardImage: Decodable { | ||
let id: Int | ||
let url: String | ||
|
||
init(id: Int, url: String) { | ||
self.id = id | ||
self.url = url | ||
} | ||
} | ||
} | ||
|
||
extension FetchNoticeResponseDTO { | ||
func toDomain() -> DetailNoticeEntity { | ||
DetailNoticeEntity( | ||
id: id, | ||
title: title, | ||
content: content, | ||
role: role, | ||
images: boardImage.map { $0.toDomain() }, | ||
createdDate: createdDate.toDateWithCustomFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"), | ||
modifiedDate: modifiedDate?.toDateWithCustomFormat("yyyy-MM-dd'T'HH:mm:ss.SSS") | ||
) | ||
} | ||
} | ||
|
||
extension FetchNoticeResponseDTO.BoardImage { | ||
func toDomain() -> DetailNoticeEntity.NoticeImage { | ||
.init(id: id, imageURL: url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Projects/Domain/NoticeDomain/Sources/UseCase/FetchNoticeUseCaseImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import NoticeDomainInterface | ||
|
||
struct FetchNoticeUseCaseImpl: FetchNoticeUseCase { | ||
private let noticeRepository: any NoticeRepository | ||
|
||
init(noticeRepository: any NoticeRepository) { | ||
self.noticeRepository = noticeRepository | ||
} | ||
|
||
func callAsFunction(id: Int) async throws -> DetailNoticeModel { | ||
try await noticeRepository.fetchNotice(id: id) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Projects/Domain/NoticeDomain/Sources/UseCase/RemoveNoticeUseCaseImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import NoticeDomainInterface | ||
|
||
struct RemoveNoticeUseCaseImpl: RemoveNoticeUseCase { | ||
private let noticeRepository: any NoticeRepository | ||
|
||
init(noticeRepository: any NoticeRepository) { | ||
self.noticeRepository = noticeRepository | ||
} | ||
|
||
func callAsFunction(id: Int) async throws { | ||
try await noticeRepository.removeNotice(id: id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Projects/Domain/NoticeDomain/Testing/UseCase/FetchNoticeUseCaseSpy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import NoticeDomainInterface | ||
|
||
final class FetchNoticeUseCaseSpy: FetchNoticeUseCase { | ||
var fetchNoticeCallCount = 0 | ||
var fetchNoticeHandler: (Int) async throws -> DetailNoticeModel = { _ in | ||
.init( | ||
id: 1, | ||
title: "", | ||
content: "", | ||
role: .member, | ||
images: [], | ||
createdDate: .init() | ||
) | ||
} | ||
func callAsFunction(id: Int) async throws -> DetailNoticeModel { | ||
fetchNoticeCallCount += 1 | ||
return try await fetchNoticeHandler(id) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Projects/Domain/NoticeDomain/Testing/UseCase/RemoveNoticeUseCaseSpy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import NoticeDomainInterface | ||
|
||
final class RemoveNoticeUseCaseSpy: RemoveNoticeUseCase { | ||
var removeNoticeCallCount = 0 | ||
var removeNoticeHandler: (Int) async throws -> Void = { _ in } | ||
func callAsFunction(id: Int) async throws { | ||
removeNoticeCallCount += 1 | ||
try await removeNoticeHandler(id) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Projects/Domain/NoticeDomain/Tests/FetchNoticeUseCaseTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import NoticeDomainInterface | ||
import XCTest | ||
@testable import NoticeDomain | ||
@testable import NoticeDomainTesting | ||
|
||
final class FetchNoticeUseCaseTests: XCTestCase { | ||
var noticeRepository: NoticeRepositorySpy! | ||
var sut: FetchNoticeUseCaseImpl! | ||
|
||
override func setUp() { | ||
noticeRepository = .init() | ||
sut = .init(noticeRepository: noticeRepository) | ||
} | ||
|
||
override func tearDown() { | ||
noticeRepository = nil | ||
sut = nil | ||
} | ||
|
||
func testCallAsFunction() async throws { | ||
let date = Date() | ||
XCTAssertEqual(noticeRepository.fetchNoticeCallCount, 0) | ||
let expected = DetailNoticeEntity( | ||
id: 1, | ||
title: "b", | ||
content: "aj", | ||
role: .councillor, | ||
images: [], | ||
createdDate: .init(), | ||
modifiedDate: nil | ||
) | ||
noticeRepository.fetchNoticeHandler = { _ in expected } | ||
|
||
let actual = try await sut(id: 1) | ||
|
||
XCTAssertEqual(noticeRepository.fetchNoticeCallCount, 1) | ||
XCTAssertEqual(actual, expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.