diff --git a/pom.xml b/pom.xml
index c99e20d..966e0dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
com.wiemanboy
WiemanApi
- 1.0.1
+ 1.1.0
WiemanApi
WiemanApi
diff --git a/src/main/java/com/wiemanboy/wiemanapi/application/ProfileService.java b/src/main/java/com/wiemanboy/wiemanapi/application/ProfileService.java
index 847c621..127c794 100644
--- a/src/main/java/com/wiemanboy/wiemanapi/application/ProfileService.java
+++ b/src/main/java/com/wiemanboy/wiemanapi/application/ProfileService.java
@@ -55,7 +55,7 @@ public Profile createProfile(String firstName, String lastName, String username,
.map(
skillDto -> Skill.builder()
.name(skillDto.name())
- .level(skillDto.level())
+ .level(SkillLevel.of(skillDto.level()))
.build()
).toList()
).build(
@@ -107,7 +107,7 @@ public Profile updateProfile(String id, String firstName, String lastName, Strin
.map(
skillDto -> Skill.builder()
.name(skillDto.name())
- .level(skillDto.level())
+ .level(SkillLevel.of(skillDto.level()))
.build()
).toList()
).build(
diff --git a/src/main/java/com/wiemanboy/wiemanapi/domain/Skill.java b/src/main/java/com/wiemanboy/wiemanapi/domain/Skill.java
index eb66c73..92dac88 100644
--- a/src/main/java/com/wiemanboy/wiemanapi/domain/Skill.java
+++ b/src/main/java/com/wiemanboy/wiemanapi/domain/Skill.java
@@ -9,10 +9,11 @@
@Builder
public class Skill {
private String name;
- private String level;
+ private SkillLevel level;
- public Skill(String name, String level) {
+ public Skill(String name, SkillLevel level) {
this.name = name;
this.level = level;
}
+
}
diff --git a/src/main/java/com/wiemanboy/wiemanapi/domain/SkillLevel.java b/src/main/java/com/wiemanboy/wiemanapi/domain/SkillLevel.java
new file mode 100644
index 0000000..670c4c8
--- /dev/null
+++ b/src/main/java/com/wiemanboy/wiemanapi/domain/SkillLevel.java
@@ -0,0 +1,20 @@
+package com.wiemanboy.wiemanapi.domain;
+
+import com.wiemanboy.wiemanapi.domain.exceptions.InvalidSkillLevelException;
+import lombok.Value;
+
+@Value
+public class SkillLevel {
+ int value;
+
+ private SkillLevel(int value) {
+ this.value = value;
+ }
+
+ public static SkillLevel of(int value) {
+ if (value < 0 || value > 5) {
+ throw new InvalidSkillLevelException(0, 5);
+ }
+ return new SkillLevel(value);
+ }
+}
diff --git a/src/main/java/com/wiemanboy/wiemanapi/domain/exceptions/InvalidSkillLevelException.java b/src/main/java/com/wiemanboy/wiemanapi/domain/exceptions/InvalidSkillLevelException.java
new file mode 100644
index 0000000..99d155a
--- /dev/null
+++ b/src/main/java/com/wiemanboy/wiemanapi/domain/exceptions/InvalidSkillLevelException.java
@@ -0,0 +1,18 @@
+package com.wiemanboy.wiemanapi.domain.exceptions;
+
+import lombok.Getter;
+
+import static java.lang.String.format;
+
+@Getter
+public class InvalidSkillLevelException extends RuntimeException {
+
+ private final int min;
+ private final int max;
+
+ public InvalidSkillLevelException(int min, int max) {
+ super(format("Level must be between %d and %d", min, max));
+ this.min = min;
+ this.max = max;
+ }
+}
diff --git a/src/main/java/com/wiemanboy/wiemanapi/presentation/dto/response/SkillDto.java b/src/main/java/com/wiemanboy/wiemanapi/presentation/dto/response/SkillDto.java
index 85aa789..46161c1 100644
--- a/src/main/java/com/wiemanboy/wiemanapi/presentation/dto/response/SkillDto.java
+++ b/src/main/java/com/wiemanboy/wiemanapi/presentation/dto/response/SkillDto.java
@@ -6,10 +6,10 @@
public record SkillDto(
String name,
- String level
+ int level
) {
public static SkillDto from(Skill skill) {
- return new SkillDto(skill.getName(), skill.getName());
+ return new SkillDto(skill.getName(), skill.getLevel().getValue());
}
public static List from(List skills) {
diff --git a/src/test/java/com/wiemanboy/wiemanapi/builders/SkillBuilder.java b/src/test/java/com/wiemanboy/wiemanapi/builders/SkillBuilder.java
index 00b5141..57d6e5a 100644
--- a/src/test/java/com/wiemanboy/wiemanapi/builders/SkillBuilder.java
+++ b/src/test/java/com/wiemanboy/wiemanapi/builders/SkillBuilder.java
@@ -1,6 +1,7 @@
package com.wiemanboy.wiemanapi.builders;
import com.wiemanboy.wiemanapi.domain.Skill;
+import com.wiemanboy.wiemanapi.domain.SkillLevel;
import lombok.Setter;
import lombok.experimental.Accessors;
@@ -8,9 +9,9 @@
@Accessors(chain = true)
public class SkillBuilder {
private String name = "Skill";
- private String description = "Description";
+ private int level = 5;
public Skill build() {
- return new Skill(name, description);
+ return new Skill(name, SkillLevel.of(level));
}
}
diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties
index e16eb8e..f1d1279 100644
--- a/src/test/resources/application.properties
+++ b/src/test/resources/application.properties
@@ -1,2 +1,9 @@
debug=true
-spring.main.allow-bean-definition-overriding=true
\ No newline at end of file
+spring.main.allow-bean-definition-overriding=true
+spring.data.mongodb.host=${MONGO_HOST:localhost}
+spring.data.mongodb.port=${MONGO_PORT:27017}
+spring.data.mongodb.database=${MONGO_DB:dev_db}
+spring.data.mongodb.username=${MONGO_USER:admin}
+spring.data.mongodb.password=${MONGO_PASS:admin}
+spring.data.mongodb.authentication-database=${MONGO_AUTH_DB:admin}
+spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
\ No newline at end of file