Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #40 from hardingadonis/vuong-code-base
Browse files Browse the repository at this point in the history
Write code base, done #41 , done #42
  • Loading branch information
hardingadonis authored Jan 18, 2024
2 parents a3c205b + d87fffc commit 6a0122f
Show file tree
Hide file tree
Showing 22 changed files with 661 additions and 6 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>0.0.2</version>
<packaging>war</packaging>

<name>Sale Dock - v${version}</name>
<name>Sale Dock - v${project.version}</name>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down Expand Up @@ -55,6 +55,12 @@
<artifactId>jersey-hk2</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.0</version>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/hardingadonis/saledock/dao/ICategoryDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.hardingadonis.saledock.dao;

import io.hardingadonis.saledock.model.*;

public interface ICategoryDAO extends IDAO<Category> {
}
6 changes: 6 additions & 0 deletions src/main/java/io/hardingadonis/saledock/dao/ICustomerDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.hardingadonis.saledock.dao;

import io.hardingadonis.saledock.model.*;

public interface ICustomerDAO extends IDAO<Customer> {
}
14 changes: 14 additions & 0 deletions src/main/java/io/hardingadonis/saledock/dao/IDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.hardingadonis.saledock.dao;

import java.util.*;

public interface IDAO<T> {

public void add(T obj);

public Optional<T> getByID(Integer ID);

public List<T> getAll();

void update(T obj);
}
6 changes: 6 additions & 0 deletions src/main/java/io/hardingadonis/saledock/dao/IEmployeeDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.hardingadonis.saledock.dao;

import io.hardingadonis.saledock.model.*;

public interface IEmployeeDAO extends IDAO<Employee> {
}
7 changes: 7 additions & 0 deletions src/main/java/io/hardingadonis/saledock/dao/IOrderDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.hardingadonis.saledock.dao;

import io.hardingadonis.saledock.model.*;

public interface IOrderDAO extends IDAO<Order> {

}
6 changes: 6 additions & 0 deletions src/main/java/io/hardingadonis/saledock/dao/IProductDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.hardingadonis.saledock.dao;

import io.hardingadonis.saledock.model.*;

public interface IProductDAO extends IDAO<Product> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.hardingadonis.saledock.dao.impl;

import io.hardingadonis.saledock.dao.*;
import io.hardingadonis.saledock.model.*;
import io.hardingadonis.saledock.utils.*;
import java.util.*;
import org.hibernate.*;

public class CategoryDAOImpl implements ICategoryDAO {

private final SessionFactory sessionFactory;

public CategoryDAOImpl() {
this.sessionFactory = HibernateUtil.getSessionFactory();
}

@Override
public void add(Category obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.persist(obj);
session.getTransaction().commit();
}
}

@Override
public Optional<Category> getByID(Integer ID) {
try (Session session = sessionFactory.openSession()) {
return Optional.ofNullable(session.get(Category.class, ID));
}
}

@Override
public List<Category> getAll() {
try (Session session = sessionFactory.openSession()) {
return session.createQuery("FROM Category", Category.class).getResultList();
}
}

