-
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.
Refactor id and reg no, create posts model
- Loading branch information
1 parent
63949a6
commit 452e725
Showing
13 changed files
with
113 additions
and
55 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// 004_CreatePosts.swift | ||
// | ||
// | ||
// Created by Shrish Deshpande on 05/01/24. | ||
// | ||
|
||
import Fluent | ||
|
||
struct CreatePosts: Migration { | ||
func prepare(on database: Database) -> EventLoopFuture<Void> { | ||
return database.schema("posts") | ||
.field("id", .string, .required) | ||
.field("user", .int, .required, .references("registeredUsers", "regNo")) | ||
.field("content", .string, .required) | ||
.field("created_at", .datetime, .required) | ||
.field("deleted", .bool, .required) | ||
.unique(on: "id") | ||
.create() | ||
} | ||
|
||
func revert(on database: Database) -> EventLoopFuture<Void> { | ||
return database.schema("posts").delete() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Post.swift | ||
// | ||
// | ||
// Created by Shrish Deshpande on 05/01/24. | ||
// | ||
|
||
import Vapor | ||
import Fluent | ||
|
||
final class Post: Model, Content { | ||
public static let schema = "posts" | ||
|
||
@ID(custom: "id", generatedBy: .user) | ||
var id: String? | ||
|
||
@Field(key: "user") | ||
var user: Int | ||
|
||
@Field(key: "content") | ||
var content: String | ||
|
||
@Timestamp(key: "created_at", on: .create) | ||
var createdAt: Date? | ||
|
||
@Field(key: "deleted") | ||
var deleted: Bool | ||
|
||
init() { | ||
} | ||
|
||
// TODO: attachments (media), comments enabled, edited | ||
init(id: String, regNo user: Int, content: String) { | ||
self.id = id | ||
self.user = user | ||
self.content = content | ||
self.deleted = false | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,4 @@ final class UnregisteredUser: Model, Content { | |
self.branch = branch | ||
self.gender = gender | ||
} | ||
|
||
|
||
} |