Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
25f4d09
Move the DB schema under resources folder
Prathyusha5c0 Feb 25, 2024
08919bf
Resolved Issue 9, 10 & 12
Prathyusha5c0 Feb 26, 2024
86d1fcb
Resolved Issue 9, 10 & 12
Prathyusha5c0 Feb 26, 2024
07d5635
Resolved Issue 9, 10 & 12
Prathyusha5c0 Feb 27, 2024
72b2930
Resolved Issue 9, 10 & 12
Prathyusha5c0 Feb 27, 2024
7de0820
Resolved Issue 9, 10 & 12
Prathyusha5c0 Feb 27, 2024
d1a4494
Merge remote-tracking branch 'origin/prathyusha' into prathyusha
Prathyusha5c0 Feb 27, 2024
cb66107
Resolved Issue 9, 10 & 12
Prathyusha5c0 Feb 27, 2024
046509a
Resolved Issues 9, 10 & 12
Prathyusha5c0 Feb 27, 2024
656e2c5
Merge remote-tracking branch 'origin/prathyusha' into prathyusha
Prathyusha5c0 Feb 28, 2024
488cf2e
Merge remote-tracking branch 'origin/prathyusha' into prathyusha
Prathyusha5c0 Feb 28, 2024
53cb031
Merge pull request #18 from Prathyusha5c0/prathyusha
NehaKariya0309 Feb 28, 2024
89aaae9
Added api for generating wallet and getting details based on userid
NehaKariya0309 Feb 29, 2024
faf9a17
Get communities associated with a given userId
Prathyusha5c0 Mar 1, 2024
4f58065
Merge remote-tracking branch 'origin/prathyusha' into prathyusha
Prathyusha5c0 Mar 1, 2024
8930a4d
Merge pull request #24 from Prathyusha5c0/prathyusha
Prathyusha5c0 Mar 1, 2024
2dc23fd
Modify and optimize the code
Prathyusha5c0 Mar 4, 2024
4b07353
Update the user details feature
Prathyusha5c0 Mar 7, 2024
95e3e90
Merge pull request #35 from Prathyusha5c0/prathyusha
Prathyusha5c0 Mar 7, 2024
fb5c035
Update the user details feature
Prathyusha5c0 Mar 7, 2024
7ed7b3f
Merge pull request #36 from Prathyusha5c0/prathyusha
Prathyusha5c0 Mar 7, 2024
50684e6
Added comments for APIs
NehaKariya0309 Mar 7, 2024
ba45179
Merge pull request #37 from NehaKariya0309/neha-community-feature
NehaKariya0309 Mar 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- Changed the scope to provided to use the dependency at runtime for tomcat (external)-->
<scope>provided</scope>

