Skip to content

Commit

Permalink
ref objct to object (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsumura-h authored Feb 16, 2024
1 parent a042b05 commit 4696bc5
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/basolato/cli/functions/make/layout.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import std/asyncdispatch
import std/json
type {targetCaptalizedType}ViewModel* = ref object
type {targetCaptalizedType}ViewModel* = object
proc new*(_:type {targetCaptalizedType}ViewModel):{targetCaptalizedType}ViewModel =
discard
Expand Down
6 changes: 3 additions & 3 deletions src/basolato/cli/functions/make/model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ proc makeModel*(target:string, message:var string):int =
import {relativeToValueObjectsPath}
type {targetCaptalized}* = ref object
type {targetCaptalized}* = object
proc new*(_:type {targetCaptalized}):{targetCaptalized} =
return {targetCaptalized}()
Expand All @@ -47,7 +47,7 @@ import ../../../models/{targetName}/{targetName}_entity
import ../../../models/{targetName}/{targetName}_repository_interface
type {targetCaptalized}Repository* = ref object
type {targetCaptalized}Repository* = object
proc new*(_:type {targetCaptalized}Repository):{targetCaptalized}Repository =
return {targetCaptalized}Repository()
Expand All @@ -62,7 +62,7 @@ import {relativeToRepoInterface}
import {targetName}_entity
type {targetCaptalized}Service* = ref object
type {targetCaptalized}Service* = object
repository: I{targetCaptalized}Repository
proc new*(_:type {targetCaptalized}Service, repository:I{parentCapitalized}Repository):{targetCaptalized}Service =
Expand Down
2 changes: 1 addition & 1 deletion src/basolato/cli/functions/make/query.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from {relativeToDatabasePath}config/database import rdb
import {relativeToInterfacePath}usecases/{target}/{targetName}_query_interface
type {targetCaptalized}Query* = ref object
type {targetCaptalized}Query* = object
proc new*(typ:type {targetCaptalized}Query):{targetCaptalized}Query =
return {targetCaptalized}Query()
Expand Down
4 changes: 2 additions & 2 deletions src/basolato/cli/functions/make/usecase.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {relativeToDiContainer}
import {dir}_query_interface
type {targetCaptalized}Usecase* = ref object
type {targetCaptalized}Usecase* = object
query: I{dirCaptalized}Query
proc new*(_:type {targetCaptalized}Usecase):{targetCaptalized}Usecase =
Expand All @@ -40,7 +40,7 @@ from ../../../config/database import rdb
import ../../usecases/{dir}/{dir}_query_interface
type {dirCaptalized}Query* = ref object
type {dirCaptalized}Query* = object
proc new*(_:type {dirCaptalized}Query):{dirCaptalized}Query =
return {dirCaptalized}Query()
Expand Down
2 changes: 1 addition & 1 deletion src/basolato/cli/functions/make/valueobject.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ proc makeValueObject*(aggregate, target, message:var string):int =
let VALUEOBJECT = &"""
type {target}* = ref object
type {target}* = object
value:string
proc new*(_:type {target}, value:string):{target} =
Expand Down
2 changes: 1 addition & 1 deletion src/basolato/core/route.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ else:

type Controller* = proc(c:Context, params:Params):Future[Response] {.async.}

type Middleware* = ref object
type Middleware* = object
action: Controller

proc action*(self:Middleware):Controller =
Expand Down
4 changes: 2 additions & 2 deletions src/basolato/core/security/cookie.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type
SameSite = enum
None, Lax, Strict

Cookie* = ref object
Cookie* = object
name:string
value:string
expire:string
Expand All @@ -24,7 +24,7 @@ type
domain:string
path:string

Cookies* = ref object
Cookies* = object
request:Request
data*:seq[Cookie]

Expand Down
2 changes: 1 addition & 1 deletion src/basolato/core/security/csrf_token.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import std/strformat
import ./session


type CsrfToken* = ref object
type CsrfToken* = object
token:string

proc new*(_:type CsrfToken, token=""):CsrfToken =
Expand Down
2 changes: 1 addition & 1 deletion src/basolato/core/security/session.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else:

var globalCsrfToken*:string

type Session* = ref object
type Session* = object
db: SessionDb


Expand Down
2 changes: 1 addition & 1 deletion src/basolato/core/security/session_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ when SESSION_TYPE == "redis":
else:
import ./session_db/json_session_db

type SessionDb* = ref object
type SessionDb* = object
impl:ISessionDb

proc new*(_:type SessionDb, sessionId=""):Future[SessionDb] {.async.} =
Expand Down
2 changes: 1 addition & 1 deletion src/basolato/core/security/session_db/json_session_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ./session_db_interface

var globalCsrfToken*:string

type JsonSessionDb* = ref object
type JsonSessionDb* = object
db:JsonFileDb


Expand Down
2 changes: 1 addition & 1 deletion src/basolato/core/security/session_db/redis_session_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ../random_string
import ./session_db_interface


type RedisSessionDb* = ref object
type RedisSessionDb* = object
conn: AsyncRedis
id: string

Expand Down
2 changes: 1 addition & 1 deletion src/basolato/core/validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import std/unicode
import std/times


type Validation* = ref object
type Validation* = object

func newValidation*():Validation =
return Validation()
Expand Down
23 changes: 11 additions & 12 deletions src/basolato/middleware.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ else:
import ./core/libservers/std/request; export request


type MiddlewareResult* = ref object
type MiddlewareResult* = object
hasError: bool
message: string

proc new(_:type MiddlewareResult, hasError=false, message=""):MiddlewareResult =
return MiddlewareResult(hasError: hasError, message: message)


func hasError*(self:MiddlewareResult):bool =
return self.hasError

Expand All @@ -32,7 +36,7 @@ func next*(status=HttpCode(0), body="", headers:HttpHeaders=newHttpHeaders()):Re
return Response.new(status, body, headers)

proc checkCsrfToken*(request:Request, params:Params):Future[MiddlewareResult] {.async.} =
result = MiddlewareResult()
result = MiddlewareResult.new()
if request.httpMethod == HttpPost and not (request.headers.hasKey("content-type") and request.headers["content-type"].contains("application/json")):
try:
if not params.hasKey("csrf_token"):
Expand All @@ -44,13 +48,12 @@ proc checkCsrfToken*(request:Request, params:Params):Future[MiddlewareResult] {.
if not csrfToken.checkCsrfValid(session).await:
raise newException(Exception, "Invalid csrf token")
except:
result.hasError = true
result.message = getCurrentExceptionMsg()
result = MiddlewareResult.new(true, getCurrentExceptionMsg())


proc checkCsrf*(context:Context):Future[MiddlewareResult] {.async.} =
## check origin header in request which is sent by same host or allowed host
result = MiddlewareResult()
result = MiddlewareResult.new()
try:
# check origin header
let request = context.request
Expand All @@ -66,15 +69,12 @@ proc checkCsrf*(context:Context):Future[MiddlewareResult] {.async.} =
raise newException(Exception, "Invalid origin")
# check
except:
result.hasError = true
result.message = getCurrentExceptionMsg()


result = MiddlewareResult.new(true, getCurrentExceptionMsg())


proc checkSessionId*(request:Request):Future[MiddlewareResult] {.async.} =
## Check session id in cookie is valid.
result = MiddlewareResult()
result = MiddlewareResult.new()
if request.httpMethod != HttpOptions:
let cookie = Cookies.new(request)
try:
Expand All @@ -86,5 +86,4 @@ proc checkSessionId*(request:Request):Future[MiddlewareResult] {.async.} =
if not SessionDb.checkSessionIdValid(sessionId).await:
raise newException(Exception, "Invalid session id")
except:
result.hasError = true
result.message = getCurrentExceptionMsg()
result = MiddlewareResult.new(true, getCurrentExceptionMsg())
2 changes: 1 addition & 1 deletion src/basolato/request_validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func add*(self:ValidationErrors, key, value:string) =
self[key] = @[value]


type RequestValidation* = ref object
type RequestValidation* = object
params: Params
errors: ValidationErrors

Expand Down
2 changes: 1 addition & 1 deletion src/basolato/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func old*(params:Params, key:string, default=""):string =


# ========== style ==========
type Style* = ref object
type Style* = object
body:string
saffix:string

Expand Down

0 comments on commit 4696bc5

Please sign in to comment.