Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Deploy

on:
push:
branches: [ main ]

permissions:
id-token: write
contents: read
packages: write
actions: write

jobs:
deploy:
uses: Management-System-for-Rental-SEP490/.github/.github/workflows/deploy-java-service.yml@main
with:
service_name: schedule-service
xmx: 512m
secrets:
GH_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.isums.scheduleservice.domains.dtos.*;
import com.isums.scheduleservice.infrastructures.abstracts.WorkSlotService;
import com.isums.scheduleservice.infrastructures.grpcs.UserClientsGrpc;
import com.isums.userservice.grpc.UserResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import java.util.UUID;

Expand All @@ -16,6 +19,7 @@
@RequiredArgsConstructor
public class WorkSlotController {
private final WorkSlotService workSlotService;
private final UserClientsGrpc userClientsGrpc;

@PostMapping("/manual")
public ApiResponse<WorkSlotDto> manualAssign(@RequestBody ManualAssignRequest request) {
Expand Down Expand Up @@ -70,11 +74,23 @@ public ApiResponse<List<WorkSlotDto>> getSlotsByRange(@RequestParam LocalDate st
return ApiResponses.ok(res, "Get slots successfully");
}

@GetMapping("/generate")
public ApiResponse<List<DaySlotDto>> generateSlots(@RequestParam LocalDate start, @RequestParam LocalDate end) {
List<DaySlotDto> res = workSlotService.generateSlots(start,end);
return ApiResponses.ok(res,"Generate successfully");
@GetMapping("/slots")
public ApiResponse<List<DaySlotDto>> getSlots(@RequestParam UUID jobId, @RequestParam LocalDate date) {
List<DaySlotDto> res = workSlotService.getSlotsByDate(jobId, date);
return ApiResponses.ok(res, "Get slots successfully");
}

@GetMapping("/slots/staff")
public ApiResponse<List<UUID>> getAvailableStaff(@RequestParam UUID jobId, @RequestParam LocalDate date, @RequestParam LocalTime startTime) {
List<UUID> res = workSlotService.getAvailableStaff(jobId, date, startTime);
return ApiResponses.ok(res, "Get available staff");
}

@GetMapping("/slots/me")
public ApiResponse<List<DaySlotDto>> getMySlots(@AuthenticationPrincipal Jwt jwt, @RequestParam LocalDate startDate, @RequestParam LocalDate endDate) {
UserResponse user = userClientsGrpc.getUserIdAndRoleByKeyCloakId(jwt.getSubject());
List<DaySlotDto> res = workSlotService.getMyAvailableSlotsRange(user.getId(),startDate,endDate);
return ApiResponses.ok(res, "Get my slots");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
public record SlotsAvailableDto(
LocalTime startTime,
LocalTime endTime,
String status
String status,
int availableStaffCount
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.isums.scheduleservice.exceptions;

public class BadRequestException extends RuntimeException {
public BadRequestException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.isums.scheduleservice.infrastructures.abstracts;

import com.isums.scheduleservice.domains.events.JobEvent;

public interface AutoAssignStrategy {
boolean supports(String referenceType);
void handle(JobEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import com.isums.scheduleservice.domains.events.SlotEvent;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import java.util.UUID;

public interface WorkSlotService {
//WorkSlotDto createSlots(CreateWorkSlotRequest req);
WorkSlotDto manualAssign(ManualAssignRequest req);
WorkSlotDto confirmSlot(ConfirmSlotRequest req);
WorkSlotDto staffConfirmTime(ConfirmSlotRequest req);
Expand All @@ -19,7 +19,8 @@ public interface WorkSlotService {
WorkSlotDto getSlotById(UUID workSlotId);
WorkSlotDto rescheduleSlot(RescheduleSlotRequest request);
List<WorkSlotDto> getSlotsByRange(LocalDate start,LocalDate end);
List<DaySlotDto> generateSlots(LocalDate start, LocalDate end);
void markSlotDone(JobEvent event);
void handleAutoAssign(JobEvent event);
List<DaySlotDto> getSlotsByDate(UUID jobId, LocalDate date);
List<UUID> getAvailableStaff(UUID jobId, LocalDate date, LocalTime startTime);
List<DaySlotDto> getMyAvailableSlotsRange(String staffId, LocalDate start, LocalDate end);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.isums.scheduleservice.infrastructures.grpcs;

import com.isums.maintenanceservice.grpc.GetJobRequest;
import com.isums.maintenanceservice.grpc.GetJobResponse;
import com.isums.maintenanceservice.grpc.MaintenanceServiceGrpc;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
@RequiredArgsConstructor
public class MaintenanceClientsGrpc {
private final MaintenanceServiceGrpc.MaintenanceServiceBlockingStub stub;

public UUID getHouseByJobId(UUID jobId){
try{
GetJobRequest req = GetJobRequest.newBuilder().setJobId(jobId.toString()).build();
GetJobResponse res = stub.getHouseByJobId(req);
return UUID.fromString(res.getHouseId());
} catch (Exception ex) {
throw new RuntimeException("Failed to get houseId for jobId: " + jobId, ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.isums.scheduleservice.domains.events.JobEvent;
import com.isums.scheduleservice.domains.enums.JobAction;
import com.isums.scheduleservice.infrastructures.abstracts.AutoAssignStrategy;
import com.isums.scheduleservice.infrastructures.abstracts.WorkSlotService;
import com.isums.scheduleservice.services.AutoAssignStrategy.AutoAssignStrategyFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
Expand All @@ -18,6 +20,7 @@ public class JobEventListener {

private final WorkSlotService workSlotService;
private final ObjectMapper objectMapper;
private final AutoAssignStrategyFactory factory;

@KafkaListener(topics = "job.created", groupId = "schedule-group")
public void handleCreated(ConsumerRecord<String, String> record, Acknowledgment ack) {
Expand All @@ -29,7 +32,8 @@ public void handleCreated(ConsumerRecord<String, String> record, Acknowledgment
return;
}

workSlotService.handleAutoAssign(event);
AutoAssignStrategy strategy = factory.getStrategy(event.getReferenceType());
strategy.handle(event);

ack.acknowledge();

Expand Down
Loading
Loading