Skip to content

Commit be5cc01

Browse files
authored
Merge pull request #31 from KamilAdd-Byte/develop
Develop
2 parents d0506af + f9321ed commit be5cc01

File tree

56 files changed

+1331
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1331
-192
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
# Gen Commiting Application
2+
# Commmit Craft API
3+
4+
<img src="src/main/resources/images/craft.jpg" alt="Craft" width="300"/>
35

46
## Requirements
57
- Java 17+
@@ -29,12 +31,12 @@
2931

3032
3. If you want to build the Docker image, use the following command:
3133
```bash
32-
docker build -t gen-commiting .
34+
docker build -t commmit-craft .
3335
```
3436

3537
4. Run the Docker container:
3638
```bash
37-
docker run -d -p 9000:9000 --name gen-commiting gen-commiting
39+
docker run -d -p 8090:8090 --name commmit-craft commmit-craft
3840
```
3941

4042
5. The application will be available at `http://localhost:8090`.
@@ -56,7 +58,7 @@ The `translate` module integrates with DeepL for machine translation. To use thi
5658

5759
## Configuration
5860

59-
You can specify different profiles for the application. For example, to use the `kam` profile:
61+
You can specify different profiles for the application. For example, to use the `dev` profile:
6062

6163
1. In `application.yml`:
6264
```properties

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ dependencies {
7070
annotationProcessor 'org.projectlombok:lombok'
7171
testImplementation 'org.springframework.boot:spring-boot-starter-test'
7272
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
73+
implementation 'org.modelmapper:modelmapper:3.2.2'
74+
implementation 'org.hibernate.validator:hibernate-validator:8.0.1.Final'
75+
implementation 'org.glassfish:jakarta.el:4.0.2'
76+
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
77+
testImplementation 'org.mockito:mockito-core:4.5.1'
78+
testImplementation 'org.mockito:mockito-junit-jupiter:4.5.1'
7379
}
7480

7581
dependencyManagement {

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
rootProject.name = 'gen'
1+
rootProject.name = 'commit-craft'
22
include 'translate'
33

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package pl.commit.craft;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication(scanBasePackages = {"pl.commit.craft"})
7+
public class CommitCraftApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(CommitCraftApplication.class, args);
11+
}
12+
13+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package pl.commit.craft.controller;
2+
3+
import org.springframework.web.bind.annotation.*;
4+
import pl.commit.craft.service.CommitTranslateService;
5+
6+
@RestController
7+
@RequestMapping("/api/v1/commit-translate")
8+
public class CommitTranslateController {
9+
10+
private final CommitTranslateService commitTranslateService;
11+
12+
public CommitTranslateController(CommitTranslateService commitTranslateService) {
13+
this.commitTranslateService = commitTranslateService;
14+
}
15+
16+
@PostMapping("/craft")
17+
public String generateCommit(@RequestBody CommitTranslateRequest commitTranslateRequest) {
18+
return commitTranslateService.generateTranslateCommit(
19+
commitTranslateRequest.major(),
20+
commitTranslateRequest.type(),
21+
commitTranslateRequest.component(),
22+
commitTranslateRequest.changeDescription(),
23+
commitTranslateRequest.details(),
24+
commitTranslateRequest.wholeGitCommand(),
25+
commitTranslateRequest.language()
26+
);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package pl.commit.gen.controller;
1+
package pl.commit.craft.controller;
22

33
public record CommitTranslateRequest(
44
String major,
55
String type,
66
String component,
77
String changeDescription,
88
String details,
9-
boolean wholeGitCommand
9+
boolean wholeGitCommand,
10+
String language
1011
) {}

src/main/java/pl/commit/gen/error/ErrorResponseCommiting.java renamed to src/main/java/pl/commit/craft/error/ErrorResponseCommiting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pl.commit.gen.error;
1+
package pl.commit.craft.error;
22

33
import lombok.Getter;
44
import lombok.Setter;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package pl.commit.craft.error;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.http.converter.HttpMessageNotReadableException;
6+
import org.springframework.web.ErrorResponse;
7+
import org.springframework.web.bind.annotation.ControllerAdvice;
8+
import org.springframework.web.bind.annotation.ExceptionHandler;
9+
import org.springframework.web.context.request.WebRequest;
10+
import java.time.LocalDateTime;
11+
import java.util.LinkedHashMap;
12+
import java.util.Map;
13+
14+
@ControllerAdvice
15+
public class RestExceptionHandler {
16+
17+
@ExceptionHandler(IllegalArgumentException.class)
18+
public ResponseEntity<ErrorResponse> handleIllegalArgumentException(IllegalArgumentException ex, WebRequest request) {
19+
ErrorResponseCommiting errorResponseCommiting = new ErrorResponseCommiting("INVALID_ARGUMENT", ex.getMessage());
20+
return new ResponseEntity<>(errorResponseCommiting, HttpStatus.BAD_REQUEST);
21+
}
22+
23+
@ExceptionHandler(HttpMessageNotReadableException.class)
24+
public ResponseEntity<Object> handleHttpMessageNotReadableException(HttpMessageNotReadableException ex) {
25+
Map<String, Object> body = new LinkedHashMap<>();
26+
body.put("timestamp", LocalDateTime.now());
27+
body.put("status", HttpStatus.BAD_REQUEST.value());
28+
body.put("error", "Invalid JSON request");
29+
body.put("message", ex.getLocalizedMessage());
30+
body.put("path", "");
31+
32+
return new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
33+
}
34+
35+
@ExceptionHandler(Exception.class)
36+
public ResponseEntity<Object> handleGeneralException(Exception ex) {
37+
Map<String, Object> body = new LinkedHashMap<>();
38+
body.put("timestamp", LocalDateTime.now());
39+
body.put("status", HttpStatus.INTERNAL_SERVER_ERROR.value());
40+
body.put("error", "Internal Server Error");
41+
body.put("message", ex.getLocalizedMessage());
42+
body.put("path", "");
43+
44+
return new ResponseEntity<>(body, HttpStatus.INTERNAL_SERVER_ERROR);
45+
}
46+
}
47+

src/main/java/pl/commit/gen/flow/CommitFlowController.java renamed to src/main/java/pl/commit/craft/flow/CommitFlowController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
package pl.commit.gen.flow;
1+
package pl.commit.craft.flow;
22

33
import org.springframework.web.bind.annotation.PostMapping;
44
import org.springframework.web.bind.annotation.RequestBody;
55
import org.springframework.web.bind.annotation.RequestMapping;
66
import org.springframework.web.bind.annotation.RestController;
7-
import pl.commit.gen.service.CommitService;
7+
import pl.commit.craft.service.CommitTranslateService;
88

99
@RestController
10-
@RequestMapping("/api/commit-flow")
10+
@RequestMapping("/api/v1/commit-flow")
1111
public class CommitFlowController {
1212

13-
private final CommitService commitService;
13+
private final CommitTranslateService commitTranslateService;
1414

15-
public CommitFlowController(CommitService commitService) {
16-
this.commitService = commitService;
15+
public CommitFlowController(CommitTranslateService commitTranslateService) {
16+
this.commitTranslateService = commitTranslateService;
1717
}
1818

19-
@PostMapping("/generate")
19+
@PostMapping("/craft")
2020
public String generateCommit(@RequestBody CommitFlowRequest commitFlowRequest) {
21-
return commitService.generateFlowCommit(
21+
return commitTranslateService.generateFlowCommit(
2222
commitFlowRequest.major(),
2323
commitFlowRequest.type(),
2424
commitFlowRequest.component(),

src/main/java/pl/commit/gen/flow/CommitFlowRequest.java renamed to src/main/java/pl/commit/craft/flow/CommitFlowRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pl.commit.gen.flow;
1+
package pl.commit.craft.flow;
22

33
record CommitFlowRequest(
44
String major,

0 commit comments

Comments
 (0)