-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create EndorsementController * add env to ignore * add DTO and DROs * de.env * create EndorsementListController * remove EndorsementListController * add EndorsementServiceTest.java * add JsonManagedReference * address some review comments * added validation checks * remove extra entries in EndorsementDRO.java * handle NoEntityException * add DB_NAME variable in application.properties * handle exceptions in one catch block * made ApiResponse class * handle NoEntityException exception globally * remove default false * merge the tests * delete usused files * fix build, add missing imports * fix EndorsementListServiceTest * fix testCreateEndorsement test * revert change * add integration test * update integration test * update integration test * revert integration test * fix integration test * use GenericResponse * fix return type * change endorsementModel to EndorsementDTO.toDto
- Loading branch information
1 parent
47f7d31
commit cfe9421
Showing
11 changed files
with
485 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementDRO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.RDS.skilltree.Endorsement; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.UUID; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Data | ||
@Builder | ||
public class EndorsementDRO { | ||
@NotNull(message = "user id cannot be null") | ||
private UUID userId; | ||
@NotNull(message = "skill id cannot be null") | ||
private UUID skillId; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListDRO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.RDS.skilltree.EndorsementList; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.UUID; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Data | ||
@Builder | ||
public class EndorsementListDRO { | ||
private String description; | ||
private UUID endorsementId; | ||
private UUID endorserId; | ||
private EndorsementType type; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.RDS.skilltree.EndorsementList; | ||
|
||
import com.RDS.skilltree.User.UserModel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.util.UUID; | ||
|
||
@Builder | ||
@Data | ||
@AllArgsConstructor | ||
public class EndorsementListDTO { | ||
private UUID id; | ||
private String description; | ||
private UserModel endorser; | ||
private EndorsementType type; | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.RDS.skilltree.EndorsementList; | ||
|
||
import com.RDS.skilltree.Endorsement.EndorsementModel; | ||
import com.RDS.skilltree.Endorsement.EndorsementRepository; | ||
import com.RDS.skilltree.Exceptions.NoEntityException; | ||
import com.RDS.skilltree.User.UserModel; | ||
import com.RDS.skilltree.User.UserRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Service | ||
public class EndorsementListService { | ||
@Autowired | ||
private final EndorsementListRepository endorsementListRepository; | ||
private final EndorsementRepository endorsementRepository; | ||
private final UserRepository userRepository; | ||
|
||
public EndorsementListService(EndorsementListRepository endorsementListRepository, EndorsementRepository endorsementRepository, UserRepository userRepository) { | ||
this.endorsementListRepository = endorsementListRepository; | ||
this.endorsementRepository = endorsementRepository; | ||
this.userRepository = userRepository; | ||
} | ||
|
||
|
||
public EndorsementListModel createEndorsementListEntry(EndorsementListDRO endorsementListDRO) { | ||
EndorsementListModel endorsementListEntry = new EndorsementListModel(); | ||
|
||
UUID endorserId = endorsementListDRO.getEndorserId(); | ||
UUID endorsementId = endorsementListDRO.getEndorsementId(); | ||
Optional<UserModel> endorserOptional = userRepository.findById(endorserId); | ||
Optional<EndorsementModel> endorsementOptional = endorsementRepository.findById(endorsementId); | ||
if (endorserOptional.isPresent() && endorsementOptional.isPresent()) { | ||
|
||
endorsementListEntry.setEndorser(endorserOptional.get()); | ||
endorsementListEntry.setEndorsement(endorsementOptional.get()); | ||
endorsementListEntry.setDescription(endorsementListDRO.getDescription()); | ||
endorsementListEntry.setType(endorsementListDRO.getType()); | ||
endorsementListRepository.save(endorsementListEntry); | ||
return endorsementListEntry; | ||
|
||
} else { | ||
if (endorserOptional.isEmpty()) | ||
throw new NoEntityException("User with id:" + endorserId + " not found"); | ||
throw new NoEntityException("Endorsement with id:" + endorsementId + " not found"); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ | |
@SpringBootTest | ||
class SkillTreeApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
} |
Oops, something went wrong.