Skip to content

Commit

Permalink
feat: 헬스체크용 API 추가 (#56)
Browse files Browse the repository at this point in the history
* refactor: RootController 분리

* refactor: WebController -> AppController 이름 변경

* fix: 클래스 가시성 조절

* feat: /api/health 컨트롤러 추가
  • Loading branch information
daengdaengLee authored Sep 14, 2023
1 parent 65e9bfb commit daa4f13
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class ApiController {
this.shortenUrlService = shortenUrlService;
}

@RequestMapping("/health")
void health() {
}

@PostMapping("/shorten")
ShortenResponse shorten(@RequestBody ShortenRequest shortenRequest) {
String shortUrlCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package io.github.daengdaenglee.mangurl.inboundadapter.web;
package io.github.daengdaenglee.mangurl.inboundadapter.app;

import io.github.daengdaenglee.mangurl.application.url.inboundport.EncodeUrlService;
import io.github.daengdaenglee.mangurl.application.url.inboundport.RestoreUrlService;
import io.github.daengdaenglee.mangurl.application.url.inboundport.ShortenUrlService;
import io.github.daengdaenglee.mangurl.config.properties.MangurlProperties;
import io.github.daengdaenglee.mangurl.inboundadapter.web.form.ShortenUrlForm;
import io.github.daengdaenglee.mangurl.inboundadapter.app.form.ShortenUrlForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
Expand All @@ -15,37 +14,22 @@

@Slf4j
@Controller
class WebController {
@RequestMapping("/app")
class AppController {
private final String origin;
private final EncodeUrlService encodeUrlService;
private final ShortenUrlService shortenUrlService;
private final RestoreUrlService restoreUrlService;

WebController(
AppController(
MangurlProperties mangurlProperties,
EncodeUrlService encodeUrlService,
ShortenUrlService shortenUrlService,
RestoreUrlService restoreUrlService) {
ShortenUrlService shortenUrlService) {
this.origin = mangurlProperties.getOrigin();
this.encodeUrlService = encodeUrlService;
this.shortenUrlService = shortenUrlService;
this.restoreUrlService = restoreUrlService;
}

@RequestMapping("/{shortUrlCode}")
String redirect(@PathVariable String shortUrlCode) {
return this.restoreUrlService.restoreUrl(shortUrlCode)
.map(this.encodeUrlService::encode)
.map(url -> "redirect:" + url)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}

@RequestMapping
String home() {
return "redirect:/app";
}

@GetMapping("/app")
@GetMapping
String app(
@RequestParam(value = "result", required = false) String result,
@RequestParam(value = "resOriginalUrl", defaultValue = "") String resOriginalUrl,
Expand Down Expand Up @@ -79,7 +63,7 @@ String app(
return "app";
}

@PostMapping("/app")
@PostMapping
String shorten(
@ModelAttribute ShortenUrlForm shortenUrlForm,
RedirectAttributes redirectAttributes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.github.daengdaenglee.mangurl.inboundadapter.app.form;

public record ShortenUrlForm(String originalUrl) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.daengdaenglee.mangurl.inboundadapter.root;

import io.github.daengdaenglee.mangurl.application.url.inboundport.EncodeUrlService;
import io.github.daengdaenglee.mangurl.application.url.inboundport.RestoreUrlService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.server.ResponseStatusException;

@Slf4j
@RequiredArgsConstructor
@Controller
class RootController {
private final RestoreUrlService restoreUrlService;
private final EncodeUrlService encodeUrlService;

@RequestMapping("/{shortUrlCode}")
String redirect(@PathVariable String shortUrlCode) {
return this.restoreUrlService.restoreUrl(shortUrlCode)
.map(this.encodeUrlService::encode)
.map(url -> "redirect:" + url)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}

@RequestMapping
String home() {
return "redirect:/app";
}
}

This file was deleted.

0 comments on commit daa4f13

Please sign in to comment.