Skip to content

Commit

Permalink
Merge pull request #64 from unsri-hackers/staging
Browse files Browse the repository at this point in the history
Seamless Vendor Onboarding
  • Loading branch information
lloistborn authored Jul 10, 2021
2 parents 2097ad6 + e64acec commit f29784a
Show file tree
Hide file tree
Showing 58 changed files with 592 additions and 160 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>

</dependencies>
</dependencies>

<build>
<plugins>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/unsri/ecommerce/EcommerceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EnableJpaRepositories
public class EcommerceApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.unsri.ecommerce.application.behaviours.inventory.commands;

import com.unsri.ecommerce.presentation.controllers.request.InventoryDTO;

public class AddInventoryCommand extends InventoryDTO {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.unsri.ecommerce.application.behaviours.inventory.commands;

import com.unsri.ecommerce.infrastructure.mediator.Handler;
import com.unsri.ecommerce.infrastructure.mediator.Response;
import com.unsri.ecommerce.application.entities.EnumStateCode;
import com.unsri.ecommerce.application.domain.Inventory;
import com.unsri.ecommerce.application.domain.PhotoInventory;
import com.unsri.ecommerce.infrastructure.repository.InventoryRepository;
import com.unsri.ecommerce.presentation.controllers.request.PhotoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class AddInventoryCommandHandler implements Handler<AddInventoryCommand, Response<Inventory, EnumStateCode>> {

@Autowired
InventoryRepository _repository;

@Override
public Response<Inventory, EnumStateCode> handle(AddInventoryCommand addInventoryCommand) {
try {
Inventory inventory = this._repository.save(toInventory(addInventoryCommand));
return new Response<>(inventory, EnumStateCode.SUCCESS, null);
} catch (Exception ex) {
return new Response<>(null, EnumStateCode.ERROR, ex.getMessage());
}
}

private Inventory toInventory(AddInventoryCommand command) {
Inventory inventory = new Inventory();

inventory.setItemName(command.getProductName());
inventory.setPrice(Double.parseDouble(command.getPrice()));
inventory.setFkSellerId(command.getSellerId());

List<PhotoInventory> inventories = new ArrayList<>();

for (PhotoDTO photoDTO : command.getPhotos()) {
PhotoInventory newInventory = new PhotoInventory();
newInventory.setName(photoDTO.getName());
newInventory.setPath(photoDTO.getPath());

inventories.add(newInventory);
}

inventory.setPhotos(inventories);

return inventory;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.unsri.ecommerce.application.behaviours.inventory.commands;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.Inventory;
import com.unsri.ecommerce.application.domain.Inventory;
import com.unsri.ecommerce.infrastructure.repository.InventoryRepository;

import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.unsri.ecommerce.application.behaviours.inventory.commands;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.Inventory;
import com.unsri.ecommerce.application.domain.Inventory;
import com.unsri.ecommerce.infrastructure.repository.InventoryRepository;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.unsri.ecommerce.application.behaviours.inventory.queries;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.Inventory;
import com.unsri.ecommerce.application.domain.Inventory;
import com.unsri.ecommerce.infrastructure.repository.InventoryRepository;
import org.springframework.data.domain.Pageable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.unsri.ecommerce.application.behaviours.inventory.queries;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.Inventory;
import com.unsri.ecommerce.application.domain.Inventory;
import com.unsri.ecommerce.infrastructure.repository.InventoryRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class GetInventoriesPaginated implements BaseCommand<Page<Inventory>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.unsri.ecommerce.application.behaviours.inventory.queries;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.Inventory;
import com.unsri.ecommerce.application.domain.Inventory;
import com.unsri.ecommerce.infrastructure.repository.InventoryRepository;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.unsri.ecommerce.application.behaviours.inventory.queries;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.Inventory;
import com.unsri.ecommerce.application.domain.Inventory;
import com.unsri.ecommerce.infrastructure.repository.InventoryRepository;

import java.util.List;
import java.util.Optional;

public class GetInventory implements BaseCommand<List<Inventory>> {

private InventoryRepository _repository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.unsri.ecommerce.application.behaviours.seller.commands;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.infrastructure.webconfig.jwt.JwtUtils;
import com.unsri.ecommerce.infrastructure.webconfig.service.SellerDetailsImpl;
import com.unsri.ecommerce.presentation.payload.response.JwtResponse;
import com.unsri.ecommerce.presentation.webconfig.jwt.JwtUtils;
import com.unsri.ecommerce.presentation.webconfig.service.SellerDetailsImpl;
import com.unsri.ecommerce.presentation.controllers.response.JwtResponse;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class LoginSeller implements BaseCommand<JwtResponse> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.unsri.ecommerce.application.behaviours.seller.commands;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.JwtUser;
import com.unsri.ecommerce.application.domain.JwtUser;
import com.unsri.ecommerce.infrastructure.repository.JwtUserRepository;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.unsri.ecommerce.application.behaviours.seller.commands;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.Seller;
import com.unsri.ecommerce.application.domain.Seller;
import com.unsri.ecommerce.infrastructure.repository.SellerRepository;
import com.unsri.ecommerce.infrastructure.webconfig.jwt.JwtUtils;
import com.unsri.ecommerce.infrastructure.webconfig.service.SellerDetailsImpl;
import com.unsri.ecommerce.presentation.payload.response.JwtResponse;
import com.unsri.ecommerce.presentation.payload.response.RegisterResponse;
import com.unsri.ecommerce.presentation.webconfig.jwt.JwtUtils;
import com.unsri.ecommerce.presentation.webconfig.service.SellerDetailsImpl;
import com.unsri.ecommerce.presentation.controllers.response.JwtResponse;
import com.unsri.ecommerce.presentation.controllers.response.RegisterResponse;
import net.bytebuddy.utility.RandomString;
import org.springframework.http.HttpStatus;
import org.springframework.mail.javamail.JavaMailSender;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.unsri.ecommerce.application.behaviours.seller.queries;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.application.domain.Seller;
import com.unsri.ecommerce.infrastructure.repository.SellerRepository;

import java.util.Optional;

public class GetSellerById implements BaseCommand<Seller> {

private final SellerRepository sellerRepository;

public GetSellerById(SellerRepository sellerRepository){
this.sellerRepository = sellerRepository;
}

@Override
public Seller execute(Optional<Seller> sellerId) {
Optional<Seller> seller = sellerRepository.findById(sellerId.get().getId());

return seller.get();
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.unsri.ecommerce.application.behaviours.seller.query;
package com.unsri.ecommerce.application.behaviours.seller.queries;

import com.unsri.ecommerce.application.behaviours.BaseCommand;
import com.unsri.ecommerce.domain.models.Seller;
import com.unsri.ecommerce.application.domain.Seller;
import com.unsri.ecommerce.infrastructure.repository.SellerRepository;

import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException;
import java.util.Optional;

public class VerifySeller implements BaseCommand<String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.unsri.ecommerce.domain.models;
package com.unsri.ecommerce.application.domain;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "INVENTORY")
Expand All @@ -10,7 +11,7 @@ public class Inventory {
@Id
@GeneratedValue
@Column
private int id;
private Integer id;

@Column
private String itemName;
Expand All @@ -21,7 +22,7 @@ public class Inventory {
@Column(name = "fk_seller_id")
private Integer fkSellerId;

@OneToMany(targetEntity = PhotoInventory.class)
@OneToMany(targetEntity = PhotoInventory.class, cascade = CascadeType.ALL)
@JoinColumn(name = "fk_inventory_id", referencedColumnName = "id")
private List<PhotoInventory> photoInventories;

Expand All @@ -36,11 +37,11 @@ public Inventory(String itemName, Double price, Integer fkSellerId, List<PhotoIn
this.photoInventories = photoInventories;
}

public int getId() {
public Integer getId() {
return id;
}

public void setId(int id) {
public void setId(Integer id) {
this.id = id;
}

Expand Down Expand Up @@ -75,4 +76,28 @@ public List<PhotoInventory> getPhotos() {
public void setPhotos(List<PhotoInventory> photoInventories) {
this.photoInventories = photoInventories;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Inventory inventory = (Inventory) o;
return Objects.equals(id, inventory.id) && Objects.equals(itemName, inventory.itemName) && Objects.equals(price, inventory.price) && Objects.equals(fkSellerId, inventory.fkSellerId) && Objects.equals(photoInventories, inventory.photoInventories);
}

@Override
public int hashCode() {
return Objects.hash(id, itemName, price, fkSellerId, photoInventories);
}

@Override
public String toString() {
return "Inventory{" +
"id=" + id +
", itemName='" + itemName + '\'' +
", price=" + price +
", fkSellerId=" + fkSellerId +
", photoInventories=" + photoInventories +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.unsri.ecommerce.domain.models;
package com.unsri.ecommerce.application.domain;

import javax.persistence.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.unsri.ecommerce.domain.models;
package com.unsri.ecommerce.application.domain;

import javax.persistence.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.unsri.ecommerce.domain.models;
package com.unsri.ecommerce.application.domain;

import javax.persistence.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.unsri.ecommerce.domain.models;
package com.unsri.ecommerce.application.domain;

import javax.persistence.*;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.unsri.ecommerce.application.entities;

public enum EnumStateCode {
SUCCESS("SUCCESS"),
ERROR("ERROR");

public final String label;

private EnumStateCode(String label) {
this.label = label;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.unsri.ecommerce.domain.models;
package com.unsri.ecommerce.application.entities;

import com.unsri.ecommerce.application.domain.PhotoInventory;

import java.util.List;

Expand Down
Loading

0 comments on commit f29784a

Please sign in to comment.