Skip to content

Commit

Permalink
Merge pull request #74 from keke125/development
Browse files Browse the repository at this point in the history
refactor: Reorganize code into modules and remove unused code.
  • Loading branch information
wei-chun-Nien authored Dec 21, 2023
2 parents 04d824a + 7f0bde1 commit 246ee85
Show file tree
Hide file tree
Showing 59 changed files with 173 additions and 163 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ntou.auction.spring;

import ntou.auction.spring.data.service.UserRepository;
import ntou.auction.spring.account.repository.UserRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.sql.init.SqlDataSourceScriptDatabaseInitializer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ntou.auction.spring.security;
package ntou.auction.spring.account.config;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import ntou.auction.spring.account.service.JWTService;
import ntou.auction.spring.account.service.UserDetailsServiceImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ntou.auction.spring.security;
package ntou.auction.spring.account.config;

import ntou.auction.spring.core.AppConfig;
import ntou.auction.spring.data.Role;
import ntou.auction.spring.util.AppConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ntou.auction.spring.controller;
package ntou.auction.spring.account.controller;

import jakarta.validation.Valid;
import ntou.auction.spring.data.Role;
import ntou.auction.spring.data.entity.User;
import ntou.auction.spring.data.service.UserService;
import ntou.auction.spring.security.AuthRequest;
import ntou.auction.spring.security.JWTService;
import ntou.auction.spring.security.SignupRequest;
import ntou.auction.spring.account.entity.Role;
import ntou.auction.spring.account.entity.User;
import ntou.auction.spring.account.service.UserService;
import ntou.auction.spring.account.request.AuthRequest;
import ntou.auction.spring.account.service.JWTService;
import ntou.auction.spring.account.request.SignupRequest;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ntou.auction.spring.controller;
package ntou.auction.spring.account.controller;

import jakarta.validation.Valid;
import ntou.auction.spring.data.entity.FavoriteRequest;
import ntou.auction.spring.data.entity.Product;
import ntou.auction.spring.data.entity.User;
import ntou.auction.spring.data.service.ProductService;
import ntou.auction.spring.data.service.UserIdentity;
import ntou.auction.spring.data.service.UserService;
import ntou.auction.spring.security.SignupRequest;
import ntou.auction.spring.account.request.FavoriteRequest;
import ntou.auction.spring.product.entity.Product;
import ntou.auction.spring.account.entity.User;
import ntou.auction.spring.product.service.ProductService;
import ntou.auction.spring.account.response.UserIdentity;
import ntou.auction.spring.account.service.UserService;
import ntou.auction.spring.account.request.SignupRequest;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ntou/auction/spring/account/entity/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ntou.auction.spring.account.entity;

