Skip to content

Commit

Permalink
Merge pull request #376 from School-of-Company/374-club-crud-api-setting
Browse files Browse the repository at this point in the history
🔀 :: [#374] 동아리 CRUD API 추가
  • Loading branch information
uuuunseo authored Jul 20, 2024
2 parents 23fffc3 + ba107c1 commit f0ea015
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 2 deletions.
18 changes: 18 additions & 0 deletions App/Sources/Application/DI/Club/AppComponent+Club.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,22 @@ public extension AppComponent {
FetchStudentDetailByClubUseCaseImpl(clubRepository: clubRepository)
}
}

var createdClubUseCase: any CreatedClubUseCase {
shared {
CreatedClubUseCaseImpl(clubRepository: clubRepository)
}
}

var modifyClubUseCase: any ModifyClubUseCase {
shared {
ModifyClubUseCaseImpl(clubRepository: clubRepository)
}
}

var deleteClubUseCase: any DeleteClubUseCase {
shared {
DeleteClubUseCaseImpl(clubRepository: clubRepository)
}
}
}
3 changes: 3 additions & 0 deletions App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,9 @@ extension AppComponent: Registration {
localTable["fetchClubDetailUseCase-any FetchClubDetailUseCase"] = { [unowned self] in self.fetchClubDetailUseCase as Any }
localTable["fetchStudentListByClubUseCase-any FetchStudentListByClubUseCase"] = { [unowned self] in self.fetchStudentListByClubUseCase as Any }
localTable["fetchStudentDetailByClubUseCase-any FetchStudentDetailByClubUseCase"] = { [unowned self] in self.fetchStudentDetailByClubUseCase as Any }
localTable["createdClubUseCase-any CreatedClubUseCase"] = { [unowned self] in self.createdClubUseCase as Any }
localTable["modifyClubUseCase-any ModifyClubUseCase"] = { [unowned self] in self.modifyClubUseCase as Any }
localTable["deleteClubUseCase-any DeleteClubUseCase"] = { [unowned self] in self.deleteClubUseCase as Any }
localTable["remoteGovernmentDataSource-any RemoteGovernmentDataSource"] = { [unowned self] in self.remoteGovernmentDataSource as Any }
localTable["governmentRepository-any GovernmentRepository"] = { [unowned self] in self.governmentRepository as Any }
localTable["fetchGovernmentListUseCase-any FetchGovernmentListUseCase"] = { [unowned self] in self.fetchGovernmentListUseCase as Any }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ public final class RemoteClubDataSourceImpl: BaseRemoteDataSource<ClubAPI>, Remo
dto: StudentDetailByClubResponseDTO.self
).toDomain()
}

public func createdClub(schoolID: String, req: CreatedClubRequestDTO) async throws {
try await request(.createdClub(schoolID: schoolID, req: req))
}

public func modifyClub(clubID: Int, req: ModifyClubRequestDTO) async throws {
try await request(.modifyClub(clubID: clubID, req: req))
}

public func deleteClub(clubID: Int) async throws {
try await request(.deleteClub(clubID: clubID))
}
}
12 changes: 12 additions & 0 deletions Service/Sources/Data/Repository/Club/ClubRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ public struct ClubRepositoryImpl: ClubRepository {
public func fetchStudentDetailByClub(clubID: Int, studentID: String) async throws -> StudentDetailByClubEntity {
try await remoteClubDataSource.fetchStudentDetailByClub(clubID: clubID, studentID: studentID)
}

public func createdClub(schoolID: String, req: CreatedClubRequestDTO) async throws {
try await remoteClubDataSource.createdClub(schoolID: schoolID, req: req)
}

public func modifyClub(clubID: Int, req: ModifyClubRequestDTO) async throws {
try await remoteClubDataSource.modifyClub(clubID: clubID, req: req)
}

public func deleteClub(clubID: Int) async throws {
try await remoteClubDataSource.deleteClub(clubID: clubID)
}
}
13 changes: 13 additions & 0 deletions Service/Sources/Data/UseCase/Club/CreatedClubUseCaseImpl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public struct CreatedClubUseCaseImpl: CreatedClubUseCase {
private let clubRepository: any ClubRepository

public init(clubRepository: any ClubRepository) {
self.clubRepository = clubRepository
}

public func callAsFunction(schoolID: String, req: CreatedClubRequestDTO) async throws {
try await clubRepository.createdClub(schoolID: schoolID, req: req)
}
}
13 changes: 13 additions & 0 deletions Service/Sources/Data/UseCase/Club/DeleteClubUseCaseImpl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public struct DeleteClubUseCaseImpl: DeleteClubUseCase {
private let clubRepository: any ClubRepository

public init(clubRepository: any ClubRepository) {
self.clubRepository = clubRepository
}

public func callAsFunction(clubID: Int) async throws {
try await clubRepository.deleteClub(clubID: clubID)
}
}
13 changes: 13 additions & 0 deletions Service/Sources/Data/UseCase/Club/ModifyClubUseCaseImpl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public struct ModifyClubUseCaseImpl: ModifyClubUseCase {
private let clubRepository: any ClubRepository

public init(clubRepository: any ClubRepository) {
self.clubRepository = clubRepository
}

public func callAsFunction(clubID: Int, req: ModifyClubRequestDTO) async throws {
try await clubRepository.modifyClub(clubID: clubID, req: req)
}
}
32 changes: 30 additions & 2 deletions Service/Sources/Domain/ClubDomain/API/ClubAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public enum ClubAPI {
case fetchClubDetail(clubID: Int)
case fetchStudentListByClub
case fetchStudentDetailByClub(clubID: Int, studentID: String)
case createdClub(schoolID: String, req: CreatedClubRequestDTO)
case modifyClub(clubID: Int, req: ModifyClubRequestDTO)
case deleteClub(clubID: Int)
}

