Skip to content

Commit

Permalink
refactor(http): MethodNotAllowSupport trait more abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Feb 13, 2024
1 parent 12e4f85 commit 3bdcbf2
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.yoshinorin.qualtet.http

import cats.effect.IO
import cats.Monad
import org.slf4j.LoggerFactory
import org.http4s.{Request, Response}
import org.http4s.headers.Allow
import org.http4s.dsl.io.*

trait MethodNotAllowedSupport {
trait MethodNotAllowedSupport[F[_]: Monad] {
private[this] val logger = LoggerFactory.getLogger(this.getClass)

private[http] def methodNotAllowed(request: Request[IO], allow: Allow): IO[Response[IO]] = {
private[http] def methodNotAllowed(request: Request[F], allow: Allow) = {
logger.error(s"method not allowed: ${request}")
MethodNotAllowed(allow)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import net.yoshinorin.qualtet.syntax.*

class ArchiveRoute[F[_]: Monad](
archiveService: ArchiveService[F]
) extends MethodNotAllowedSupport {
) extends MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { r =>
implicit val x = r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import net.yoshinorin.qualtet.syntax.*

class ArticleRoute[F[_]: Monad](
articleService: ArticleService[F]
) extends MethodNotAllowedSupport {
) extends MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { r =>
implicit val x = r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import net.yoshinorin.qualtet.auth.{AuthService, RequestToken}
import net.yoshinorin.qualtet.http.{MethodNotAllowedSupport, RequestDecoder}
import net.yoshinorin.qualtet.syntax.*

class AuthRoute[F[_]: Monad](authService: AuthService[F]) extends RequestDecoder with MethodNotAllowedSupport {
class AuthRoute[F[_]: Monad](authService: AuthService[F]) extends RequestDecoder with MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { r =>
implicit val x = r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.yoshinorin.qualtet.http.MethodNotAllowedSupport

class AuthorRoute[F[_]: Monad](
authorService: AuthorService[F]
) extends MethodNotAllowedSupport {
) extends MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { r =>
implicit val x = r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import net.yoshinorin.qualtet.http.{AuthProvider, MethodNotAllowedSupport}
class CacheRoute[F[_]: Monad](
authProvider: AuthProvider[F],
cacheService: CacheService[F]
) extends MethodNotAllowedSupport {
) extends MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = authProvider.authenticate(AuthedRoutes.of { ctxRequest =>
(ctxRequest match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ContentRoute[F[_]: Monad](
authProvider: AuthProvider[F],
contentService: ContentService[F]
) extends RequestDecoder
with MethodNotAllowedSupport {
with MethodNotAllowedSupport[IO] {

private[this] val logger = LoggerFactory.getLogger(this.getClass)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.yoshinorin.qualtet.syntax.*

class ContentTypeRoute[F[_]: Monad](
contentTypeService: ContentTypeService[F]
) extends MethodNotAllowedSupport {
) extends MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { r =>
implicit val x = r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.yoshinorin.qualtet.http.MethodNotAllowedSupport

class FeedRoute[F[_]: Monad](
feedService: FeedService[F]
) extends MethodNotAllowedSupport {
) extends MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { r =>
implicit val x = r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.yoshinorin.qualtet.http.MethodNotAllowedSupport

class SearchRoute[F[_]: Monad](
searchService: SearchService[F]
) extends MethodNotAllowedSupport {
) extends MethodNotAllowedSupport[IO] {

private[this] val logger = LoggerFactory.getLogger(this.getClass)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SeriesRoute[F[_]: Monad](
authProvider: AuthProvider[F],
seriesService: SeriesService[F]
) extends RequestDecoder
with MethodNotAllowedSupport {
with MethodNotAllowedSupport[IO] {

// NOTE: must be compose `auth route` after `Non auth route`.
private[http] def index: HttpRoutes[IO] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import net.yoshinorin.qualtet.domains.sitemaps.SitemapService
import net.yoshinorin.qualtet.syntax.*
import net.yoshinorin.qualtet.http.MethodNotAllowedSupport

class SitemapRoute[F[_]: Monad](sitemapService: SitemapService[F]) extends MethodNotAllowedSupport {
class SitemapRoute[F[_]: Monad](sitemapService: SitemapService[F]) extends MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { r =>
implicit val x = r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import net.yoshinorin.qualtet.ApplicationInfo
import net.yoshinorin.qualtet.syntax.*
import net.yoshinorin.qualtet.config.HttpSystemEndpointConfig

class SystemRoute(config: HttpSystemEndpointConfig) extends MethodNotAllowedSupport {
class SystemRoute(config: HttpSystemEndpointConfig) extends MethodNotAllowedSupport[IO] {

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { r =>
implicit val x = r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TagRoute[F[_]: Monad](
authProvider: AuthProvider[F],
tagService: TagService[F],
articleService: ArticleService[F]
) extends MethodNotAllowedSupport {
) extends MethodNotAllowedSupport[IO] {

private[this] val logger = LoggerFactory.getLogger(this.getClass)

Expand Down

0 comments on commit 3bdcbf2

Please sign in to comment.