public enum Role {
USER, ADMIN
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ntou.auction.spring.data.entity;
package ntou.auction.spring.account.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import ntou.auction.spring.data.Role;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import ntou.auction.spring.util.AbstractEntity;
import org.hibernate.validator.constraints.Length;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ntou.auction.spring.data.service;
package ntou.auction.spring.account.repository;

import ntou.auction.spring.data.entity.User;
import ntou.auction.spring.account.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntou.auction.spring.security;
package ntou.auction.spring.account.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntou.auction.spring.data.entity;
package ntou.auction.spring.account.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntou.auction.spring.security;
package ntou.auction.spring.account.request;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntou.auction.spring.security;
package ntou.auction.spring.account.response;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package ntou.auction.spring.data.service;
package ntou.auction.spring.account.response;

import ntou.auction.spring.data.Role;
import ntou.auction.spring.data.entity.User;
import ntou.auction.spring.account.service.UserService;
import ntou.auction.spring.account.entity.Role;
import ntou.auction.spring.account.entity.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ntou.auction.spring.security;
package ntou.auction.spring.account.service;

import io.jsonwebtoken.*;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import ntou.auction.spring.account.request.AuthRequest;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ntou.auction.spring.security;
package ntou.auction.spring.account.service;

import ntou.auction.spring.data.entity.User;
import ntou.auction.spring.data.service.UserRepository;
import ntou.auction.spring.account.entity.User;
import ntou.auction.spring.account.repository.UserRepository;

import java.util.List;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ntou.auction.spring.data.service;
package ntou.auction.spring.account.service;

import ntou.auction.spring.data.entity.User;
import ntou.auction.spring.account.entity.User;

import java.util.Optional;
import java.util.Set;

import ntou.auction.spring.account.repository.UserRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ntou.auction.spring.chat.config;

import io.micrometer.common.util.StringUtils;
import ntou.auction.spring.security.JWTService;
import ntou.auction.spring.security.UserDetailsServiceImpl;
import ntou.auction.spring.account.service.JWTService;
import ntou.auction.spring.account.service.UserDetailsServiceImpl;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.messaging.Message;
Expand Down Expand Up @@ -39,7 +39,7 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
List<String> header = accessor.getNativeHeader("Authorization");
// header裡面有沒有token
if (header != null && !header.isEmpty()) {
String token = header.get(0);
String token = header.getFirst();
if (StringUtils.isNotBlank(token)) {
String username = JWTService.validateTokenAndGetUsername(token);
System.out.println("username:" + username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

import java.net.http.WebSocketHandshakeException;
import java.util.List;

@Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ntou.auction.spring.chat.controller;


import ntou.auction.spring.chat.data.entity.ChatMessage;
import ntou.auction.spring.chat.data.entity.ChatNotification;
import ntou.auction.spring.chat.data.service.ChatMessageService;
import ntou.auction.spring.chat.data.service.ChatRoomService;
import ntou.auction.spring.data.service.UserIdentity;
import ntou.auction.spring.data.service.UserService;
import ntou.auction.spring.chat.entity.ChatMessage;
import ntou.auction.spring.chat.entity.ChatNotification;
import ntou.auction.spring.chat.service.ChatMessageService;
import ntou.auction.spring.chat.service.ChatRoomService;
import ntou.auction.spring.account.response.UserIdentity;
import ntou.auction.spring.account.service.UserService;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
Expand Down Expand Up @@ -45,13 +45,6 @@ public ChatController(UserService userService, UserIdentity userIdentity, SimpMe

@MessageMapping("/send")
public void sendMessage(@Payload ChatMessage chatMessage, Principal principal) {
/*
User sender = userService.findByUsername(userIdentity.getUsername());
ChatMessage message = new ChatMessage();
message.setSenderId(sender.getId());
message.setReceiverId(chatMessageRequest.getReceiverId());
message.setContent(chatMessageRequest.getContent());
*/

// token無效
if (principal.getName() == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ntou.auction.spring.chat.data.entity;
package ntou.auction.spring.chat.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import ntou.auction.spring.data.entity.AbstractEntity;
import ntou.auction.spring.util.AbstractEntity;
import java.time.LocalDateTime;

@Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntou.auction.spring.chat.data.entity;
package ntou.auction.spring.chat.entity;

public enum ChatMessageStatus {
RECEIVED, DELIVERED
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ntou.auction.spring.chat.data.entity;
package ntou.auction.spring.chat.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import ntou.auction.spring.data.entity.AbstractEntity;
import ntou.auction.spring.util.AbstractEntity;

@Data
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ntou.auction.spring.chat.data.entity;
package ntou.auction.spring.chat.entity;

import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import ntou.auction.spring.data.entity.AbstractEntity;
import ntou.auction.spring.util.AbstractEntity;
@Entity
@Data
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@


import jakarta.validation.constraints.NotNull;
import ntou.auction.spring.chat.data.entity.ChatMessageStatus;
import ntou.auction.spring.chat.data.entity.ChatMessage;
import ntou.auction.spring.chat.entity.ChatMessageStatus;
import ntou.auction.spring.chat.entity.ChatMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ntou.auction.spring.chat.repository;

import ntou.auction.spring.chat.data.entity.ChatRoom;
import ntou.auction.spring.chat.entity.ChatRoom;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ntou.auction.spring.chat.data.service;
package ntou.auction.spring.chat.service;

import ntou.auction.spring.chat.data.entity.ChatMessage;
import ntou.auction.spring.chat.data.entity.ChatMessageStatus;
import ntou.auction.spring.chat.entity.ChatMessage;
import ntou.auction.spring.chat.entity.ChatMessageStatus;
import ntou.auction.spring.chat.exception.MessageNotFound;
import ntou.auction.spring.chat.repository.ChatMessageRepository;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ntou.auction.spring.chat.data.service;
package ntou.auction.spring.chat.service;

import ntou.auction.spring.chat.data.entity.ChatRoom;
import ntou.auction.spring.chat.entity.ChatRoom;
import ntou.auction.spring.chat.repository.ChatRoomRepository;
import org.springframework.stereotype.Service;

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/ntou/auction/spring/data/Role.java

This file was deleted.

8 changes: 4 additions & 4 deletions src/main/java/ntou/auction/spring/mail/EmailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import jakarta.mail.Message;
import jakarta.mail.internet.InternetAddress;
import ntou.auction.spring.core.AppConfig;
import ntou.auction.spring.data.entity.Product;
import ntou.auction.spring.data.entity.User;
import ntou.auction.spring.data.service.UserService;
import ntou.auction.spring.util.AppConfig;
import ntou.auction.spring.product.entity.Product;
import ntou.auction.spring.account.entity.User;
import ntou.auction.spring.account.service.UserService;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessagePreparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package ntou.auction.spring.controller;
package ntou.auction.spring.order.controller;

import jakarta.validation.Valid;
import ntou.auction.spring.data.entity.*;
import ntou.auction.spring.data.service.*;
import ntou.auction.spring.account.response.UserIdentity;
import ntou.auction.spring.account.service.UserService;
import ntou.auction.spring.order.entity.Order;
import ntou.auction.spring.order.request.AddOrderRequest;
import ntou.auction.spring.order.request.OperateOrderRequest;
import ntou.auction.spring.order.response.OrderWithProductDetail;
import ntou.auction.spring.order.service.OrderService;
import ntou.auction.spring.product.entity.Product;
import ntou.auction.spring.product.service.ProductService;
import ntou.auction.spring.shoppingcart.service.ShoppingcartService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -118,7 +126,7 @@ ResponseEntity<Map<String, String>> addOrder(@Valid @RequestBody AddOrderRequest
List<List<Long>> getrequest = request.getProductList();

for (List<Long> eachProductAddAmount : getrequest) {
Long productId = eachProductAddAmount.get(0);
Long productId = eachProductAddAmount.getFirst();
Product getProduct = productService.getID(productId);
// Id error
if (getProduct == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ntou.auction.spring.data.entity;
package ntou.auction.spring.order.entity;

import ch.qos.logback.core.joran.sanity.Pair;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import ntou.auction.spring.util.AbstractEntity;

import java.time.LocalDateTime;
import java.util.*;
Expand Down
Loading

0 comments on commit 246ee85

Please sign in to comment.