diff --git a/sql/flightmanagement.session.sql b/sql/flightmanagement.session.sql index 72c5e46..411a65b 100644 --- a/sql/flightmanagement.session.sql +++ b/sql/flightmanagement.session.sql @@ -1,6 +1,8 @@ +drop database flightmanagement; +create database flightmanagement; USE `flightmanagement`; CREATE TABLE IF NOT EXISTS `user` ( - `user_id` int(11) NULL AUTO_INCREMENT, + `user_id` BIGINT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `password` varchar(255) NOT NULL, `email` varchar(100) NULL, @@ -24,4 +26,16 @@ VALUES ( 'admin', 'sakurapuare@sakurapuare.com', 15 - ); \ No newline at end of file + ); +CREATE TABLE IF NOT EXISTS `airline` ( + `airline_id` BIGINT NULL AUTO_INCREMENT, + `user_id` BIGINT NOT NULL, + `airline_name` varchar(100) NOT NULL, + `airline_country` varchar(100) NOT NULL, + `airline_code` varchar(10) NOT NULL, + `airline_description` varchar(255) NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`airline_id`), + FOREIGN KEY (`user_id`) REFERENCES `user`(`user_id`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8; \ No newline at end of file diff --git a/src/main/java/com/sakurapuare/flightmanagement/controllers/AuthController.java b/src/main/java/com/sakurapuare/flightmanagement/controllers/AuthController.java index 41ed331..a3e18c6 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/controllers/AuthController.java +++ b/src/main/java/com/sakurapuare/flightmanagement/controllers/AuthController.java @@ -1,10 +1,14 @@ package com.sakurapuare.flightmanagement.controllers; import com.sakurapuare.flightmanagement.common.Response; -import com.sakurapuare.flightmanagement.mapper.UserMapper; +import com.sakurapuare.flightmanagement.constant.UserType; +import com.sakurapuare.flightmanagement.mapper.*; import com.sakurapuare.flightmanagement.pojo.dto.auth.login.UserLoginDTO; +import com.sakurapuare.flightmanagement.pojo.dto.auth.register.BaseUserRegisterDTO; import com.sakurapuare.flightmanagement.pojo.dto.auth.register.UserRegisterDTO; -import com.sakurapuare.flightmanagement.pojo.entity.User; +import com.sakurapuare.flightmanagement.pojo.entity.user.Airline; +import com.sakurapuare.flightmanagement.pojo.entity.user.User; +import com.sakurapuare.flightmanagement.pojo.entity.user.info.AirlineInfo; import com.sakurapuare.flightmanagement.pojo.vo.UserLoginVO; import com.sakurapuare.flightmanagement.services.AuthService; import com.sakurapuare.flightmanagement.utils.UserTypeUtils; @@ -13,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -30,8 +35,20 @@ public class AuthController { @Autowired private UserMapper userMapper; + @Autowired + private AirlineMapper airlineMapper; + + @Autowired + private MerchantMapper merchantMapper; + + @Autowired + private PassengerMapper passengerMapper; + + @Autowired + private StaffMapper staffMapper; + @PostMapping("/login") - public Response login(@Valid @RequestBody UserLoginDTO userLoginDTO) { + public Response login(@Validated @RequestBody UserLoginDTO userLoginDTO) { User user = userMapper.findUserByUsernameAndPassword( userLoginDTO.getUsername(), userLoginDTO.getPassword()); @@ -44,28 +61,107 @@ public Response login(@Valid @RequestBody UserLoginDTO userLoginDTO } } - @PostMapping("/register") - public Response register(@RequestBody UserRegisterDTO userRegisterDTO) { - // LOG - log.info("Register: {}", userRegisterDTO); + @PostMapping("/register/airline") + public Response register_airline( + @Valid @RequestBody UserRegisterDTO airlineInfoUserRegisterDTO) { + User user = userMapper.findUserByUsername(airlineInfoUserRegisterDTO.getUsername()); + Airline airline = airlineMapper.findAirlineByAirlineCode(airlineInfoUserRegisterDTO.getData().getAirlineCode()); + + if (user != null && airline != null) { + return Response.error("Airline already exists"); + } - // Register Role - User user = userMapper.findUserByUsername(userRegisterDTO.getUsername()); - int role = userRegisterDTO.getRole(); + // check password if (user != null) { - if (!user.getPassword().equals(userRegisterDTO.getPassword())) - return Response.error("Invalid password"); - if (UserTypeUtils.isContain(user.getRole(), role)) - return Response.error("User already exists"); - user.setRole(UserTypeUtils.addRole(user.getRole(), role)); + if (!airlineInfoUserRegisterDTO.getPassword().equals(user.getPassword())) { + return Response.error("Password not match"); + } + } + + if (user == null) { + user = new User(); + BeanUtils.copyProperties(airlineInfoUserRegisterDTO, user); + user.setRole(UserType.AIRLINE); + userMapper.insert(user); + } + if (airline == null) { + airline = new Airline(); + BeanUtils.copyProperties(airlineInfoUserRegisterDTO.getData(), airline); + user.setRole(UserTypeUtils.addRole(user.getRole(), UserType.AIRLINE)); + airline.setUserId(user.getUserId()); + airlineMapper.insert(airline); userMapper.updateById(user); - return Response.success("Update role success"); - } else { + return Response.success("Airline Register success"); + } + return Response.error("User already exists"); + } + + // @PostMapping("/register/merchant") + // public Response register_merchant(@Valid @RequestBody + // MerchantRegisterDTO merchantRegisterDTO) { + // User user = userMapper.findUserByUsername(merchantRegisterDTO.getUsername()); + // Merchant merchant = + // merchantMapper.findMerchantByMerchantCode(merchantRegisterDTO.getData().getMerchantCode()); + + // if (user == null) { + // user = new User(); + // BeanUtils.copyProperties(merchantRegisterDTO, user); + // user.setRole(UserType.MERCHANT); + // userMapper.insert(user); + // return Response.success("Merchant Register success"); + // } + // return Response.error("User already exists"); + // } + + @PostMapping("/register") + public Response register_user(@Valid @RequestBody BaseUserRegisterDTO baseUserRegisterDTO) { + User user = userMapper.findUserByUsername(baseUserRegisterDTO.getUsername()); + if (user == null) { user = new User(); - BeanUtils.copyProperties(userRegisterDTO, user); + BeanUtils.copyProperties(baseUserRegisterDTO, user); userMapper.insert(user); + return Response.success("Register success"); } - return Response.success("Register success"); + return Response.error("User already exists"); } + // public Response register_user(@Valid @RequestBody UserRegisterDTO + // userRegisterDTO) { + // User user = userMapper.findUserByUsername(userRegisterDTO.getUsername()); + // int role = userRegisterDTO.getRole(); + + // // ALL type is not allowed to register + // if (role == UserType.ALL || UserTypeUtils.getRoleCount(role) != 1) + // return Response.error("Invalid role"); + // if (userRegisterDTO.getData() == null) + // return Response.error("User info is required"); + + // if (user == null) { + // user = new User(); + // BeanUtils.copyProperties(userRegisterDTO, user); + // userMapper.insert(user); + // if (role != 0) { + // if (userRegisterDTO.getData() == null) + // return Response.error("User info is required"); + + // UserInfo userInfo = UserRegisterInfoFactory.create(userRegisterDTO, role); + // if (userInfo == null || !userInfo.checkDataIntegrity()) + // return Response.error("Data integrity error"); + // } + // } else { + // if (!user.getPassword().equals(userRegisterDTO.getPassword())) + // return Response.error("Invalid password"); + // if (UserTypeUtils.isContain(user.getRole(), role)) + // return Response.error("User already exists"); + // if (userRegisterDTO.getData() == null) + // return Response.error("User info is required"); + + // UserInfo userInfo = UserRegisterInfoFactory.create(userRegisterDTO, role); + // if (userInfo == null || !userInfo.checkDataIntegrity()) + // return Response.error("Data integrity error"); + // } + + // return Response.success("Register success"); + // } + } diff --git a/src/main/java/com/sakurapuare/flightmanagement/controllers/UserController.java b/src/main/java/com/sakurapuare/flightmanagement/controllers/UserController.java index 588155e..fe0ceaf 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/controllers/UserController.java +++ b/src/main/java/com/sakurapuare/flightmanagement/controllers/UserController.java @@ -1,6 +1,5 @@ package com.sakurapuare.flightmanagement.controllers; - import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; @@ -12,5 +11,4 @@ @Tag(name = "User Controller", description = "User API Endpoints") public class UserController { - } diff --git a/src/main/java/com/sakurapuare/flightmanagement/mapper/AirlineMapper.java b/src/main/java/com/sakurapuare/flightmanagement/mapper/AirlineMapper.java index 389b663..84ff1bd 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/mapper/AirlineMapper.java +++ b/src/main/java/com/sakurapuare/flightmanagement/mapper/AirlineMapper.java @@ -1,10 +1,16 @@ package com.sakurapuare.flightmanagement.mapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.sakurapuare.flightmanagement.pojo.entity.Airline; +import com.sakurapuare.flightmanagement.pojo.entity.user.Airline; import org.apache.ibatis.annotations.Mapper; @Mapper public interface AirlineMapper extends BaseMapper { + default Airline findAirlineByAirlineCode(String airlineCode) { + return this.selectOne( + new QueryWrapper() + .eq("airline_code", airlineCode)); + } } \ No newline at end of file diff --git a/src/main/java/com/sakurapuare/flightmanagement/mapper/MerchantMapper.java b/src/main/java/com/sakurapuare/flightmanagement/mapper/MerchantMapper.java index b6dd3b0..de66d2a 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/mapper/MerchantMapper.java +++ b/src/main/java/com/sakurapuare/flightmanagement/mapper/MerchantMapper.java @@ -1,7 +1,7 @@ package com.sakurapuare.flightmanagement.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.sakurapuare.flightmanagement.pojo.entity.Merchant; +import com.sakurapuare.flightmanagement.pojo.entity.user.Merchant; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/src/main/java/com/sakurapuare/flightmanagement/mapper/PassengerMapper.java b/src/main/java/com/sakurapuare/flightmanagement/mapper/PassengerMapper.java index ddb58f3..b67fd3a 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/mapper/PassengerMapper.java +++ b/src/main/java/com/sakurapuare/flightmanagement/mapper/PassengerMapper.java @@ -1,7 +1,7 @@ package com.sakurapuare.flightmanagement.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.sakurapuare.flightmanagement.pojo.entity.Passenger; +import com.sakurapuare.flightmanagement.pojo.entity.user.Passenger; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/src/main/java/com/sakurapuare/flightmanagement/mapper/StaffMapper.java b/src/main/java/com/sakurapuare/flightmanagement/mapper/StaffMapper.java index 0cdfbc2..5324e0e 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/mapper/StaffMapper.java +++ b/src/main/java/com/sakurapuare/flightmanagement/mapper/StaffMapper.java @@ -1,7 +1,7 @@ package com.sakurapuare.flightmanagement.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.sakurapuare.flightmanagement.pojo.entity.Staff; +import com.sakurapuare.flightmanagement.pojo.entity.user.Staff; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/src/main/java/com/sakurapuare/flightmanagement/mapper/UserMapper.java b/src/main/java/com/sakurapuare/flightmanagement/mapper/UserMapper.java index 9a8a5e7..4ef85c7 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/mapper/UserMapper.java +++ b/src/main/java/com/sakurapuare/flightmanagement/mapper/UserMapper.java @@ -2,7 +2,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.sakurapuare.flightmanagement.pojo.entity.User; +import com.sakurapuare.flightmanagement.pojo.entity.user.User; import org.apache.ibatis.annotations.Mapper; import java.util.List; diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/login/UserLoginDTO.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/login/UserLoginDTO.java index 7868919..447dd06 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/login/UserLoginDTO.java +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/login/UserLoginDTO.java @@ -1,9 +1,12 @@ package com.sakurapuare.flightmanagement.pojo.dto.auth.login; +import jakarta.validation.constraints.NotBlank; import lombok.Data; @Data public class UserLoginDTO { + @NotBlank(message = "Username is required") String username; + @NotBlank(message = "Password is required") String password; } diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/AirlineRegisterDTO.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/AirlineRegisterDTO.java deleted file mode 100644 index 42a0774..0000000 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/AirlineRegisterDTO.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.sakurapuare.flightmanagement.pojo.dto.auth.register; - -import lombok.Data; - -@Data -public class AirlineRegisterDTO { -} \ No newline at end of file diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/BaseUserRegisterDTO.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/BaseUserRegisterDTO.java new file mode 100644 index 0000000..2360c0c --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/BaseUserRegisterDTO.java @@ -0,0 +1,20 @@ +package com.sakurapuare.flightmanagement.pojo.dto.auth.register; + +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +@Data +public class BaseUserRegisterDTO { + @NotBlank(message = "Username is required") + public String username; + + @NotBlank(message = "Password is required") + public String password; + + @Email(message = "Email is invalid") + public String email; + + // @Size(min = 0, max = UserType.ALL, message = "Role is invalid") + // public int role; +} \ No newline at end of file diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/MerchantRegisterDTO.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/MerchantRegisterDTO.java deleted file mode 100644 index e9a3a39..0000000 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/MerchantRegisterDTO.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.sakurapuare.flightmanagement.pojo.dto.auth.register; - -public class MerchantRegisterDTO { - -} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/PassengerRegisterDTO.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/PassengerRegisterDTO.java deleted file mode 100644 index 8b65af6..0000000 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/PassengerRegisterDTO.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sakurapuare.flightmanagement.pojo.dto.auth.register; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class PassengerRegisterDTO extends UserRegisterDTO { - PassengerInfo data; -} - -@Data -class PassengerInfo { - String identityNumber; -} \ No newline at end of file diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/StaffRegisterDTO.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/StaffRegisterDTO.java deleted file mode 100644 index 5407059..0000000 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/StaffRegisterDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sakurapuare.flightmanagement.pojo.dto.auth.register; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = true) -public class StaffRegisterDTO extends UserRegisterDTO { - - StaffInfo data; -} - -@Data -class StaffInfo { - -} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/UserRegisterDTO.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/UserRegisterDTO.java index 0e86812..9d1f8ec 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/UserRegisterDTO.java +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/dto/auth/register/UserRegisterDTO.java @@ -1,19 +1,10 @@ package com.sakurapuare.flightmanagement.pojo.dto.auth.register; -import com.sakurapuare.flightmanagement.constant.UserType; -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; +import jakarta.validation.constraints.NotNull; import lombok.Data; @Data -public class UserRegisterDTO { - @NotBlank(message = "Username is required") - public String username; - @NotBlank(message = "Password is required") - public String password; - @Email(message = "Email is invalid") - public String email; - @Size(min = 0, max = UserType.ALL, message = "Role is invalid") - public int role; +public class UserRegisterDTO extends BaseUserRegisterDTO { + @NotNull(message = "Merchant info is required") + T data; } diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Airline.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Airline.java deleted file mode 100644 index 126023e..0000000 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Airline.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sakurapuare.flightmanagement.pojo.entity; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = false) -public class Airline { - @TableId(value = "airline_id") - private Long airlineId; - - @TableField(value = "user_id") - private Long userId; -} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Merchant.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Merchant.java deleted file mode 100644 index f390882..0000000 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Merchant.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.sakurapuare.flightmanagement.pojo.entity; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import lombok.Data; - -@Data -public class Merchant { - @TableId(value = "merchant_id") - private Long merchantId; - - @TableField(value = "user_id") - private Long userId; -} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Staff.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Staff.java deleted file mode 100644 index eb250ee..0000000 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Staff.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sakurapuare.flightmanagement.pojo.entity; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = false) -public class Staff { - @TableId(value = "staff_id") - private Long staffId; - - @TableField(value = "user_id") - private Long userId; -} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Ticket.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Ticket.java new file mode 100644 index 0000000..fb5f273 --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Ticket.java @@ -0,0 +1,39 @@ +package com.sakurapuare.flightmanagement.pojo.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class Ticket { + + @TableId(value = "id") + private Long id; + + @TableField(value = "flight_id") + private Long flightId; + + @TableField(value = "passenger_id") + private Long passengerId; + + @TableField(value = "seat_class") + private String seatClass; + + @TableField(value = "seat_number") + private String seatNumber; + + @TableField(value = "status") + private String status; + + @TableField(value = "price") + private String price; + + @TableField(value = "created_at", fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Airline.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Airline.java new file mode 100644 index 0000000..392a08d --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Airline.java @@ -0,0 +1,37 @@ +package com.sakurapuare.flightmanagement.pojo.entity.user; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +@Data +@EqualsAndHashCode(callSuper = false) +public class Airline { + @TableId(value = "airline_id") + private Long airlineId; + + @TableField(value = "user_id") + private Long userId; + + @TableField(value = "airline_name") + private String airlineName; + + @TableField(value = "airline_country") + private String airlineCountry; + + @TableField(value = "airline_code") + private String airlineCode; + + @TableField(value = "airline_description") + private String airlineDescription; + + @TableField(value = "created_at", fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Merchant.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Merchant.java new file mode 100644 index 0000000..239b948 --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Merchant.java @@ -0,0 +1,32 @@ +package com.sakurapuare.flightmanagement.pojo.entity.user; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class Merchant { + @TableId(value = "merchant_id") + private Long merchantId; + + @TableField(value = "user_id") + private Long userId; + + @TableField(value = "merchant_name") + private String merchantName; + + @TableField(value = "merchant_address") + private String merchantAddress; + + @TableField(value = "merchant_description") + private String merchantDescription; + + @TableField(value = "created_at", fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Passenger.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Passenger.java similarity index 50% rename from src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Passenger.java rename to src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Passenger.java index c082f5f..e629415 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/Passenger.java +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Passenger.java @@ -1,10 +1,13 @@ -package com.sakurapuare.flightmanagement.pojo.entity; +package com.sakurapuare.flightmanagement.pojo.entity.user; +import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import lombok.Data; import lombok.EqualsAndHashCode; +import java.time.LocalDateTime; + @EqualsAndHashCode(callSuper = false) @Data public class Passenger { @@ -13,4 +16,10 @@ public class Passenger { @TableField(value = "user_id") private Long userId; + + @TableField(value = "created_at", fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updatedAt; } diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Staff.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Staff.java new file mode 100644 index 0000000..6e7e630 --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/Staff.java @@ -0,0 +1,25 @@ +package com.sakurapuare.flightmanagement.pojo.entity.user; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +@Data +@EqualsAndHashCode(callSuper = false) +public class Staff { + @TableId(value = "staff_id") + private Long staffId; + + @TableField(value = "user_id") + private Long userId; + + @TableField(value = "created_at", fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/User.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/User.java similarity index 93% rename from src/main/java/com/sakurapuare/flightmanagement/pojo/entity/User.java rename to src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/User.java index f90dfb7..b04a749 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/User.java +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/User.java @@ -1,4 +1,4 @@ -package com.sakurapuare.flightmanagement.pojo.entity; +package com.sakurapuare.flightmanagement.pojo.entity.user; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.IdType; diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/AirlineInfo.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/AirlineInfo.java new file mode 100644 index 0000000..ce31c12 --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/AirlineInfo.java @@ -0,0 +1,16 @@ +package com.sakurapuare.flightmanagement.pojo.entity.user.info; + +import lombok.Data; + + +@Data +public class AirlineInfo { + String airlineName; + + String airlineCode; + + String airlineCountry; + + String airlineDescription; + +} \ No newline at end of file diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/MerchantInfo.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/MerchantInfo.java new file mode 100644 index 0000000..a0d8e88 --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/MerchantInfo.java @@ -0,0 +1,12 @@ +package com.sakurapuare.flightmanagement.pojo.entity.user.info; + +import lombok.Data; + +@Data +public class MerchantInfo { + String merchantName; + + String merchantAddress; + + String merchantDescription; +} \ No newline at end of file diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/PassengerInfo.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/PassengerInfo.java new file mode 100644 index 0000000..d898c2c --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/PassengerInfo.java @@ -0,0 +1,10 @@ +package com.sakurapuare.flightmanagement.pojo.entity.user.info; + +import lombok.Data; + + +@Data +public class PassengerInfo { + String identityNumber; + +} \ No newline at end of file diff --git a/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/StaffInfo.java b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/StaffInfo.java new file mode 100644 index 0000000..846190c --- /dev/null +++ b/src/main/java/com/sakurapuare/flightmanagement/pojo/entity/user/info/StaffInfo.java @@ -0,0 +1,9 @@ +package com.sakurapuare.flightmanagement.pojo.entity.user.info; + +import lombok.Data; + + +@Data +public class StaffInfo { + +} diff --git a/src/main/java/com/sakurapuare/flightmanagement/services/AuthService.java b/src/main/java/com/sakurapuare/flightmanagement/services/AuthService.java index d066641..48635c5 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/services/AuthService.java +++ b/src/main/java/com/sakurapuare/flightmanagement/services/AuthService.java @@ -1,7 +1,9 @@ package com.sakurapuare.flightmanagement.services; import com.sakurapuare.flightmanagement.pojo.dto.auth.login.UserLoginDTO; -import com.sakurapuare.flightmanagement.pojo.entity.User; +import com.sakurapuare.flightmanagement.pojo.entity.user.Airline; +import com.sakurapuare.flightmanagement.pojo.entity.user.User; +import com.sakurapuare.flightmanagement.pojo.entity.user.info.AirlineInfo; public interface AuthService { diff --git a/src/main/java/com/sakurapuare/flightmanagement/services/impl/AuthServiceImpl.java b/src/main/java/com/sakurapuare/flightmanagement/services/impl/AuthServiceImpl.java index 6f8406b..09980b9 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/services/impl/AuthServiceImpl.java +++ b/src/main/java/com/sakurapuare/flightmanagement/services/impl/AuthServiceImpl.java @@ -3,7 +3,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.sakurapuare.flightmanagement.mapper.UserMapper; import com.sakurapuare.flightmanagement.pojo.dto.auth.login.UserLoginDTO; -import com.sakurapuare.flightmanagement.pojo.entity.User; +import com.sakurapuare.flightmanagement.pojo.entity.user.User; import com.sakurapuare.flightmanagement.services.AuthService; import com.sakurapuare.flightmanagement.utils.JwtTokenUtil; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/com/sakurapuare/flightmanagement/utils/UserTypeUtils.java b/src/main/java/com/sakurapuare/flightmanagement/utils/UserTypeUtils.java index 8ac1ad7..134e8cc 100644 --- a/src/main/java/com/sakurapuare/flightmanagement/utils/UserTypeUtils.java +++ b/src/main/java/com/sakurapuare/flightmanagement/utils/UserTypeUtils.java @@ -70,7 +70,7 @@ public static int removeStaff(int userType) { return userType & UserType.ALL - UserType.STAFF; } - public static List getUserType(int userType) { + public static List getRoleList(int userType) { List userTypeList = new ArrayList<>(); if (isPassenger(userType)) { userTypeList.add("Passenger"); @@ -86,4 +86,21 @@ public static List getUserType(int userType) { } return userTypeList; } + + public static int getRoleCount(int userType) { + int count = 0; + if (isPassenger(userType)) { + count++; + } + if (isMerchant(userType)) { + count++; + } + if (isAirline(userType)) { + count++; + } + if (isStaff(userType)) { + count++; + } + return count; + } }