Skip to content

Commit

Permalink
Merge pull request #95 from Team-MindWay/94-notice-domain-setting
Browse files Browse the repository at this point in the history
🔀 :: [#94] NoticeDomain Setting
  • Loading branch information
kimkyumbi authored Jun 21, 2024
2 parents 9252b94 + f622fee commit 484aa99
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 14 deletions.
1 change: 1 addition & 0 deletions Service/Sources/Base/MindWayAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum MindWayDomain: String {
case order
case admin
case rank
case notice
}

extension MindWayDomain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public struct FetchBookDetailInfoResponseDTO: Decodable {
}

extension FetchBookDetailInfoResponseDTO {
func toDomain() -> BookDetialInfoEntity {
BookDetialInfoEntity(
func toDomain() -> BookDetailInfoEntity {
BookDetailInfoEntity(
title: title,
plot: plot
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public struct BookRepositoryImpl: BookRepository {
try await remoteBookDataSource.fetchBookList()
}

public func modifyBook(req: BookInfoRequestDTO) async throws {
try await remoteBookDataSource.modifyBook(req: req)
public func modifyBook(book_id: Int, req: BookInfoRequestDTO) async throws {
try await remoteBookDataSource.modifyBook(book_id: book_id, req: req)
}

public func deleteBook() async throws {
try await remoteBookDataSource.deleteBook()
public func deleteBook(book_id: Int) async throws {
try await remoteBookDataSource.deleteBook(book_id: book_id)
}

public func fetchBookDetail() async throws -> BookDetailInfoEntity {
try await remoteBookDataSource.fetchBookDetail()
public func fetchBookDetail(book_id: Int) async throws -> BookDetailInfoEntity {
try await remoteBookDataSource.fetchBookDetail(book_id: book_id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct DeleteBookUseCaseImpl: DeleteBookUseCase {
self.bookRepository = bookRepository
}

public func execute() async throws {
try await bookRepository.deleteBook()
public func execute(book_id: Int) async throws {
try await bookRepository.deleteBook(book_id: book_id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct FetchBookDetailUseCaseImpl: FetchBookDetailUseCase {
self.bookRepository = bookRepository
}

public func execute() async throws -> BookDetailInfoEntity {
try await bookRepository.fetchBookDetail()
public func execute(book_id: Int) async throws -> BookDetailInfoEntity {
try await bookRepository.fetchBookDetail(book_id: book_id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct ModifyBookUseCaseImpl: ModifyBookUseCase {
self.bookRepository = bookRepository
}

public func execute(req: BookInfoRequestDTO) async throws {
try await bookRepository.modifyBook(req: req)
public func execute(book_id: Int, req: BookInfoRequestDTO) async throws {
try await bookRepository.modifyBook(book_id: book_id, req: req)
}
}
51 changes: 51 additions & 0 deletions Service/Sources/Domain/NoticeDomain/API/NoticeAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Foundation
import Moya

public enum NoticeAPI {
case fetchNotice
}

extension NoticeAPI: MindWayAPI {
public typealias ErrorType = NoticeDomainError

public var domain: MindWayDomain {
.notice
}

public var urlPath: String {
switch self {
case .fetchNotice:
return ""
}
}

public var method: Moya.Method {
switch self {
case .fetchNotice:
return .get
}
}

public var task: Moya.Task {
switch self {
case .fetchNotice:
return .requestPlain
}
}

public var jwtTokenType: JwtTokenType {
switch self {
case .fetchNotice:
return .accessToken
}
}

public var errorMap: [Int: ErrorType] {
switch self {
case .fetchNotice:
return [
401: .unauthorized
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation

public struct FetchNoticeResponseDTO: Decodable {
public let title: String
public let content: String

init(
title: String,
content: String
) {
self.title = title
self.content = content
}
}

extension FetchNoticeResponseDTO {
func toDomain() -> FetchNoticeEntity {
FetchNoticeEntity(
title: title,
content: content
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

public final class RemoteNoticeDataSourceImpl: BaseRemoteDataSource<NoticeAPI>, RemoteNoticeDataSource {
public func fetchNotice() async throws -> FetchNoticeEntity {
try await request(.fetchNotice, dto: FetchNoticeResponseDTO.self)
.toDomain()
}
}
14 changes: 14 additions & 0 deletions Service/Sources/Domain/NoticeDomain/Entity/FetchNoticeEntity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

public struct FetchNoticeEntity {
private let title: String
private let content: String

init(
title: String,
content: String
) {
self.title = title
self.content = content
}
}
14 changes: 14 additions & 0 deletions Service/Sources/Domain/NoticeDomain/Error/NoticeDomainError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

public enum NoticeDomainError: Error {
case unauthorized
}

extension NoticeDomainError: LocalizedError {
public var errorDescription: String? {
switch self {
case .unauthorized:
return "AccessToken이 블랙리스트에 있습니다."
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

public struct NoticeRepositoryImpl: NoticeRepository {
private let remoteNoticeDataSource: any RemoteNoticeDataSource

public init(
remoteNoticeDataSource: any RemoteNoticeDataSource
) {
self.remoteNoticeDataSource = remoteNoticeDataSource
}

public func fetchNotice() async throws -> FetchNoticeEntity {
try await remoteNoticeDataSource.fetchNotice()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

public struct FetchNoticeUseCaseImpl: FetchNoticeUseCase {
private let noticeRepository: any NoticeRepository

public init(
noticeRepository: any NoticeRepository
) {
self.noticeRepository = noticeRepository
}

public func execute() async throws -> FetchNoticeEntity {
try await noticeRepository.fetchNotice()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public protocol RemoteNoticeDataSource {
func fetchNotice() async throws -> FetchNoticeEntity
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public protocol NoticeRepository {
func fetchNotice() async throws -> FetchNoticeEntity
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public protocol FetchNoticeUseCase {
func execute() async throws -> FetchNoticeEntity
}

0 comments on commit 484aa99

Please sign in to comment.