-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added EmergencyContact entity and CRUD for it #41
Closed
Closed
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
aad7c2f
Added EmergencyCrud entity and CRUD for it
742b896
Added EmergencyCrud entity and CRUD for it
e2e1446
Comments for EmergencyContact and started unit tests
6c10112
Merge branch 'emergency-contacts' of github.com:alecstincu/next-door …
27ff8d6
More code review changes
503207d
Add support for groups
701100a
Add compose with the db
ec59160
Fix CORS
3bbfca9
Merge pull request #46 from georgebejan/develop
mihairinzis 79d9a05
Merge pull request #45 from mihairinzis/docker
georgebejan 81e1e5e
Merge pull request #42 from georgebejan/groups
mihairinzis 4f4a84b
Added EmergencyCrud entity and CRUD for it
b2d1184
Comments for EmergencyContact and started unit tests
822fc83
More code review changes
8b9987b
Refactored tests and used modelmapper
53a5da8
solved conflicts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
14 changes: 14 additions & 0 deletions
14
api/src/main/java/com/code4ro/nextdoor/core/dto/BaseEntityDto.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,14 @@ | ||
package com.code4ro.nextdoor.core.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
@Setter | ||
@Getter | ||
public class BaseEntityDto { | ||
private UUID id; | ||
private LocalDateTime creationDate; | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/com/code4ro/nextdoor/core/service/MapperService.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,13 @@ | ||
package com.code4ro.nextdoor.core.service; | ||
|
||
import org.springframework.data.domain.Page; | ||
|
||
import java.util.List; | ||
|
||
public interface MapperService { | ||
<T> T map(Object source, Class<T> targetType); | ||
|
||
<T> List<T> mapList(List<?> sourceList, Class<? extends T> targetClass); | ||
|
||
<T> Page<T> mapPage(Page<?> sourcePage, Class<? extends T> targetClass); | ||
} |
83 changes: 83 additions & 0 deletions
83
api/src/main/java/com/code4ro/nextdoor/core/service/impl/MapperServiceImpl.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,83 @@ | ||
package com.code4ro.nextdoor.core.service.impl; | ||
|
||
import com.code4ro.nextdoor.core.dto.BaseEntityDto; | ||
import com.code4ro.nextdoor.core.entity.BaseEntity; | ||
import com.code4ro.nextdoor.core.service.MapperService; | ||
import com.code4ro.nextdoor.emergency.contact.dto.EmergencyContactDto; | ||
import com.code4ro.nextdoor.emergency.contact.entity.EmergencyContact; | ||
import com.code4ro.nextdoor.group.dto.GroupDto; | ||
import com.code4ro.nextdoor.group.dto.GroupSecurityPolicyDto; | ||
import com.code4ro.nextdoor.group.entity.Group; | ||
import com.code4ro.nextdoor.group.entity.GroupSecurityPolicy; | ||
import org.modelmapper.AbstractConverter; | ||
import org.modelmapper.ModelMapper; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class MapperServiceImpl implements MapperService, ApplicationListener<ContextRefreshedEvent> { | ||
private final ModelMapper modelMapper; | ||
|
||
public MapperServiceImpl() { | ||
this.modelMapper = new ModelMapper(); | ||
|
||
addCustomMappings(); | ||
addCustomTypeMaps(); | ||
} | ||
|
||
private void addCustomMappings() { | ||
modelMapper.createTypeMap(BaseEntity.class, BaseEntityDto.class) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Toate astea pot fi mutate acolo unde se creeaza ModelMapper. |
||
.addMapping(BaseEntity::getId, BaseEntityDto::setId); | ||
modelMapper.createTypeMap(BaseEntityDto.class, BaseEntity.class) | ||
.addMapping(BaseEntityDto::getId, BaseEntity::setId); | ||
} | ||
|
||
private void addCustomTypeMaps() { | ||
modelMapper.createTypeMap(Group.class, GroupDto.class) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. si astea la fel |
||
.includeBase(BaseEntity.class, BaseEntityDto.class); | ||
|
||
modelMapper.createTypeMap(GroupSecurityPolicy.class, GroupSecurityPolicyDto.class); | ||
|
||
modelMapper.createTypeMap(EmergencyContact.class, EmergencyContactDto.class); | ||
modelMapper.createTypeMap(EmergencyContactDto.class, EmergencyContact.class); | ||
} | ||
|
||
@Override | ||
public <T> T map(final Object source, final Class<T> targetType) { | ||
return source != null ? modelMapper.map(source, targetType) : null; | ||
} | ||
|
||
@Override | ||
public <T> List<T> mapList(final List<?> sourceList, final Class<? extends T> targetClass) { | ||
if (sourceList == null) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return sourceList.stream() | ||
.map(listElement -> modelMapper.map(listElement, targetClass)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public <T> Page<T> mapPage(final Page<?> sourcePage, final Class<? extends T> targetClass) { | ||
if (sourcePage == null) { | ||
return Page.empty(); | ||
} | ||
|
||
return sourcePage.map(pageElement -> modelMapper.map(pageElement, targetClass)); | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(final ContextRefreshedEvent event) { | ||
final Collection<AbstractConverter> converters = | ||
event.getApplicationContext().getBeansOfType(AbstractConverter.class).values(); | ||
converters.forEach(modelMapper::addConverter); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
api/src/main/java/com/code4ro/nextdoor/group/controller/GroupController.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,47 @@ | ||
package com.code4ro.nextdoor.group.controller; | ||
|
||
import com.code4ro.nextdoor.group.dto.GroupCreateDto; | ||
import com.code4ro.nextdoor.group.dto.GroupDto; | ||
import com.code4ro.nextdoor.group.dto.GroupUpdateDto; | ||
import com.code4ro.nextdoor.group.service.GroupService; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.UUID; | ||
|
||
@Api("Group Controller") | ||
@RestController | ||
@RequestMapping("/api/groups") | ||
public class GroupController { | ||
private final GroupService groupService; | ||
|
||
@Autowired | ||
public GroupController(final GroupService groupService) { | ||
this.groupService = groupService; | ||
} | ||
|
||
@ApiOperation("Create group") | ||
@PostMapping | ||
public ResponseEntity<GroupDto> create(@RequestBody final GroupCreateDto createDto) { | ||
final GroupDto groupDto = groupService.create(createDto); | ||
return ResponseEntity.ok(groupDto); | ||
} | ||
|
||
@ApiOperation("Update group") | ||
@PutMapping("/{id}") | ||
public ResponseEntity<GroupDto> update(@PathVariable("id") final UUID id, | ||
@RequestBody final GroupUpdateDto updateDto) { | ||
final GroupDto groupDto = groupService.update(id, updateDto); | ||
return ResponseEntity.ok(groupDto); | ||
} | ||
|
||
@ApiOperation("Get group") | ||
@GetMapping("/{id}") | ||
public ResponseEntity<GroupDto> get(@PathVariable("id") final UUID id) { | ||
final GroupDto groupDto = groupService.get(id); | ||
return ResponseEntity.ok(groupDto); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/com/code4ro/nextdoor/group/dto/GroupCreateDto.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,13 @@ | ||
package com.code4ro.nextdoor.group.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class GroupCreateDto { | ||
private GroupSecurityPolicyDto securityPolicy; | ||
private String name; | ||
private String description; | ||
private Boolean open; | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/com/code4ro/nextdoor/group/dto/GroupDto.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,13 @@ | ||
package com.code4ro.nextdoor.group.dto; | ||
|
||
import com.code4ro.nextdoor.core.dto.BaseEntityDto; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class GroupDto extends BaseEntityDto { | ||
private String name; | ||
private String description; | ||
private Boolean open; | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/com/code4ro/nextdoor/group/dto/GroupSecurityPolicyDto.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,11 @@ | ||
package com.code4ro.nextdoor.group.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class GroupSecurityPolicyDto { | ||
private String question; | ||
private String answer; | ||
} |
12 changes: 12 additions & 0 deletions
12
api/src/main/java/com/code4ro/nextdoor/group/dto/GroupUpdateDto.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,12 @@ | ||
package com.code4ro.nextdoor.group.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class GroupUpdateDto { | ||
private String name; | ||
private String description; | ||
private Boolean open; | ||
} |
26 changes: 26 additions & 0 deletions
26
api/src/main/java/com/code4ro/nextdoor/group/entity/Group.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,26 @@ | ||
package com.code4ro.nextdoor.group.entity; | ||
|
||
|
||
import com.code4ro.nextdoor.core.entity.BaseEntity; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.Cascade; | ||
import org.hibernate.annotations.CascadeType; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.OneToOne; | ||
import javax.persistence.Table; | ||
|
||
@Table(name = "groups") | ||
@Entity | ||
@Getter | ||
@Setter | ||
public class Group extends BaseEntity { | ||
private String name; | ||
private String description; | ||
private Boolean open; | ||
@Cascade(CascadeType.ALL) | ||
@OneToOne(fetch = FetchType.LAZY) | ||
private GroupSecurityPolicy securityPolicy; | ||
} |
19 changes: 19 additions & 0 deletions
19
api/src/main/java/com/code4ro/nextdoor/group/entity/GroupSecurityPolicy.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.code4ro.nextdoor.group.entity; | ||
|
||
import com.code4ro.nextdoor.core.entity.BaseEntity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Entity; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@Entity | ||
public class GroupSecurityPolicy extends BaseEntity { | ||
private String question; | ||
private String answer; | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/java/com/code4ro/nextdoor/group/repository/GroupRepository.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,9 @@ | ||
package com.code4ro.nextdoor.group.repository; | ||
|
||
import com.code4ro.nextdoor.group.entity.Group; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface GroupRepository extends JpaRepository<Group, UUID> { | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Model mapper poate fi creat cu @bean in configuration si sa il dam ca si parametru cu @Inject