Skip to content

Commit

Permalink
Feat: example controller ์ถ”๊ฐ€ (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaewon-pro authored Jul 24, 2024
1 parent e648714 commit e6d1f9d
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/main/java/com/dnd/runus/domain/example/ExampleController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.dnd.runus.domain.example;

import com.dnd.runus.global.exception.BusinessException;
import com.dnd.runus.global.exception.type.ApiErrorType;
import com.dnd.runus.global.exception.type.ErrorType;
import io.swagger.v3.oas.annotations.Operation;
import lombok.Getter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/examples")
public class ExampleController { // FIXME: ์ถ”ํ›„ ์‚ญ์ œ
@Operation(summary = "ํŽ˜์ด์ง• ํ…Œ์ŠคํŠธ, ๋ณต์žกํ•œ ํŽ˜์ด์ง•(pageable) ๊ฒฐ๊ณผ๋Š” ๋‚˜์ค‘์— ์ •ํ•ด์„œ ๊ฐ„๋žตํ™”ํ•ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”")
@GetMapping("/pagination")
public Page<?> a(Pageable pageable) {
List<String> list = List.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j");
List<String> sublist = list.subList(
(int) pageable.getOffset(), Math.min((int) pageable.getOffset() + pageable.getPageSize(), list.size()));
return new PageImpl<>(sublist, pageable, list.size());
}

@Operation(summary = "input ํ…Œ์ŠคํŠธ, input์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/input")
public String name(@RequestParam String input) {
return input;
}

@Operation(summary = "header ํ…Œ์ŠคํŠธ, request์™€ ํ•จ๊ป˜ ์ž…๋ ฅํ•œ header๋“ค์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/headers")
public Map<String, String> headers(@RequestHeader(value = "authorization") Map<String, String> headers) {
return headers;
}

@Operation(summary = "๋ฐ์ดํ„ฐ ํ…Œ์ŠคํŠธ, ์‹œ๊ฐ„ ๊ด€๋ จ ํ˜•์‹๋„ ์ •ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”")
@GetMapping("/data")
public MyData data() {
return new MyData();
}

@Getter
public static class MyData {
int a;
String b = "b";
Instant c = Instant.now();
String d = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME);
}

@GetMapping("/empty")
@ResponseStatus(HttpStatus.OK)
public void empty() {}

@Operation(summary = "COOKIE_NOT_FOND ์—๋Ÿฌ ํ…Œ์ŠคํŠธ")
@ApiErrorType({ErrorType.COOKIE_NOT_FOND, ErrorType.FAILED_VALIDATION})
@GetMapping("/errors")
public String errors() {
throw new BusinessException(ErrorType.COOKIE_NOT_FOND, "์ฟ ํ‚ค ์ด๋ฆ„~~");
}
}

0 comments on commit e6d1f9d

Please sign in to comment.