Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jmprathab/MyHome
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/jmprathab/MyHome:
  Resolved as per PR Comments
  delete community api
  • Loading branch information
jmprathab committed Jul 19, 2020
2 parents 502381c + e3e096d commit 316766f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/myhome/controllers/CommunityController.java
Expand Up @@ -205,5 +205,21 @@ public ResponseEntity<Void> deleteAdminFromCommunity(
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
}

@Operation(description = "Deletion community with given community id",
responses = {@ApiResponse(responseCode = "204", description = "If community was removed"),
@ApiResponse(responseCode = "404", description = "If parameters are invalid")})
@DeleteMapping(
path = "/communities/{communityId}"
)
public ResponseEntity<Void> deleteCommunity(@PathVariable String communityId) {
log.trace("Received delete community request");
Integer isDeleted = communityService.deleteCommunity(communityId);
if (isDeleted == 1) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
}
}

Expand Up @@ -19,9 +19,13 @@
import com.myhome.domain.Community;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface CommunityRepository extends CrudRepository<Community, Long> {

Community findByCommunityId(String communityId);

@Transactional
Integer deleteByCommunityId(String communityId);
}
2 changes: 2 additions & 0 deletions src/main/java/com/myhome/services/CommunityService.java
Expand Up @@ -33,5 +33,7 @@ public interface CommunityService {

Set<String> addHousesToCommunity(String communityId, Set<CommunityHouse> houses);

Integer deleteCommunity(String communityId);

Optional<Community> deleteAdminFromCommunity(String communityId, String adminId);
}
Expand Up @@ -116,6 +116,11 @@ public Optional<Community> deleteAdminFromCommunity(String communityId, String a
return Optional.of(savedCommunity);
}

@Override
public Integer deleteCommunity(String communityId) {
return communityRepository.deleteByCommunityId(communityId);
}

private String generateUniqueId() {
return UUID.randomUUID().toString();
}
Expand Down

0 comments on commit 316766f

Please sign in to comment.