Skip to content

Commit

Permalink
feat: repositery 선수추가 기능(#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemdeeks committed Jan 20, 2024
1 parent 64e59a0 commit 3232e98
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ public struct TeamDBRepository: TeamDBRepositoryInterface {
team.sort { pre, _ in
pre.isSelected
}

return team.map { Team(id: $0.id, name: $0.teamName) }

return team.map {
Team(id: $0.id, name: $0.teamName, members: $0.teamPlayers.map{
Player(id: $0.id,name: $0.name, backNumber: $0.backNumber)
})
}
} catch {
fatalError(error.localizedDescription)
}
Expand All @@ -45,6 +49,24 @@ public struct TeamDBRepository: TeamDBRepositoryInterface {
}
}

public func addPlayer(player: Player) {
do {
var fetchDescriptor = FetchDescriptor<SchemaV1.Team>()
fetchDescriptor.sortBy = [SortDescriptor<SchemaV1.Team>(\.updatedAt, order: .reverse)]

var team = try modelContext.fetch(fetchDescriptor)
team.sort { pre, _ in
pre.isSelected
}

var human = SchemaV1.TeamPlayer(id: player.id ,name: player.name, backNumber: player.backNumber)
team[0].teamPlayers.insert(human, at: 0)
try modelContext.save()
} catch {
fatalError(error.localizedDescription)
}
}

// func loadUniform(index: Int) {
// do {
// var fetchDescriptor = FetchDescriptor<SchemaV1.Team>()
Expand Down

0 comments on commit 3232e98

Please sign in to comment.