extension ClubAPI: BitgouelAPI {
Expand All @@ -19,12 +22,20 @@ extension ClubAPI: BitgouelAPI {
switch self {
case .fetchClubList:
return ""
case let .fetchClubDetail(clubID):

case let .fetchClubDetail(clubID),
let .modifyClub(clubID, _),
let .deleteClub(clubID):
return "/\(clubID)"

case .fetchStudentListByClub:
return "/my"

case let .fetchStudentDetailByClub(clubID, studentID):
return "/\(clubID)/\(studentID)"

case let .createdClub(schoolID, _):
return "/\(schoolID)"
}
}

Expand All @@ -35,6 +46,15 @@ extension ClubAPI: BitgouelAPI {
.fetchStudentListByClub,
.fetchStudentDetailByClub:
return .get

case .createdClub:
return .post

case .modifyClub:
return .patch

case .deleteClub:
return .delete
}
}

Expand All @@ -44,10 +64,18 @@ extension ClubAPI: BitgouelAPI {
return .requestParameters(parameters: [
"highSchool": highSchool
], encoding: URLEncoding.queryString)

case .fetchClubDetail,
.fetchStudentListByClub,
.fetchStudentDetailByClub:
.fetchStudentDetailByClub,
.deleteClub:
return .requestPlain

case let .createdClub(_, req):
return .requestJSONEncodable(req)

case let .modifyClub(_, req):
return .requestJSONEncodable(req)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

public struct CreatedClubRequestDTO: Encodable {
public let name: String
public let field: FieldType

public init(
name: String,
field: FieldType
) {
self.name = name
self.field = field
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation

public struct ModifyClubRequestDTO: Encodable {
public let name: String
public let field: FieldType
public let schoolID: String

public init(
name: String,
field: FieldType,
schoolID: String
) {
self.name = name
self.field = field
self.schoolID = schoolID
}

enum CodingKeys: String, CodingKey {
case name
case field
case schoolID = "schoolId"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ public protocol RemoteClubDataSource: BaseRemoteDataSource<ClubAPI> {
func fetchClubDetail(clubID: Int) async throws -> ClubDetailEntity
func fetchStudentListByClub() async throws -> ClubDetailEntity
func fetchStudentDetailByClub(clubID: Int, studentID: String) async throws -> StudentDetailByClubEntity
func createdClub(schoolID: String, req: CreatedClubRequestDTO) async throws
func modifyClub(clubID: Int, req: ModifyClubRequestDTO) async throws
func deleteClub(clubID: Int) async throws
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ public protocol ClubRepository {
func fetchClubDetail(clubID: Int) async throws -> ClubDetailEntity
func fetchStudentListByClub() async throws -> ClubDetailEntity
func fetchStudentDetailByClub(clubID: Int, studentID: String) async throws -> StudentDetailByClubEntity
func createdClub(schoolID: String, req: CreatedClubRequestDTO) async throws
func modifyClub(clubID: Int, req: ModifyClubRequestDTO) async throws
func deleteClub(clubID: Int) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public protocol CreatedClubUseCase {
func callAsFunction(schoolID: String, req: CreatedClubRequestDTO) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public protocol DeleteClubUseCase {
func callAsFunction(clubID: Int) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public protocol ModifyClubUseCase {
func callAsFunction(clubID: Int, req: ModifyClubRequestDTO) async throws
}

0 comments on commit f0ea015

Please sign in to comment.