Skip to content

Commit

Permalink
Release 1.2.3 (#66)
Browse files Browse the repository at this point in the history
T-23 Add banners place position index
  • Loading branch information
mayer1a authored Oct 16, 2024
2 parents 8212c00 + fd31b75 commit 73ddb7d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Sources/App/Helpers/DTOFactory/DTOFactory+Banners.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ extension DTOFactory {

static func makeBanners(from banners: [MainBanner], fullModel: Bool = true) throws -> [MainBannerDTO] {

var bannersDTO = try banners.map { mainBanner in
var bannersDTO = try banners.sorted(by: { $0.placeIndex < $1.placeIndex }).map { mainBanner in
try makeBanner(from: mainBanner, fullModel: fullModel)
}

moveCategoryBannerToSecondPlace(in: &bannersDTO)
// moveBannersPlace(in: &bannersDTO)

return bannersDTO
}
Expand Down Expand Up @@ -101,11 +101,15 @@ extension DTOFactory {

private extension DTOFactory {

static func moveCategoryBannerToSecondPlace(in banners: inout [MainBannerDTO]) {
static func moveBannersPlace(in banners: inout [MainBannerDTO]) {
if let index = banners.firstIndex(where: { $0.categories != nil }), index != 1 {
let element = banners.remove(at: index)
banners.insert(element, at: 1)
}
if let index = banners.firstIndex(where: { $0.placeType == .singleBanner }), index != banners.count - 1 {
let element = banners.remove(at: index)
banners.append(element)
}
}

}
1 change: 1 addition & 0 deletions Sources/App/Migrations/MainBanner/CreateMainBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct CreateMainBanner: AsyncMigration {
.id()
.field("title", .string)
.field("place_type", placeType)
.field("place_index", .int, .required)
.field("parent_id", .uuid, .references("main_banners", "id", onDelete: .cascade))
.create()
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/App/Models/DBEntity/MainBanner/MainBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ final class MainBanner: Model, Content, @unchecked Sendable {
@OptionalEnum(key: "place_type")
var placeType: PlaceType?

@Field(key: "place_index")
var placeIndex: Int

@OptionalChild(for: \.$mainBanner)
var redirect: Redirect?

Expand All @@ -44,10 +47,11 @@ final class MainBanner: Model, Content, @unchecked Sendable {

init() {}

init(id: UUID? = nil, title: String?, placeType: PlaceType?, parentID: MainBanner.IDValue? = nil) {
init(id: UUID? = nil, title: String?, placeType: PlaceType?, placeIndex: Int, parentID: MainBanner.IDValue? = nil) {
self.id = id
self.title = title
self.placeType = placeType
self.placeIndex = placeIndex
self.$parent.id = parentID
}

Expand Down

0 comments on commit 73ddb7d

Please sign in to comment.