@Override
public void update(Category obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.merge(obj);
session.getTransaction().commit();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.hardingadonis.saledock.dao.impl;

import io.hardingadonis.saledock.dao.*;
import io.hardingadonis.saledock.model.*;
import io.hardingadonis.saledock.utils.*;
import java.util.*;
import org.hibernate.*;

public class CustomerDAOImpl implements ICustomerDAO {

private final SessionFactory sessionFactory;

public CustomerDAOImpl() {
this.sessionFactory = HibernateUtil.getSessionFactory();
}

@Override
public void add(Customer obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.persist(obj);
session.getTransaction().commit();
}
}

@Override
public Optional<Customer> getByID(Integer ID) {
try (Session session = sessionFactory.openSession()) {
return Optional.ofNullable(session.get(Customer.class, ID));
}
}

@Override
public List<Customer> getAll() {
try (Session session = sessionFactory.openSession()) {
return session.createQuery("FROM Customer", Customer.class).getResultList();
}
}

@Override
public void update(Customer obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.merge(obj);
session.getTransaction().commit();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.hardingadonis.saledock.dao.impl;

import io.hardingadonis.saledock.dao.*;
import io.hardingadonis.saledock.model.*;
import io.hardingadonis.saledock.utils.*;
import java.util.*;
import org.hibernate.*;

public class EmployeeDAOImpl implements IEmployeeDAO {

private final SessionFactory sessionFactory;

public EmployeeDAOImpl() {
this.sessionFactory = HibernateUtil.getSessionFactory();
}

@Override
public void add(Employee obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.persist(obj);
session.getTransaction().commit();
}
}

@Override
public Optional<Employee> getByID(Integer ID) {
try (Session session = sessionFactory.openSession()) {
return Optional.ofNullable(session.get(Employee.class, ID));
}
}

@Override
public List<Employee> getAll() {
try (Session session = sessionFactory.openSession()) {
return session.createQuery("FROM Employee", Employee.class).getResultList();
}
}

@Override
public void update(Employee obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.merge(obj);
session.getTransaction().commit();
}
}
}
48 changes: 48 additions & 0 deletions src/main/java/io/hardingadonis/saledock/dao/impl/OrderDAOImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.hardingadonis.saledock.dao.impl;

import io.hardingadonis.saledock.dao.*;
import io.hardingadonis.saledock.model.*;
import io.hardingadonis.saledock.utils.*;
import java.util.*;
import org.hibernate.*;

public class OrderDAOImpl implements IOrderDAO {

private final SessionFactory sessionFactory;

public OrderDAOImpl() {
this.sessionFactory = HibernateUtil.getSessionFactory();
}

@Override
public void add(Order obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.persist(obj);
session.getTransaction().commit();
}
}

@Override
public Optional<Order> getByID(Integer ID) {
try (Session session = sessionFactory.openSession()) {
return Optional.ofNullable(session.get(Order.class, ID));
}
}

@Override
public List<Order> getAll() {
try (Session session = sessionFactory.openSession()) {
return session.createQuery("FROM Order", Order.class).getResultList();
}
}

@Override
public void update(Order obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.merge(obj);
session.getTransaction().commit();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.hardingadonis.saledock.dao.impl;

import io.hardingadonis.saledock.dao.*;
import io.hardingadonis.saledock.model.*;
import io.hardingadonis.saledock.utils.*;
import java.util.*;
import org.hibernate.*;

public class ProductDAOImpl implements IProductDAO {

private final SessionFactory sessionFactory;

public ProductDAOImpl() {
this.sessionFactory = HibernateUtil.getSessionFactory();
}

@Override
public void add(Product obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.persist(obj);
session.getTransaction().commit();
}
}

@Override
public Optional<Product> getByID(Integer ID) {
try (Session session = sessionFactory.openSession()) {
return Optional.ofNullable(session.get(Product.class, ID));
}
}

@Override
public List<Product> getAll() {
try (Session session = sessionFactory.openSession()) {
return session.createQuery("FROM Product", Product.class).getResultList();
}
}

@Override
public void update(Product obj) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.merge(obj);
session.getTransaction().commit();
}
}
}
32 changes: 32 additions & 0 deletions src/main/java/io/hardingadonis/saledock/model/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.hardingadonis.saledock.model;

import jakarta.persistence.*;
import java.time.*;
import lombok.*;

@Entity(name = "Category")
@Table(name = "`category`")
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@EqualsAndHashCode
@ToString
public class Category {

@Id
@Column(name = "`id`")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer ID;

@Column(name = "`name`")
private String name;

@Column(name = "`created_at`")
private LocalDateTime createdAt;

@PrePersist
protected void onCreate() {
this.createdAt = LocalDateTime.now(ZoneId.of("Asia/Ho_Chi_Minh"));
}
}
Loading

0 comments on commit 6a0122f

Please sign in to comment.