the filter value type
10 | * @param the pagination value type (inclusive or exclusive value type)
11 | * @param the id type
12 | * @param the entity type
13 | */
14 | public abstract class DefaultPaginationService
15 | extends DefaultPaginationResultService {
16 |
17 | public DefaultPaginationService(
18 | PaginationRepository repository
19 | ) {
20 | super(repository);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/unit-test/src/main/java/org/youngmonkeys/ut/VirtualMachine.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.ut;
2 |
3 | import lombok.AllArgsConstructor;
4 |
5 | @AllArgsConstructor
6 | public class VirtualMachine {
7 |
8 | private final Calculator calculator;
9 |
10 | public String evaluate(String expression) {
11 | String[] strings = expression.split(" ");
12 | if ("+".equals(strings[1])) {
13 | return String.valueOf(
14 | calculator.sum(
15 | Integer.parseInt(strings[0]),
16 | Integer.parseInt(strings[2])
17 | )
18 | );
19 | }
20 | throw new IllegalArgumentException(
21 | "only support plus operation"
22 | );
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/dont-forget-security/client/tsconfig.node.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4 | "target": "ES2023",
5 | "lib": ["ES2023"],
6 | "module": "ESNext",
7 | "skipLibCheck": true,
8 |
9 | /* Bundler mode */
10 | "moduleResolution": "bundler",
11 | "allowImportingTsExtensions": true,
12 | "verbatimModuleSyntax": true,
13 | "moduleDetection": "force",
14 | "noEmit": true,
15 |
16 | /* Linting */
17 | "strict": true,
18 | "noUnusedLocals": true,
19 | "noUnusedParameters": true,
20 | "erasableSyntaxOnly": true,
21 | "noFallthroughCasesInSwitch": true,
22 | "noUncheckedSideEffectImports": true
23 | },
24 | "include": ["vite.config.ts"]
25 | }
26 |
--------------------------------------------------------------------------------
/write-dry-code/src/main/java/org/youngmonkeys/wdc/duplicated_initiation/v2/converter/ModelToResponseConverter.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.wdc.duplicated_initiation.v2.converter;
2 |
3 | import org.youngmonkeys.wdc.duplicated_initiation.v1.model.UserModel;
4 | import org.youngmonkeys.wdc.duplicated_initiation.v1.response.UserResponse;
5 |
6 | import com.tvd12.ezyfox.bean.annotation.EzySingleton;
7 |
8 | @EzySingleton
9 | public class ModelToResponseConverter {
10 |
11 | public UserResponse toResponse(UserModel model) {
12 | return UserResponse
13 | .builder()
14 | .uuid(model.getUuid())
15 | .displayName(model.getDisplayName())
16 | .profileUrl(model.getProfileUrl())
17 | .build();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/clean-code/src/main/java/org/youngmonkeys/cc/v2/entity/UserRole.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.cc.v2.entity;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.Id;
6 | import javax.persistence.IdClass;
7 | import javax.persistence.Table;
8 |
9 | import lombok.AllArgsConstructor;
10 | import lombok.Getter;
11 | import lombok.NoArgsConstructor;
12 | import lombok.Setter;
13 |
14 | @Getter
15 | @Setter
16 | @AllArgsConstructor
17 | @NoArgsConstructor
18 | @Entity
19 | @Table(name = "user_roles")
20 | @IdClass(UserRoleId.class)
21 | public class UserRole {
22 |
23 | @Id
24 | @Column(name = "user_id")
25 | private long userId;
26 |
27 | @Id
28 | @Column(name = "role_id")
29 | private long roleId;
30 | }
31 |
--------------------------------------------------------------------------------
/dont-forget-security/src/main/java/org/youngmonkeys/dfs/file_upload/service/SettingService.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.dfs.file_upload.service;
2 |
3 | import com.tvd12.ezyfox.collect.Sets;
4 | import com.tvd12.ezyhttp.core.constant.ContentType;
5 | import com.tvd12.ezyhttp.server.core.annotation.Service;
6 |
7 | import java.util.Set;
8 |
9 | @Service
10 | public class SettingService {
11 |
12 | public long getMaxUploadFileSize() {
13 | return 50 * 1024 * 1024;
14 | }
15 |
16 | public Set getAcceptedMediaMimeTypes() {
17 | return Sets.newHashSet(
18 | ContentType.IMAGE_JPEG.getMimeType(),
19 | ContentType.IMAGE_JPG.getMimeType(),
20 | ContentType.IMAGE_PNG.getMimeType()
21 | );
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/self-comment/src/main/java/org/youngmonkeys/sc/v1/repo/PostRepository.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.sc.v1.repo;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.youngmonkeys.sc.v1.entity.Post;
7 |
8 | import com.tvd12.ezyfox.bean.annotation.EzySingleton;
9 | import com.tvd12.ezyfox.database.annotation.EzyQuery;
10 |
11 | @EzySingleton
12 | public class PostRepository {
13 | @EzyQuery(
14 | "SELECT e FROM Post e " +
15 | "WHERE e.priority < ?0 OR (e.priority = ?0 AND e.id < ?0) " +
16 | "ORDER BY e.priority DESC, e.id DESC LIMIT ?2"
17 | )
18 | public List findPosts(
19 | int priority,
20 | int id,
21 | int limit
22 | ) {
23 | return new ArrayList<>();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/liskov-substitution/src/main/java/org/youngmonkeys/ls/paint/v1/Paint.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.ls.paint.v1;
2 |
3 | import org.youngmonkeys.ls.paint.Position;
4 | import org.youngmonkeys.ls.paint.Size;
5 |
6 | public class Paint {
7 |
8 | public void pain(Shape shape) {
9 | System.out.println("paint: " + shape);
10 | }
11 |
12 | public static void main(String[] args) {
13 | Paint paint = new Paint();
14 | paint.pain(
15 | new Rectangle(
16 | new Position(1, 2),
17 | new Size(3, 4)
18 | )
19 | );
20 |
21 | paint.pain(
22 | new Square(
23 | new Position(1, 2),
24 | new Size(3, 4)
25 | )
26 | );
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/dont-forget-security/src/main/java/org/youngmonkeys/dfs/limit_request_rate/EzyActionFrameSecond.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.dfs.limit_request_rate;
2 |
3 | public class EzyActionFrameSecond extends EzyActionFrame {
4 |
5 | public EzyActionFrameSecond() {
6 | this(Integer.MAX_VALUE);
7 | }
8 |
9 | public EzyActionFrameSecond(long maxActions) {
10 | super(maxActions);
11 | }
12 |
13 | public EzyActionFrameSecond(long maxActions, long startTime) {
14 | super(maxActions, startTime);
15 | }
16 |
17 | @Override
18 | protected final int getExistsTime() {
19 | return 1000;
20 | }
21 |
22 | @Override
23 | public final EzyActionFrame nextFrame() {
24 | return new EzyActionFrameSecond(maxActions, endTime);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/write-dry-code/src/main/java/org/youngmonkeys/wdc/duplicated_method/v1/converter/PageModelToEntityConverter.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.wdc.duplicated_method.v1.converter;
2 |
3 | import org.youngmonkeys.wdc.duplicated_method.v1.entity.Page;
4 | import org.youngmonkeys.wdc.duplicated_method.v1.model.AddPageModel;
5 | import org.youngmonkeys.wdc.duplicated_method.v1.model.AddPageModel;
6 |
7 | import com.tvd12.ezyfox.bean.annotation.EzySingleton;
8 |
9 | @EzySingleton
10 | public class PageModelToEntityConverter {
11 |
12 | public Page toEntity(AddPageModel model) {
13 | Page page = new Page();
14 | page.setTitle(model.getTitle());
15 | page.setContent(model.getContent());
16 | page.setCategoryId(model.getCategoryId());
17 | return page;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/clean-code/src/main/java/org/youngmonkeys/cc/v2/converter/ModelToEntityConverter.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.cc.v2.converter;
2 |
3 | import org.youngmonkeys.cc.v2.entity.User;
4 | import org.youngmonkeys.cc.v2.model.CreateUserModel;
5 |
6 | import com.tvd12.ezyfox.bean.annotation.EzySingleton;
7 | import com.tvd12.ezyfox.security.EzySHA256;
8 |
9 | @EzySingleton
10 | public class ModelToEntityConverter {
11 |
12 | public User toEntity(CreateUserModel model) {
13 | User entity = new User();
14 | entity.setEmail(model.getEmail());
15 | entity.setPassword(EzySHA256.cryptUtf(model.getPassword()));
16 | entity.setUsername(model.getUsername());
17 | entity.setActive(true);
18 | entity.setEmailVerified(false);
19 | return entity;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/dependency-inversion/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.youngmonkeys
8 | programming-principles
9 | 1.0.0
10 |
11 |
12 | dependency-inversion
13 |
14 |
15 |
16 | org.youngmonkeys
17 | hourly-scheduler
18 | ${project.version}
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/interface-segregation/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.youngmonkeys
8 | programming-principles
9 | 1.0.0
10 |
11 |
12 | interface-segregation
13 |
14 |
15 | 11
16 | 11
17 | UTF-8
18 |
19 |
20 |
--------------------------------------------------------------------------------
/composition-over-inheritance/src/main/java/org/youngmonkeys/coi/controller/api/v2/BaseUserController.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.coi.controller.api.v2;
2 |
3 | import org.youngmonkeys.coi.converter.ModelToResponseConverter;
4 | import org.youngmonkeys.coi.model.UserModel;
5 | import org.youngmonkeys.coi.response.UserResponse;
6 | import org.youngmonkeys.coi.service.UserService;
7 |
8 | import lombok.AllArgsConstructor;
9 |
10 | @AllArgsConstructor
11 | public class BaseUserController {
12 |
13 | protected UserService userService;
14 | protected ModelToResponseConverter responseConverter;
15 |
16 | protected UserResponse getUserByIdToResponse(
17 | long userId
18 | ) {
19 | UserModel user = userService.getUserById(userId);
20 | return responseConverter.toResponse(user);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/dont-forget-security/client/src/App.css:
--------------------------------------------------------------------------------
1 | #root {
2 | max-width: 1280px;
3 | margin: 0 auto;
4 | padding: 2rem;
5 | text-align: center;
6 | }
7 |
8 | .logo {
9 | height: 6em;
10 | padding: 1.5em;
11 | will-change: filter;
12 | transition: filter 300ms;
13 | }
14 | .logo:hover {
15 | filter: drop-shadow(0 0 2em #646cffaa);
16 | }
17 | .logo.react:hover {
18 | filter: drop-shadow(0 0 2em #61dafbaa);
19 | }
20 |
21 | @keyframes logo-spin {
22 | from {
23 | transform: rotate(0deg);
24 | }
25 | to {
26 | transform: rotate(360deg);
27 | }
28 | }
29 |
30 | @media (prefers-reduced-motion: no-preference) {
31 | a:nth-of-type(2) .logo {
32 | animation: logo-spin infinite 20s linear;
33 | }
34 | }
35 |
36 | .card {
37 | padding: 2em;
38 | }
39 |
40 | .read-the-docs {
41 | color: #888;
42 | }
43 |
--------------------------------------------------------------------------------
/interface-segregation/src/main/java/org/youngmonkeys/is/db/SimpleMongodbRepository.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.is.db;
2 |
3 | import java.util.Collection;
4 | import java.util.List;
5 |
6 | public class SimpleMongodbRepository implements MongodbRepository {
7 | @Override
8 | public void save(E entity) {}
9 |
10 | @Override
11 | public void save(Collection entities) {}
12 |
13 | @Override
14 | public E findById(I id) {
15 | return null;
16 | }
17 |
18 | @Override
19 | public void deleteById(I id) {}
20 |
21 | @Override
22 | public long increment(String field, long value) {
23 | return 0;
24 | }
25 |
26 | @Override
27 | public List aggregateListWithQuery(String query, Class result) {
28 | return null;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/dont-forget-security/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "tsc -b && vite build",
9 | "lint": "eslint .",
10 | "preview": "vite preview"
11 | },
12 | "dependencies": {
13 | "react": "^19.1.0",
14 | "react-dom": "^19.1.0"
15 | },
16 | "devDependencies": {
17 | "@eslint/js": "^9.30.1",
18 | "@types/react": "^19.1.8",
19 | "@types/react-dom": "^19.1.6",
20 | "@vitejs/plugin-react": "^4.6.0",
21 | "eslint": "^9.30.1",
22 | "eslint-plugin-react-hooks": "^5.2.0",
23 | "eslint-plugin-react-refresh": "^0.4.20",
24 | "globals": "^16.3.0",
25 | "typescript": "~5.8.3",
26 | "typescript-eslint": "^8.35.1",
27 | "vite": "^7.0.4"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/dont-forget-security/src/main/java/org/youngmonkeys/dfs/zeroday/ZeroDayController.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.dfs.zeroday;
2 |
3 | import com.tvd12.ezyhttp.core.response.ResponseEntity;
4 | import com.tvd12.ezyhttp.server.core.annotation.Controller;
5 | import com.tvd12.ezyhttp.server.core.annotation.DoGet;
6 | import com.tvd12.ezyhttp.server.core.annotation.RequestParam;
7 |
8 | @Controller
9 | public class ZeroDayController {
10 |
11 | private final Logger logger = new Logger();
12 |
13 | @DoGet("/zeroday")
14 | public ResponseEntity zerodayGet(
15 | @RequestParam("fileUrl") String fileUrl
16 | ) throws Exception {
17 | logger.info(fileUrl);
18 | return ResponseEntity.builder()
19 | .body("fileContent")
20 | .textPlain()
21 | .build();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/liskov-substitution/src/main/java/org/youngmonkeys/ls/paint/v2/Paint.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.ls.paint.v2;
2 |
3 | import org.youngmonkeys.ls.paint.Position;
4 | import org.youngmonkeys.ls.paint.Size;
5 |
6 | public class Paint {
7 | public void pain(Shape shape) {
8 | if (shape.isValid()) {
9 | System.out.println("paint: " + shape);
10 | }
11 | }
12 |
13 | public static void main(String[] args) {
14 | Paint paint = new Paint();
15 | paint.pain(
16 | new Rectangle(
17 | new Position(1, 2),
18 | new Size(3, 4)
19 | )
20 | );
21 |
22 | paint.pain(
23 | new Square(
24 | new Position(1, 2),
25 | new Size(3, 4)
26 | )
27 | );
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/document-your-code/src/main/java/org/youngmonkeys/dyc/entity/Post.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.dyc.entity;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.EnumType;
6 | import javax.persistence.Enumerated;
7 | import javax.persistence.Id;
8 | import javax.persistence.Table;
9 |
10 | import lombok.Getter;
11 | import lombok.Setter;
12 |
13 | @Getter
14 | @Setter
15 | @Entity
16 | @Table(name = "posts")
17 | public class Post {
18 | @Id
19 | private long id;
20 |
21 | private String title;
22 |
23 | private String content;
24 |
25 | @Column(name = "post_type")
26 | @Enumerated(EnumType.STRING)
27 | private PostType postType;
28 |
29 | @Column(name = "post_status")
30 | @Enumerated(EnumType.STRING)
31 | private PostStatus postStatus;
32 | }
33 |
--------------------------------------------------------------------------------
/self-comment/src/main/java/org/youngmonkeys/sc/v2/repo/PaginationPostRepository.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.sc.v2.repo;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.youngmonkeys.sc.v1.entity.Post;
7 |
8 | import com.tvd12.ezyfox.bean.annotation.EzySingleton;
9 | import com.tvd12.ezyfox.database.annotation.EzyQuery;
10 |
11 | @EzySingleton
12 | public class PaginationPostRepository {
13 | @EzyQuery(
14 | "SELECT e FROM Post e " +
15 | "WHERE e.priority < ?0 OR (e.priority = ?0 AND e.id < ?0) " +
16 | "ORDER BY e.priority DESC, e.id DESC LIMIT ?2"
17 | )
18 | public List findPostsByPriorityDescAndIdDesc(
19 | int priorityInclusive,
20 | int idExclusive,
21 | int limit
22 | ) {
23 | return new ArrayList<>();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/code-smell/src/main/java/org/youngmonkeys/code_smell/TooManyParameter.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.code_smell;
2 |
3 | import lombok.AllArgsConstructor;
4 | import org.youngmonkeys.code_smell.entity.UserEntity;
5 | import org.youngmonkeys.code_smell.repository.UserRepository;
6 |
7 | @AllArgsConstructor
8 | public class TooManyParameter {
9 |
10 | private final UserRepository userRepository;
11 |
12 | public void saveUser(
13 | String username,
14 | String password,
15 | String displayName,
16 | String email
17 | ) {
18 | UserEntity entity = new UserEntity();
19 | entity.setUsername(username);
20 | entity.setPassword(password);
21 | entity.setDisplayName(displayName);
22 | entity.setEmail(email);
23 | userRepository.saveUser(entity);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/chat/chat-plugin/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/game/game-plugin/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/dont-forget-security/client/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4 | "target": "ES2022",
5 | "useDefineForClassFields": true,
6 | "lib": ["ES2022", "DOM", "DOM.Iterable"],
7 | "module": "ESNext",
8 | "skipLibCheck": true,
9 |
10 | /* Bundler mode */
11 | "moduleResolution": "bundler",
12 | "allowImportingTsExtensions": true,
13 | "verbatimModuleSyntax": true,
14 | "moduleDetection": "force",
15 | "noEmit": true,
16 | "jsx": "react-jsx",
17 |
18 | /* Linting */
19 | "strict": true,
20 | "noUnusedLocals": true,
21 | "noUnusedParameters": true,
22 | "erasableSyntaxOnly": true,
23 | "noFallthroughCasesInSwitch": true,
24 | "noUncheckedSideEffectImports": true
25 | },
26 | "include": ["src"]
27 | }
28 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/chat/chat-app-api/src/main/java/org/youngmonkeys/chat/app/service/GreetingService.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.chat.app.service;
2 |
3 | import org.youngmonkeys.chat.app.config.AppConfig;
4 | import org.youngmonkeys.chat.common.service.CommonService;
5 |
6 | import com.tvd12.ezyfox.bean.annotation.EzyAutoBind;
7 | import com.tvd12.ezyfox.bean.annotation.EzySingleton;
8 |
9 | @EzySingleton
10 | public class GreetingService {
11 |
12 | @EzyAutoBind
13 | private AppConfig appConfig;
14 |
15 | @EzyAutoBind
16 | private CommonService commonService;
17 |
18 | public String hello(String nickName) {
19 | return appConfig.getHelloPrefix() + " " + nickName + "!";
20 | }
21 |
22 | public String go(String nickName) {
23 | return appConfig.getGoPrefix() + " " + nickName + "!";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/game/game-app-api/src/main/java/org/youngmonkeys/game/app/service/GreetingService.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.game.app.service;
2 |
3 | import org.youngmonkeys.game.app.config.AppConfig;
4 | import org.youngmonkeys.game.common.service.CommonService;
5 |
6 | import com.tvd12.ezyfox.bean.annotation.EzyAutoBind;
7 | import com.tvd12.ezyfox.bean.annotation.EzySingleton;
8 |
9 | @EzySingleton
10 | public class GreetingService {
11 |
12 | @EzyAutoBind
13 | private AppConfig appConfig;
14 |
15 | @EzyAutoBind
16 | private CommonService commonService;
17 |
18 | public String hello(String nickName) {
19 | return appConfig.getHelloPrefix() + " " + nickName + "!";
20 | }
21 |
22 | public String go(String nickName) {
23 | return appConfig.getGoPrefix() + " " + nickName + "!";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/chat/chat-app-entry/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/game/game-app-entry/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/refactoring-spring-boot/src/main/java/org/youngmonkeys/refactoring/v2/advice/GlobalExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.refactoring.v2.advice;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.web.bind.annotation.ControllerAdvice;
7 | import org.springframework.web.bind.annotation.ExceptionHandler;
8 |
9 | @ControllerAdvice
10 | public class GlobalExceptionHandler {
11 |
12 | private final Logger logger =
13 | LoggerFactory.getLogger(GlobalExceptionHandler.class);
14 |
15 | @ExceptionHandler(Exception.class)
16 | public ResponseEntity handle(Exception e) {
17 | logger.info("internal server error", e);
18 | return ResponseEntity
19 | .internalServerError()
20 | .body(e.getMessage());
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/dont-forget-security/src/main/java/org/youngmonkeys/dfs/clickjacking/controller/ClickjackingController.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.dfs.clickjacking.controller;
2 |
3 | import com.tvd12.ezyfox.util.EzyLoggable;
4 | import com.tvd12.ezyhttp.server.core.annotation.Controller;
5 | import com.tvd12.ezyhttp.server.core.annotation.DoPost;
6 | import com.tvd12.ezyhttp.server.core.annotation.RequestParam;
7 | import com.tvd12.ezyhttp.server.core.view.Redirect;
8 |
9 | @Controller
10 | public class ClickjackingController extends EzyLoggable {
11 |
12 | @DoPost("/clickjacking/transfer")
13 | public Redirect csrfTransferPost(
14 | @RequestParam("value") String value,
15 | @RequestParam("to") String to
16 | ) {
17 | logger.info("clickjacking: user has just transfer: {} to: {}", value, to);
18 | return Redirect.to("/clickjacking.html");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/copilot-example/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.youngmonkeys
8 | programming-principles
9 | 1.0.0
10 |
11 |
12 | org.example
13 | copilot-example
14 |
15 |
16 |
17 | com.tvd12
18 | ezyhttp-server-boot
19 | ${ezy.http.version}
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/write-dry-code/src/main/java/org/youngmonkeys/wdc/duplicated_method/v1/service/PageService.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.wdc.duplicated_method.v1.service;
2 |
3 | import org.youngmonkeys.wdc.duplicated_method.v1.converter.PageModelToEntityConverter;
4 | import org.youngmonkeys.wdc.duplicated_method.v1.model.AddPageModel;
5 | import org.youngmonkeys.wdc.duplicated_method.v1.repository.PageRepository;
6 |
7 | import com.tvd12.ezyhttp.server.core.annotation.Service;
8 |
9 | import lombok.AllArgsConstructor;
10 |
11 | @Service
12 | @AllArgsConstructor
13 | public class PageService {
14 |
15 | private final PageRepository pageRepository;
16 | private final PageModelToEntityConverter pageModelToEntityConverter;
17 |
18 | public void addPage(AddPageModel model) {
19 | pageRepository.save(
20 | pageModelToEntityConverter.toEntity(model)
21 | );
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/write-dry-code/src/main/java/org/youngmonkeys/wdc/duplicated_method/v2/service/AbstractPostService.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.wdc.duplicated_method.v2.service;
2 |
3 | import org.youngmonkeys.wdc.duplicated_method.v1.model.AddPostModel;
4 | import org.youngmonkeys.wdc.duplicated_method.v1.repository.PostRepository;
5 | import org.youngmonkeys.wdc.duplicated_method.v2.converter.ModelToEntityConverter;
6 |
7 | import com.tvd12.ezyhttp.server.core.annotation.Service;
8 |
9 | import lombok.AllArgsConstructor;
10 |
11 | @Service
12 | @AllArgsConstructor
13 | public class AbstractPostService {
14 |
15 | private final PostRepository postRepository;
16 | private final ModelToEntityConverter modelToEntityConverter;
17 |
18 | public void addPost(AddPostModel model) {
19 | postRepository.save(
20 | modelToEntityConverter.toEntity(model)
21 | );
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/dont-forget-security/src/main/resources/templates/xss.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | XSS
8 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/document-your-code/src/main/java/org/youngmonkeys/dyc/repo/PaginationRepository.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.dyc.repo;
2 |
3 | import com.tvd12.ezyfox.reflect.EzyGenerics;
4 |
5 | /**
6 | * For pagination business.
7 | *
8 | * @param the filter value type
9 | * @param the pagination value type (inclusive or exclusive value type)
10 | * @param the id type
11 | * @param the entity type
12 | */
13 | public class PaginationRepository
14 | extends PaginationResultRepository {
15 |
16 | @Override
17 | protected Class getResultType() {
18 | return getEntityType();
19 | }
20 |
21 | @SuppressWarnings("unchecked")
22 | @Override
23 | protected Class getEntityType() {
24 | return EzyGenerics.getGenericClassArguments(
25 | getClass().getGenericSuperclass(),
26 | 4
27 | )[3];
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/refactoring-spring-web-mvc/src/main/webapp/WEB-INF/dispatcher-servlet.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/chat/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/game/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/separation-of-concerns-ezyfox-server/chat/chat-app-api/src/main/java/org/youngmonkeys/chat/app/controller/ServerReadyController.java:
--------------------------------------------------------------------------------
1 | package org.youngmonkeys.chat.app.controller;
2 |
3 | import com.tvd12.ezyfox.bean.annotation.EzySingleton;
4 | import com.tvd12.ezyfox.core.annotation.EzyEventHandler;
5 | import com.tvd12.ezyfoxserver.context.EzyAppContext;
6 | import com.tvd12.ezyfoxserver.controller.EzyAbstractAppEventController;
7 | import com.tvd12.ezyfoxserver.event.EzyServerReadyEvent;
8 |
9 | import static com.tvd12.ezyfoxserver.constant.EzyEventNames.SERVER_READY;
10 |
11 | @EzySingleton
12 | @EzyEventHandler(SERVER_READY) // refer EzyEventType
13 | public class ServerReadyController
14 | extends EzyAbstractAppEventController {
15 |
16 | @Override
17 | public void handle(EzyAppContext ctx, EzyServerReadyEvent event) {
18 | logger.info("chat app: fire custom app ready");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------