</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class UnitylendApplication {

public static void main(String[] args) {

SpringApplication.run(UnitylendApplication.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.educare.unitylend.controller;

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.model.Community;
import com.educare.unitylend.service.CommunityService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/community")

public class CommunityController extends BaseController {
CommunityService communityService;

@GetMapping("all-communities")
public ResponseEntity<?> getAllCommunities() throws ControllerException {
//Getting all the existing communities
try {
List<Community> communityList = communityService.getCommunities();

if (communityList == null || communityList.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found");
}

return ResponseEntity.ok(communityList);
} catch (ServiceException e) {
log.error("Error encountered in getting the communities", e);
throw new ControllerException("Error encountered in getting the communities", e);
}
}

@GetMapping("get-community-by-tag")
public ResponseEntity<?> getCommunityWithTag(@RequestParam(required = false) String commonTag) throws ControllerException {
//Getting all communities with the given common tag
try {
if (commonTag == null || commonTag.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("commonTag parameter is missing or empty");
}

String communityName = communityService.getCommunityName(commonTag);

if (communityName == null || communityName.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found");
}

return ResponseEntity.ok(communityName);
} catch (ServiceException e) {
log.error("Error encountered in getting the community by tag", e);
throw new ControllerException("Error encountered in getting the community by tag", e);
}
}

@PostMapping("/create-community")
public ResponseEntity<String> createNewCommunity(@RequestBody Community community) throws ControllerException {
//Creating a new community with community object
try {
if (community == null) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Request body is null");
}

communityService.createCommunity(community);
return ResponseEntity.ok("success!!!");
} catch (ServiceException e) {
log.error("Error encountered in creating the community", e);
throw new ControllerException("Error encountered in creating the community", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.educare.unitylend.controller;

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.service.UserCommunityService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/usercommunity")
public class UserCommunityController {

private UserCommunityService usercommunityService;

@GetMapping("/{userId}")
public ResponseEntity<List<String>> getAllCommunities(@PathVariable String userId) throws ControllerException {
//Getting all communities for a given user
try {
if (userId == null || userId.isEmpty()) {
return ResponseEntity.badRequest().body(List.of("User ID cannot be null or empty"));
}

List<String> communityList = usercommunityService.getCommunitiesByUserId(userId);

if (communityList == null || communityList.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(communityList);
} catch (Exception e) {
log.error("Error encountered in getting the communities for user with ID: {}", userId, e);
throw new ControllerException("Error encountered in getting the communities", e);
}
}
}
108 changes: 95 additions & 13 deletions src/main/java/com/educare/unitylend/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,119 @@

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.dao.UserCommunityRepository;
import com.educare.unitylend.dao.UserRepository;
import com.educare.unitylend.model.User;
import com.educare.unitylend.service.UserCommunityService;
import com.educare.unitylend.service.UserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
public class UserController extends BaseController{

UserService userService;

/**
*
* @return List of all the available {@link User}
* @throws ControllerException : Exception to be thrown from controller in case of any exception
*/
private UserCommunityService usercommunityService;
private UserRepository userRepository;
private UserCommunityRepository userCommunityRepository;
@GetMapping("all-users")
public List<User> getAllUsers() throws ControllerException {
public ResponseEntity<?> getAllUsers() throws ControllerException {
//Getting all the users
try {
List<User> userList = userService.getUsers();
return userList;
if (userList.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found");
}
return ResponseEntity.ok(userList);
} catch (ServiceException e) {
log.error("Error encountered in getting the users");
log.error("Error encountered in getting the users", e);
throw new ControllerException("Error encountered in getting the users", e);
}
}
@PostMapping("/create-user")
public ResponseEntity<String> createUser(@RequestBody User user) throws ControllerException {
//Creating a new user with the user object
try {
userService.createUser(user);
return ResponseEntity.ok("success!!!");
} catch (ServiceException e) {
log.error("Error encountered in creating the user", e);
throw new ControllerException("Error encountered in creating the user", e);
}
}

@PutMapping("/{userId}")
public ResponseEntity<String> updateUser(@PathVariable String userId, @RequestBody User updatedUser) throws ControllerException {
//List<String> prevCommunities;

//Updating the user

try {
if (userId == null || userId.isEmpty() || updatedUser == null) {
return ResponseEntity.badRequest().body("User ID and updated user cannot be null or empty");
}
updatedUser.setUserid(userId);
// System.out.println(updatedUser);
userService.updateUser(updatedUser, userId);
return ResponseEntity.ok("User updated successfully");
}
catch (ServiceException e) {
log.error("Error encountered in updating the user", e);
throw new ControllerException("Error encountered in updating the user", e);
} catch (Exception e) {
log.error("Error encountered in getting the communities for user with ID: {}", userId, e);
throw new ControllerException("Error encountered in getting the communities", e);
}
}
@GetMapping("/{userId}/get-info")
public ResponseEntity<User> getUserByUserId(@PathVariable String userId) throws ControllerException {
//Getting user information for a given user by its userId
try {
if (userId == null || userId.isEmpty()) {
return ResponseEntity.badRequest().build();
}

User user = userService.getUserByUserId(userId);

if (user != null) {
return ResponseEntity.ok(user);
} else {
return ResponseEntity.notFound().build();
}
} catch (ServiceException e) {
log.error("Error encountered in getting user information by ID: {}", userId, e);
throw new ControllerException("Error encountered in getting user information", e);
}
}

@PutMapping("/{userId}/inactive")
public ResponseEntity<String> deactivateUser(@PathVariable String userId) throws ControllerException{
//Deactivating the user
try {
if (userId == null || userId.isEmpty()) {
return ResponseEntity.badRequest().body("User ID cannot be null or empty");
}

boolean updated = userService.markUserAsInactive(userId);

if (updated) {
return ResponseEntity.ok("User marked as inactive successfully");
} else {
return ResponseEntity.notFound().build();
}
} catch (ServiceException e) {
log.error("Error encountered in deactivating user with ID: {}", userId, e);
throw new ControllerException("Error encountered in deactivating user", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.educare.unitylend.controller;

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.Exception.ServiceException;
import com.educare.unitylend.model.User;
import com.educare.unitylend.model.Wallet;
import com.educare.unitylend.service.UserService;
import com.educare.unitylend.service.WalletService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/wallet")
public class WalletController extends BaseController {

WalletService walletService;

@GetMapping("/get-user-info/{userId}")

public Wallet getWalletInfo(@PathVariable String userId) throws ControllerException{
//Getting wallet information
try {
return walletService.getWalletInfo(userId);
} catch (Exception e) {
log.error("Error encountered in getting the wallet info for the given user");
throw new ControllerException("Error encountered in getting the wallet info for the given user", e);
}
}

@PostMapping("/generate-wallet")

public ResponseEntity<String> generateWallet(@RequestBody Wallet wallet) throws ControllerException {
// Generating the wallet
try {
walletService.generateWallet(wallet);
return ResponseEntity.ok("succcessfully created wallet!!!");
} catch (Exception e) {
log.error("Error encountered in generating the wallet");
throw new ControllerException("Error encountered in generating the wallet", e);
}

}





}


46 changes: 46 additions & 0 deletions src/main/java/com/educare/unitylend/dao/CommunityRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.educare.unitylend.dao;

import com.educare.unitylend.model.Community;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
@Repository

public interface CommunityRepository {
@Select("select * from community")
List<Community> getAllCommunities();

@Select("select communityname from community where commontag = #{commontag}")
String getCommunity(String commontag);

@Insert("INSERT INTO community (communityid, communityname, commontag) VALUES (uuid_generate_v4(), #{communityname}, #{commontag})")
void createCommunity(Community community);

@Insert("INSERT INTO community (communityid, communityname, commontag) VALUES (uuid_generate_v4(), #{name}, #{tag})")
void createCommunityUsingStrings(String name, String tag);

@Select("SELECT COUNT(*) > 0 FROM community WHERE commontag = #{commontag}")
boolean existsByCommontag(String commontag);


@Select({
"<script>",
"SELECT communityname, commontag FROM community",
"WHERE commontag IN ",
"<foreach item='name' collection='names' open='(' separator=',' close=')'>",
"#{name}",
"</foreach>",
"</script>"
})
@MapKey("commontag")
Map<String, String> findCommontagsByNames(@Param("names") List<String> names);


@Select("SELECT communityid FROM community WHERE communityname = #{name}")
String getCommunityIdByName(String name);
}
Loading