Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
099f5f7
removed redundant codes and rubbish comments
ebiggerr Jun 27, 2021
f5ab1e9
optimized imports by removing unnecessary imports of libraries.
ebiggerr Jun 27, 2021
4c1636c
changed the signature of the exception and refine the log message.
ebiggerr Jun 27, 2021
d0fdf1e
updated the license signature in every java files
ebiggerr Jun 27, 2021
56c0300
removed deprecated code
ebiggerr Jun 27, 2021
6cc24e2
add logger into the class
ebiggerr Jun 28, 2021
dec0f0c
handling the creation of JWT if the username is null
ebiggerr Jun 28, 2021
545bf6b
changed "return" to inline
ebiggerr Jun 28, 2021
c3fad43
removed unnecessary comments
ebiggerr Jun 28, 2021
2ad9ef1
removed unnecessary comments
ebiggerr Jun 28, 2021
18fdcf2
repetitive usage of 1, thus changed it to CONSTANT : DEFAULT_FIRST_PAGE
ebiggerr Jun 28, 2021
f2bc64f
removed the dependency on historicalSalesService ( unused, deprecated )
ebiggerr Jun 28, 2021
ec0daae
add the method of update an existing item in the inventory
ebiggerr Jun 28, 2021
cfc4b9e
updated the documentation of methods in the inventoryService.java
ebiggerr Jun 28, 2021
c663cf9
added the field of "id"
ebiggerr Jun 28, 2021
ed4ca6b
added an endpoint that allows user to update an existing item in the …
ebiggerr Jun 28, 2021
6155052
updated the antMatchers in WebSecurity_Config.java
ebiggerr Jun 28, 2021
65ba59e
optimized imports
ebiggerr Jun 28, 2021
6dbddbf
update the README.md with screenshots of Postman
ebiggerr Jun 28, 2021
2e72a68
update the README.md
ebiggerr Jun 28, 2021
350bcfe
update the README.md
ebiggerr Jun 28, 2021
bc738ae
Renamed all the classes and interfaces in Pascal Case style.
ebiggerr Jun 30, 2021
498d8c8
renamed the method generateTokenAuthentication to generateToken
ebiggerr Jun 30, 2021
d415eb8
add comments
ebiggerr Jun 30, 2021
e1eaf20
renamed the name of the methods in AccountMainController.java
ebiggerr Jun 30, 2021
867eba2
-renamed the methods name in RestockController.java
ebiggerr Jun 30, 2021
3fa3551
update template for application.properties
ebiggerr Jun 30, 2021
e80b905
renamed the name of methods for better description
ebiggerr Jun 30, 2021
6bdcb73
PostgreSQL enum type
ebiggerr Jun 30, 2021
7b9f262
changed the name of method
ebiggerr Jun 30, 2021
f99c785
Merge branch 'prod' into enchance-refractor-clean-up
ebiggerr Jun 30, 2021
768c47b
Fix : Comment out the @Transactional will cause the update query to f…
ebiggerr Jul 18, 2021
70f93a1
Merge branch 'prod' into enchance-refractor-clean-up
ebiggerr Jul 18, 2021
3fbf474
Fix - removed test
ebiggerr Jul 18, 2021
a58fae7
Fix - comment out to prevent compile error/ expect to deprecate or re…
ebiggerr Jul 18, 2021
09ef535
Feature - Update database schema to support batch expiry tracking in …
ebiggerr Jul 20, 2021
d8bab6f
Feature : Improve the restock update by adding information on who per…
ebiggerr Jul 20, 2021
e32b15e
Feature - update database schema for expiry tracking
ebiggerr Jul 20, 2021
8508b22
Changes made to things related to the account controller
ebiggerr Aug 22, 2021
fb4d4f1
Enhance - Lazy to do meaningful commit
ebiggerr Aug 23, 2021
5979e00
Enhance - Lazy
ebiggerr Aug 23, 2021
6f67568
Enhance - Throwing and catching exception
ebiggerr Aug 23, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public class AccountMainController {

private final BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();

private boolean passwordMatch;

//constructor dependency injection
//@Autowired
public AccountMainController(AuthenticationManager authenticationManager, Token_Provider tokenProvider, AccountService accountService, AccountAuthenticationService accountAuthenticationService) {
Expand Down Expand Up @@ -143,15 +141,15 @@ public API_Response registerAccount(@RequestBody AuthenticationRequest credentia
String message="Something Went Wrong";

if ( InputCheckValid.checkEmail( credentials.getUsername()) ) {
if ( accountService.registerAccount( credentials.getUsername(), encodedPasswordFromRegisterRequest ) ) return new API_Response().Success();
if ( accountService.registerAccount( credentials.getUsername(), encodedPasswordFromRegisterRequest ) ) return new API_Response().Success(); //successful registration
else{
message = "Duplicates";
}
}
else{ return new API_Response().Failed("Invalid Email Address");
else{ return new API_Response().Failed("Invalid Email Address"); //If the email address does not pass the regex validation
}

return new API_Response().Failed(message);
return new API_Response().Failed(message); //Meaningless message. ikr...
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.ebiggerr.sims.domain.response.API_Response;
import com.ebiggerr.sims.domain.response.DemandResult;
import com.ebiggerr.sims.domain.stock.Stock;
import com.ebiggerr.sims.exception.CustomException;
import com.ebiggerr.sims.service.DemandService;
import com.ebiggerr.sims.service.input.InputCheckValid;
import com.ebiggerr.sims.service.inventory.InventoryService;
Expand Down Expand Up @@ -84,7 +85,7 @@ public API_Response getAllFromInventory(@RequestParam(name ="pagenumber")int pag
*/
@PreAuthorize("hasAnyAuthority('Admin','Manager','Staff')")
@GetMapping(path="/inventory/all/categorical")
public API_Response getFromInventoryByCategory(@RequestParam(name ="pagenumber")int pageNumber, @RequestParam( name="pagesize")int pageSize, @RequestParam(name = "category", required = false) String categoryName, @RequestParam(name="categoryid") String categoryID){
public API_Response getFromInventoryByCategory(@RequestParam(name ="pagenumber")int pageNumber, @RequestParam( name="pagesize")int pageSize, @RequestParam(name = "category", required = false) String categoryName, @RequestParam(name="categoryid") String categoryID) throws CustomException {

return new API_Response().Success(
inventoryService.getItemsByCategoryWithPageAndSize(pageNumber, pageSize, categoryName, categoryID)
Expand Down Expand Up @@ -177,14 +178,19 @@ public API_Response updateAnItem( @Valid @ModelAttribute(value = "itemWithImageR

@PreAuthorize("hasAnyAuthority('Admin','Manager')")
@PostMapping(path ="/inventory/itemWithImage")
public API_Response addNewItemWithImage( @Valid @ModelAttribute(value = "itemWithImageRequest") ItemWithImageRequest item) throws IOException {
public API_Response addNewItemWithImage( @Valid @ModelAttribute(value = "itemWithImageRequest") ItemWithImageRequest item) {

message = InputCheckValid.checkAllForItem(item);

Item response = null;
if( message == null ){
response = inventoryService.addNewItemImage(item);
if( response == null ) return new API_Response().Failed("Duplicates in SKU");

try {
response = inventoryService.addNewItemImage(item);
if (response == null) return new API_Response().Failed("Duplicates in SKU");
}catch (Exception exception){
return new API_Response().Failed(exception.getMessage());
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ public AccountAuthenticationDTO entityToDTO(AccountAuthentication acc){
*/
public List<AccountAuthenticationDTO> entitiesToDTO(List<AccountAuthentication> accList ){

List<AccountAuthenticationDTO> list=new LinkedList<>();
//@Deprecated
/*List<AccountAuthenticationDTO> list=new LinkedList<>();

for( int index=0; index< accList.size(); index++){
list.add( this.entityToDTO( accList.get(index) ) );
}
}*/

return accList.stream().map(this::entityToDTO).collect(Collectors.toList());

Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/ebiggerr/sims/repository/CategoryRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ public interface CategoryRepo extends JpaRepository<Category,Long> {
@Query(value="select listing.categoryid,category.categoryname, count(listing.categoryid) as value from itemlisting listing join itemcategory category ON listing.categoryid = category.categoryid group by listing.categoryid, category.categoryname order by listing.categoryid asc" ,nativeQuery=true)
List<Category> getCategoricalAnalytics();

@Query(value="select category.categoryname, count(listing.categoryid) as value from itemlisting listing join itemcategory category ON listing.categoryid = category.categoryid group by listing.categoryid, category.categoryname order by listing.categoryid asc" ,nativeQuery=true)
List<Category> getCategoricalAnalyticsA();

@Query(value="SELECT categoryid FROM itemcategory WHERE categoryname=?1 ", nativeQuery=true)
int getCategoryIdByName(String categoryName);

@Query(value="SELECT categoryid FROM itemcategory WHERE categoryname=?1 ", nativeQuery=true)
Optional<Integer> getCategoryIdByNameOptional(String categoryName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Repository
Expand All @@ -39,4 +40,10 @@ public interface RestockHistoryRepo extends JpaRepository<RestockHistory,Long> {
@Query(value=" INSERT INTO restockhistory (itemid,quantity,restocktime) VALUES (?1,?2,?3)", nativeQuery=true)
void addNewHistory(Long itemid, int quantity, LocalDateTime restockTime);

@Modifying
@Transactional
@Query(value="INSERT INTO restockhistory (itemid,quantity,restocktime,accountid) VALUES( ?1,?2,?3, (SELECT accountauthentication.accountid FROM accountauthentication WHERE accountusername=?4 ) );", nativeQuery=true)
void addNewRestockHistoryWithAccountId(Long itemid, int quantity, LocalDateTime restockTimestamp, String accountUsername);
//TODO not yet do the unit testing for this query

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@

public interface TotalAssetsRepo extends JpaRepository<TotalAssets,String> {


/**
* Planning update - adding more fields as the filters in the query
*
* @return the total amount of all active assets in the inventory
*/
@Query(value="SELECT SUM( stock.quantitycount * listing.itemunitprice ) AS totalassets FROM itemlisting listing join inventorystock stock on listing.itemid = stock.itemid",nativeQuery=true)
String gettotalassets();
String GetTheTotalAmountOfAllActiveAssetsInTheInventory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ public boolean registerAccount(String username,String password){
// extract abc as the username of the account
username = username.split("@")[0];

String latestId=accountRepo.getMaxId();
String newId= IdService.idIncrement(latestId);
String latestId=accountRepo.getMaxId(); //Not a good practice
String newId= IdService.idIncrement(latestId); //Not a good practice

//@Deprecated
//accountRepo.insertANewRecordInTheAccountAuthenticationTableInTheDatabaseWithPendingAccountStatusAsDefault(newID,username,password,email);

AccountEntity newAccount = new AccountEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DashboardService(CategoryRepo categoryRepo, TotalAssetsRepo totalassetsRe
*/
public Dashboard getAnalytics(){

return new Dashboard( categoryRepo.getCategoricalAnalytics(), totalassetsRepo.gettotalassets() );
return new Dashboard( categoryRepo.getCategoricalAnalytics(), totalassetsRepo.GetTheTotalAmountOfAllActiveAssetsInTheInventory() );

}
}
23 changes: 14 additions & 9 deletions src/main/java/com/ebiggerr/sims/service/input/ImageUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ public static String saveUploadFile(MultipartFile file, String filename) throws

if( !file.isEmpty() ){

//String[] format = file.getOriginalFilename().split(".");
extension = Objects.requireNonNull(file.getOriginalFilename()).split("\\.")[1];
try {
//String[] format = file.getOriginalFilename().split(".");
extension = Objects.requireNonNull(file.getOriginalFilename()).split("\\.")[1];

filename = filename+ "."+ extension;
filename = filename + "." + extension;

//normal size
byte[] bytes = file.getBytes();
Path path = Paths.get(UPLOADED_FOLDER + filename);
Files.write(path, bytes);
//normal size
byte[] bytes = file.getBytes();
Path path = Paths.get(UPLOADED_FOLDER + filename);
Files.write(path, bytes);

//thumbnail size
//TODO thumbnail resize
//thumbnail size
//TODO thumbnail resize

}catch (Exception exception){
throw new IOException(exception.getMessage());
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@

package com.ebiggerr.sims.service.inventory;

import ch.qos.logback.classic.Logger;
import com.ebiggerr.sims.domain.dashboard.Category;
import com.ebiggerr.sims.domain.inventory.Item;
import com.ebiggerr.sims.domain.inventory.ItemDTO;
import com.ebiggerr.sims.domain.request.ItemWithImageRequest;
import com.ebiggerr.sims.domain.response.Inventory;
import com.ebiggerr.sims.exception.CustomException;
import com.ebiggerr.sims.mapper.InventoryConverter;
import com.ebiggerr.sims.repository.CategoryRepo;
import com.ebiggerr.sims.repository.InventoryRepo;
Expand Down Expand Up @@ -64,7 +66,7 @@ public InventoryService(InventoryRepo inventoryRepo, CategoryRepo categoryRepo){
* @return result of the operation , populated item if successful or null in the case of failure
* @throws IOException IO exception if there is any error during the operation of writing image file from user request to the resource directory of the project
*/
public Item addNewItemImage(ItemWithImageRequest item) throws IOException {
public Item addNewItemImage(ItemWithImageRequest item) throws IOException, CustomException {

int id = inventoryRepo.getMaxID();

Expand All @@ -73,17 +75,22 @@ public Item addNewItemImage(ItemWithImageRequest item) throws IOException {
if( findDuplicates.isEmpty() ) {

Item repoItem = new Item();
//TODO use Optional
Optional<Integer> categoryIDOptional = categoryRepo.getCategoryIdByNameOptional( item.getCategoryName() );
long categoryID;
if( categoryIDOptional.isPresent() ) {
categoryID = categoryIDOptional.get();
}
else{
return null;
throw new CustomException("No Category found with the given ID.");
}

String imagePath = ImageUpload.saveUploadFile(item.getImage(), item.getSKU());
String imagePath = "";

try{
imagePath = ImageUpload.saveUploadFile(item.getImage(), item.getSKU());
}catch (IOException exception){
throw new IOException(exception.getMessage());
}

try {
Item itemEntity = new Item(
Expand Down Expand Up @@ -229,7 +236,7 @@ public Inventory getItemsSortedPageAndSize(int pageNumber, int pageSize){
* @param categoryID id of the category
* @return [inventory] result wrapped in together with the current page index and total pages available
*/
public Inventory getItemsByCategoryWithPageAndSize(int pageNumber, int pageSize, String categoryName, String categoryID){
public Inventory getItemsByCategoryWithPageAndSize(int pageNumber, int pageSize, String categoryName, String categoryID) throws CustomException {

if( pageNumber == 0 || pageNumber < 0 ) pageNumber = DEFAULT_FIRST_PAGE;
if( pageSize == 0 || pageSize <0 ) pageSize= DEFAULT_PAGE_SIZE;
Expand All @@ -239,8 +246,16 @@ public Inventory getItemsByCategoryWithPageAndSize(int pageNumber, int pageSize,
categoryId = Integer.parseInt(categoryID);

if( categoryId == 0 ){

categoryId = categoryRepo.getCategoryIdByName(categoryName);
Optional<Integer> categoryIdOptional = categoryRepo.getCategoryIdByNameOptional(categoryName);
if( categoryIdOptional.isPresent()){
categoryId = categoryIdOptional.get();
}
else{
throw new CustomException("No Category found with the given ID.");
}
}
else{
throw new CustomException("No Category found with the given ID.");
}

PageRequest pageRequest=PageRequest.of(pageNumber-1,pageSize, Sort.by("itemid").ascending() );
Expand Down
Loading