Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ build/
logs/

.nfs*


4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
Expand Down 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,56 @@
package com.educare.unitylend.controller;

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.model.Community;
import com.educare.unitylend.service.CommunityService;
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("/community")

public class CommunityController extends BaseController {
CommunityService communityService;

@GetMapping("all-communities")
public List<Community> getAllCommunities() throws ControllerException {

try {
List<Community> communityList = communityService.getCommunities();
return communityList;
} catch (Exception e) {
log.error("Error encountered in getting the users");
throw new ControllerException("Error encountered in getting the users", e);
}
}
@GetMapping("get-community-by-tag")
public String getCommunityWithTag(@RequestParam String commonTag) throws ControllerException {
try {
String communityName = communityService.getCommunityName(commonTag);
return communityName;
} catch (Exception e) {
log.error("Error encountered in getting the community by tag");
throw new ControllerException("Error encountered in getting the community by tag", e);
}
}


@PostMapping("/create-community")
public ResponseEntity<String> createNewCommunity(@RequestBody Community community) throws ControllerException {
try {
communityService.createCommunity(community);
return ResponseEntity.ok("success!!!");
} catch (Exception e) {
log.error("Error encountered in getting the users");
throw new ControllerException("Error encountered in getting the users", e);
}

}

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

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.model.User;
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 java.util.List;

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


// @GetMapping("all-users-community")
// public List<String> getAllUsers() throws ControllerException {
// try {
// List<String> userList = ;
// return userList;
// } catch (Exception e) {
// log.error("Error encountered in getting the users");
// throw new ControllerException("Error encountered in getting the users", e);
// }
// }


}
42 changes: 35 additions & 7 deletions src/main/java/com/educare/unitylend/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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.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.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -17,11 +15,9 @@
@RestController
@RequestMapping("/user")
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
*/
Expand All @@ -30,9 +26,41 @@ public List<User> getAllUsers() throws ControllerException {
try {
List<User> userList = userService.getUsers();
return userList;
} catch (ServiceException e) {
} catch (Exception e) {
log.error("Error encountered in getting the users");
throw new ControllerException("Error encountered in getting the users", e);
}
}

@PostMapping("/create-user")
public ResponseEntity<String> createUser(@RequestBody User user) throws ControllerException {
// Create the user
try {
userService.createUser(user);
return ResponseEntity.ok("succcesss!!!");
} catch (Exception e) {
log.error("Error encountered in getting the users");
throw new ControllerException("Error encountered in getting the users", e);
}

}

@PutMapping("/{userId}")
public ResponseEntity<String> updateUser(@PathVariable String userId, @RequestBody User updatedUser) throws ControllerException {
// Set the userId in the updatedUser object
updatedUser.setUserid(userId);

// Validate and update the user
try {
userService.updateUser(updatedUser);
} catch (Exception e) {
log.error("Error encountered in getting the users");
throw new ControllerException("Error encountered in getting the users", e);
}

return ResponseEntity.ok("User updated successfully");
}

}


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

import com.educare.unitylend.Exception.ControllerException;
import com.educare.unitylend.model.Wallet;
import com.educare.unitylend.service.WalletService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 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;

/**
* @return List of all the available {@link Wallet}
* @throws ControllerException : Exception to be thrown from controller in case of any exception
*/

@GetMapping("all-wallets")
public List<Wallet> getAllWallets() throws ControllerException {
try {
List<Wallet> walletList = walletService.getWallets();
return walletList;
} catch (Exception e) {
log.error("Error encountered in getting the users");
throw new ControllerException("Error encountered in getting the users", e);
}
}

@GetMapping("/get-user-info/{userId}")
public Wallet getWalletInfo(@PathVariable String userId) throws ControllerException{

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);
}
}

@GetMapping("get-wallet/{walletId}")
public Wallet getWalletById(@PathVariable String walletId) throws ControllerException {
try {
return walletService.getWalletById(walletId);
} catch (Exception e) {
log.error("Error in fetching desired wallet's details");
throw new ControllerException("Error encountered in getting the wallet info for the given walletId", e);
}
}

@PostMapping("/{walletId}/addAmount")
public ResponseEntity<String> addAmountToWallet(@PathVariable String walletId, @RequestParam Float amount) throws ControllerException{
try {
walletService.addAmountToWallet(walletId, amount);
return ResponseEntity.ok("Amount added successfully to wallet");
} catch (Exception e) {
log.error("Error adding requested amount to wallet");
throw new ControllerException("Error encountered while adding requested amount to wallet", e);
}
}

@PostMapping("/{walletId}/debitAmount")
public ResponseEntity<String> debitFromWallet(@PathVariable String walletId, @RequestParam Float amount) throws ControllerException{
try {
walletService.debitFromWallet(walletId, amount);
return ResponseEntity.ok("Amount debited successfully from wallet");
} catch (Exception e) {
log.error("Error debiting requested amount from wallet");
throw new ControllerException("Error encountered while debiting requested amount from wallet", e);
}
}
}
35 changes: 35 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,35 @@
package com.educare.unitylend.dao;

import com.educare.unitylend.model.Community;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@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("SELECT commontag FROM community WHERE commontag = #{commontag}")
String findByCommontag(String commontag);

@Select("SELECT communityid FROM community WHERE communityname = #{name}")
String getCommunityIdByName(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.educare.unitylend.dao;


import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserCommunityRepository {
@Insert("INSERT INTO usercommunity (userid, communityid) VALUES (#{userid}, #{communityid})")
void createUserCommunityMapping(@Param("userid") String userId, @Param("communityid") String communityId);


}
35 changes: 22 additions & 13 deletions src/main/java/com/educare/unitylend/dao/UserRepository.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.educare.unitylend.dao;

import com.educare.unitylend.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -13,22 +10,34 @@
@Repository
public interface UserRepository {

@Select(SELECT_USERS)
List<User> getAllUsers();

@SelectProvider(type = UserRepository.class, method = "getUserForUserIdQuery")
User getUserForUserId(@Param("userId") String userId);

static final String SELECT_USERS = "select user_id as userID, password, name from user_table";

static String getUserForUserIdQuery(String userId){
StringBuilder sqlQueryBuilder = new StringBuilder();

sqlQueryBuilder.append("select user_id as userID, password, name from user_table where 1=1 ");
sqlQueryBuilder.append("select userid as userID, password, name,email,dob,income,officename,collegeuniversity,locality from User where 1=1 ");
if(userId != null){
sqlQueryBuilder.append(" and userId = %s".formatted(userId));
}

return sqlQueryBuilder.toString();
}

@Select("select * from tempuser")
List<User> getAllUsers();

@SelectProvider(type = UserRepository.class, method = "getUserForUserIdQuery")
User getUserForUserId(@Param("UserId") String userId);
// static final List<String> SELECT_USERS = "select password from User";

@Insert("INSERT INTO tempuser (userid, password, name,email,dob,income,officename,collegeuniversity,locality) VALUES (CAST(uuid_generate_v4() AS VARCHAR), #{password}, #{name}, #{email},#{dob},#{income},#{officename},#{collegeuniversity},#{locality})")
void createUser(User user);


@Select("SELECT userid FROM tempuser WHERE email = #{email}")
String settingID(@Param("email") String email);


@Update("UPDATE tempuser SET name = #{name}, email =#{email}, locality = #{locality}, officename = #{officename},collegeuniversity=#{collegeuniversity} income = #{income} WHERE userid = #{userid}")
void updateUser(User user);


}
Loading