Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #59

Merged
merged 34 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0038a73
Merge pull request #47 from Hoang-Nguyen-Huy/main
Hoang-Nguyen-Huy Sep 30, 2024
e12fa24
[NguyenHCP] fix: loop data response
nguyenhcp2004 Sep 30, 2024
c44bfd8
Merge pull request #48 from Hoang-Nguyen-Huy/feat/login
nguyenhcp2004 Sep 30, 2024
3214fc3
[PBS-43][HuyNBQ] feat: implement API get all service package
HuyDiCode Oct 1, 2024
4536f8a
Merge branch 'develop' of https://github.com/Hoang-Nguyen-Huy/pod-boo…
HuyDiCode Oct 1, 2024
0b90fde
fix: upgrade org.mapstruct:mapstruct from 1.5.5.Final to 1.6.0
snyk-bot Oct 2, 2024
6635466
fix: upgrade org.projectlombok:lombok from 1.18.30 to 1.18.34
snyk-bot Oct 2, 2024
0af593a
[NguyenHCP] feat: add Swagger for API documentation
nguyenhcp2004 Oct 2, 2024
eda066f
[HoangHN] feat: update CI
Hoang-Nguyen-Huy Oct 2, 2024
27aa741
[HoangHN] fix: 💀 resolve merge conflict
Hoang-Nguyen-Huy Oct 2, 2024
d5e0da8
Merge pull request #51 from Hoang-Nguyen-Huy/feat/login
nguyenhcp2004 Oct 2, 2024
84445a7
[PBS-43][HuyNBQ] feat: implement Get rooms by typeId and Slots API
HuyDiCode Oct 2, 2024
3429836
Merge branch 'develop' into PBS-43-View-Room-Detail
HuyDiCode Oct 2, 2024
6a590ad
[PBS-43][HuyNBQ] fix: fix case only one slot as param
HuyDiCode Oct 2, 2024
e774e88
Merge branch 'PBS-43-View-Room-Detail' of https://github.com/Hoang-Ng…
HuyDiCode Oct 2, 2024
ab6726f
[PBS-43][HuyNBQ] fix: fix typo
HuyDiCode Oct 2, 2024
6be3372
Merge pull request #49 from Hoang-Nguyen-Huy/snyk-upgrade-e28659b0b86…
Hoang-Nguyen-Huy Oct 3, 2024
2dd173e
Merge branch 'develop' into snyk-upgrade-1a2f4c4272e489eab5788ab038d9…
Hoang-Nguyen-Huy Oct 3, 2024
9999683
Merge pull request #50 from Hoang-Nguyen-Huy/snyk-upgrade-1a2f4c4272e…
Hoang-Nguyen-Huy Oct 3, 2024
55fb315
[PBS-40][HoangHN] chore: 🙈 roomTypeId might be null on request
Hoang-Nguyen-Huy Oct 3, 2024
aa181ec
[PBS-54][Anh Dao] fix: change param get payment api
toki-ai Oct 3, 2024
ddeae45
Merge pull request #52 from Hoang-Nguyen-Huy/PBS-43-View-Room-Detail
nguyenhcp2004 Oct 4, 2024
5896749
Merge pull request #53 from Hoang-Nguyen-Huy/feature/PBS-36/crud-room
nguyenhcp2004 Oct 4, 2024
e5581be
Merge pull request #54 from Hoang-Nguyen-Huy/PBS-54-Payment-Confirrm-…
nguyenhcp2004 Oct 4, 2024
9d3ebba
[PBS-62][NguyenHCP] feat: send google calendar invite
nguyenhcp2004 Oct 4, 2024
57a68fb
Merge pull request #55 from Hoang-Nguyen-Huy/feat/calendar
nguyenhcp2004 Oct 4, 2024
0d22e99
[PBS-40][HoangHN] fix: fix response for room
Hoang-Nguyen-Huy Oct 5, 2024
522b01a
Merge pull request #56 from Hoang-Nguyen-Huy/feature/PBS-36/crud-room
Hoang-Nguyen-Huy Oct 5, 2024
b29f571
[PBS-43][HuyNBQ] feat: calendar api
HuyDiCode Oct 5, 2024
aa35727
Merge branch 'develop' of https://github.com/Hoang-Nguyen-Huy/pod-boo…
HuyDiCode Oct 5, 2024
d3ed2ce
[PBS-43][HuyNBQ] feat: unavailable rooms api
HuyDiCode Oct 5, 2024
a3d843f
Merge pull request #57 from Hoang-Nguyen-Huy/PBS-43-View-Room-Detail
nguyenhcp2004 Oct 6, 2024
e4e3829
[NguyenHCP] feat: forgot password
nguyenhcp2004 Oct 6, 2024
f497a65
Merge pull request #58 from Hoang-Nguyen-Huy/feat/logout
nguyenhcp2004 Oct 6, 2024
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
1 change: 1 addition & 0 deletions .dccache

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ jobs:
echo "server:" >> src/main/resources/application.yaml
echo " port: 8080" >> src/main/resources/application.yaml
echo "" >> src/main/resources/application.yaml
echo "openapi:" >> src/main/resources/application.yaml
echo " service: " >> src/main/resources/application.yaml
echo " api-docs: api-service" >> src/main/resources/application.yaml
echo " server: \"${{ secrets.SERVER_API_URL }}\"" >> src/main/resources/application.yaml
echo " title: API Service" >> src/main/resources/application.yaml
echo " version: 1.0.0" >> src/main/resources/application.yaml
echo "spring:" >> src/main/resources/application.yaml
echo " datasource:" >> src/main/resources/application.yaml
echo " url: \"${{ secrets.DATABASE_URL }}\"" >> src/main/resources/application.yaml
Expand Down
14 changes: 12 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<version>3.3.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.swp</groupId>
Expand All @@ -28,7 +28,7 @@
</scm>
<properties>
<java.version>21</java.version>
<projectlombok-lombok.version>1.18.30</projectlombok-lombok.version>
<projectlombok-lombok.version>1.18.34</projectlombok-lombok.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
</properties>
Expand Down Expand Up @@ -89,6 +89,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>net.sf.biweekly</groupId>
<artifactId>biweekly</artifactId>
<version>0.6.8</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.swp.PodBookingSystem.configuration;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class OpenAPIConfig {

@Bean
public GroupedOpenApi publicApi(@Value("${openapi.service.api-docs}") String apiDocs) {
return GroupedOpenApi.builder()
.group(apiDocs) // /v3/api-docs/api-service
.packagesToScan("com.swp.PodBookingSystem.controller")
.build();
}

@Bean
public OpenAPI openAPI(
@Value("${openapi.service.title}") String title,
@Value("${openapi.service.version}") String version,
@Value("${openapi.service.server}") String serverUrl) {
return new OpenAPI()
.servers(List.of(new Server().url(serverUrl)))
.info(new Info().title(title)
.description("API documents")
.version(version)
.license(new License().name("Apache 2.0").url("https://springdoc.org")))
.components(
new Components()
.addSecuritySchemes("bearerAuth",
new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")))
.security(List.of(new SecurityRequirement().addList("bearerAuth")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
private final String[] PUBLIC_ENDPOINTS = {"/accounts",
private final String[] PUBLIC_ENDPOINTS = {"/accounts", "/accounts/me",
"/auth/login", "/auth/introspect", "/auth/refresh-token", "/auth/logout", "/auth/login/google"
};

Expand All @@ -45,8 +45,8 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.
authorizeHttpRequests(request ->
request.requestMatchers(HttpMethod.POST, PUBLIC_ENDPOINTS).permitAll()
.anyRequest().authenticated())
request.requestMatchers(PUBLIC_ENDPOINTS).permitAll()
.anyRequest().permitAll())
.oauth2Login(oauth2login -> oauth2login.loginPage("http://localhost:3000/login")
.successHandler(((request, response, authentication) ->
response.sendRedirect("/auth/login/google"))))
Expand Down Expand Up @@ -104,4 +104,4 @@ JwtDecoder jwtDecoder() {
.macAlgorithm(MacAlgorithm.HS512)
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
package com.swp.PodBookingSystem.controller;

import com.swp.PodBookingSystem.dto.request.Account.AccountCreationRequest;
import com.swp.PodBookingSystem.dto.request.Account.AccountResponseClient;
import com.swp.PodBookingSystem.dto.request.Account.GetMeRequest;
import com.swp.PodBookingSystem.dto.request.CalendarRequest;
import com.swp.PodBookingSystem.dto.respone.ApiResponse;
import com.swp.PodBookingSystem.dto.respone.AccountResponse;
import com.swp.PodBookingSystem.entity.Account;
import com.swp.PodBookingSystem.mapper.AccountMapper;
import com.swp.PodBookingSystem.service.AccountService;
import com.swp.PodBookingSystem.service.SendEmailService;
import jakarta.mail.MessagingException;
import jakarta.validation.Valid;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;

@RestController
Expand All @@ -22,6 +32,8 @@
@Slf4j
public class AccountController {
AccountService accountService;
AccountMapper accountMapper;
SendEmailService sendEmailService;

@PostMapping
ApiResponse<AccountResponse> createAccount(@RequestBody @Valid AccountCreationRequest request) {
Expand All @@ -33,10 +45,39 @@ ApiResponse<AccountResponse> createAccount(@RequestBody @Valid AccountCreationRe
@GetMapping
ApiResponse<List<Account>> getAccounts() {
var authentication = SecurityContextHolder.getContext().getAuthentication();
log.info("Username: {}", authentication.getName());
authentication.getAuthorities().forEach(grantedAuthority -> log.info(grantedAuthority.getAuthority()));
return ApiResponse.<List<Account>>builder()
.data(accountService.getAccounts())
.build();
}

@GetMapping("/{id}")
ApiResponse<AccountResponseClient> getAccountById(@PathVariable("id") String id) {
return ApiResponse.<AccountResponseClient>builder()
.data(accountMapper.toAccountResponseClient(accountService.getAccountById(id)))
.message("Thành cong ")
.build();
}

@GetMapping("/me")
ApiResponse<AccountResponseClient> getMe(@AuthenticationPrincipal Jwt jwt) {
var result = accountService.getAccountById("d6b9469e-978f-4f84-b2bb-5910c6240deb");
return ApiResponse.<AccountResponseClient>builder()
.data(accountMapper.toAccountResponseClient(result))
.message("Lấy thông tin cá nhân thành công")
.code(200)
.build();
}

// @GetMapping("/send-email")
// public String sendEmail() throws MessagingException, IOException {
// sendEmailService.sendCalenderInvite(
// CalendarRequest.builder()
// .subject("test")
// .description("test")
// .summary("test")
// .to("[email protected]")
// .eventDateTime(LocalDateTime.now()).build());
// return "Send email successfully";
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

import com.swp.PodBookingSystem.dto.respone.RefreshTokenResponse;
import com.swp.PodBookingSystem.service.AuthenticationService;
import jakarta.servlet.http.HttpServletResponse;
import com.swp.PodBookingSystem.service.SendEmailService;
import jakarta.mail.MessagingException;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
Expand All @@ -22,7 +23,7 @@
import org.springframework.web.servlet.view.RedirectView;

import java.text.ParseException;
import java.util.Map;


@RestController
@RequestMapping("/auth")
Expand All @@ -31,6 +32,7 @@
@Slf4j
public class AuthenticationController {
AuthenticationService authenticationService;
SendEmailService sendEmailService;

@GetMapping("/login/google")
public RedirectView loginGoogle(OAuth2AuthenticationToken token) throws ParseException {
Expand Down Expand Up @@ -77,7 +79,8 @@ ApiResponse logout(@RequestBody LogoutRequest request)
}

@PostMapping("/forgot-password")
ApiResponse forgotPassword(@RequestBody ForgotPasswordRequest request) {
ApiResponse forgotPassword(@RequestBody ForgotPasswordRequest request) throws MessagingException {
authenticationService.forgotPassword(request);
return ApiResponse.builder()
.message("Gửi mail xác nhận thành công")
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.swp.PodBookingSystem.controller;

import com.swp.PodBookingSystem.dto.request.Payment.PaymentReqDTO;
import com.swp.PodBookingSystem.dto.respone.Payment.PaymentResDTO;
import com.swp.PodBookingSystem.dto.respone.Payment.TransactionStatusDTO;
import com.swp.PodBookingSystem.service.PaymentService;
Expand All @@ -20,9 +19,10 @@ public class PaymentController {
private PaymentService paymentService;

@GetMapping("/url")
public ResponseEntity<?> generatePaymentUrl(@Valid @RequestBody PaymentReqDTO paymentRequestDTO, HttpServletRequest request) {
public ResponseEntity<?> generatePaymentUrl( @RequestParam("amount") long amount,
@RequestParam("orderId") String orderId, HttpServletRequest request) {
String clientIp = request.getRemoteAddr();
PaymentResDTO paymentResDTO = paymentService.generatePaymentUrl(paymentRequestDTO.getAmount(), paymentRequestDTO.getOrderId(), clientIp);
PaymentResDTO paymentResDTO = paymentService.generatePaymentUrl(amount, orderId, clientIp);
return ResponseEntity.status(HttpStatus.OK).body(paymentResDTO);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.swp.PodBookingSystem.controller;

import com.swp.PodBookingSystem.dto.request.Room.RoomAvailabilityDTO;
import com.swp.PodBookingSystem.dto.request.Slot.SlotCreationRequest;
import com.swp.PodBookingSystem.dto.respone.ApiResponse;
import com.swp.PodBookingSystem.dto.request.Room.RoomCreationRequest;
import com.swp.PodBookingSystem.dto.request.Room.RoomPaginationDTO;
import com.swp.PodBookingSystem.dto.respone.Calendar.DateResponse;
import com.swp.PodBookingSystem.dto.respone.PaginationResponse;
import com.swp.PodBookingSystem.dto.respone.Room.RoomResponse;
import com.swp.PodBookingSystem.entity.Room;
import com.swp.PodBookingSystem.service.OrderDetailService;
import com.swp.PodBookingSystem.service.RoomService;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,7 +18,9 @@
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -64,6 +70,46 @@ PaginationResponse<List<Room>> getFilteredRoom(@RequestParam(required = false) S
.build();
}

@GetMapping("/available-rooms")
ApiResponse<List<Room>> getAvailableRoomsByRoomTypeId(@RequestParam Integer typeId,
@RequestParam(required = false) List<String> slots) {
List<SlotCreationRequest> slotList = new ArrayList<>();
if(slots!=null) {
for(String slot: slots) {
String[] parts = slot.split("_");
LocalDateTime startTime = LocalDateTime.parse(parts[0]);
LocalDateTime endTime = LocalDateTime.parse(parts[1]);
slotList.add(new SlotCreationRequest(startTime,endTime));
}
}
return ApiResponse.<List<Room>>builder()
.data(roomService.getRoomByTypeAndSlot(typeId,slotList))
.message("Get rooms by typeId and slots successfully")
.build();
}

@GetMapping("/calendar")
ApiResponse<List<DateResponse>> getCalendar(@RequestParam List<Integer> roomIds,
@RequestParam(required = false) Integer servicePackageId,
@RequestParam LocalDate selectedDate,
@RequestParam List<String> slots
) {
return ApiResponse.<List<DateResponse>>builder()
.data(roomService.getCalendar(roomIds,servicePackageId,selectedDate,slots))
.message("Get calendar successfully")
.build();
}

@GetMapping("/unavailable")
ApiResponse<List<RoomAvailabilityDTO>> getUnavailableRooms(@RequestParam LocalDateTime startTime,
@RequestParam LocalDateTime endTime
) {
return ApiResponse.<List<RoomAvailabilityDTO>>builder()
.data(roomService.getUnavailableRooms(startTime,endTime))
.message("Get unavailable rooms successfully")
.build();
}

@GetMapping("/{roomId}")
ApiResponse<Optional<RoomResponse>> getRoomById(@PathVariable("roomId") int roomId) {
return ApiResponse.<Optional<RoomResponse>>builder().data(roomService.getRoomById(roomId)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class RoomTypeController {
RoomTypeService roomTypeService;

@PostMapping
ApiResponse<RoomTypeResponse> createRoomType(@RequestBody RoomTypeCreationRequest request) {
return ApiResponse.<RoomTypeResponse>builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.swp.PodBookingSystem.controller;

import com.swp.PodBookingSystem.dto.respone.ApiResponse;
import com.swp.PodBookingSystem.dto.respone.ServicePackage.ServicePackageResponse;
import com.swp.PodBookingSystem.entity.Account;
import com.swp.PodBookingSystem.entity.ServicePackage;
import com.swp.PodBookingSystem.service.ServicePackageService;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/service-package")
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class ServicePackageController {
@Autowired
ServicePackageService servicePackageService;

@GetMapping
ApiResponse<List<ServicePackage>> getServicePackages(){
return ApiResponse.<List<ServicePackage>>builder()
.data(servicePackageService.findAll())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.swp.PodBookingSystem.dto.request.Account;

import lombok.*;
import lombok.experimental.FieldDefaults;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@FieldDefaults(level = AccessLevel.PRIVATE)
public class GetMeRequest {
String id;
}
Loading