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
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,18 @@ private void validateOwner(Transporter transporter) {
throw new GlobalException(ResultCode.FORBIDDEN);
}
}

/**
* 노출 범위 토글 (자사 <-> 통합)
* @return 변경된 상태값
*/
public CallType toggleExposure() {
if (this.call == CallType.INTERNAL) {
this.call = CallType.INTEGRATED;
} else {
this.call = CallType.INTERNAL;
}
return this.call;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.mobility.api.domain.office.controller;

import com.mobility.api.domain.office.dto.request.ManagerStatusUpdateReq;
import com.mobility.api.domain.office.dto.response.ManagerRes;
import com.mobility.api.domain.office.service.OfficeManagerService;
import com.mobility.api.global.response.CommonResponse;
import com.mobility.api.global.security.PrincipalDetails;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@Tag(name = "사무실 - 직원 관련 요청(/api/v1/office/employee/**)")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/office/employee")
public class OfficeManagerV1Controller {

// 새로 분리한 서비스 주입
private final OfficeManagerService officeManagerService;

/**
* <pre>
* 직원 리스트 조회
* </pre>
* @param user 로그인한 관리자
* @param page 페이지 번호 (0부터)
* @param size 페이지 크기
* @return
*/
@Operation(summary = "직원 리스트 조회", description = "사무실에 소속된 직원(Manager) 목록을 조회합니다.")
@GetMapping("")
public CommonResponse<Page<ManagerRes>> getManagers(
@AuthenticationPrincipal PrincipalDetails user,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size
) {
// 최신순 or 이름순 정렬
Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending());

Page<ManagerRes> result = officeManagerService.getManagers(user.getManager(), pageable);

return CommonResponse.success(result);
}

/**
* <pre>
* 직원 상태 변경 (활성/비활성/대기)
* </pre>
* @param managerId 변경할 직원 ID
* @param req 변경할 상태값 (ACTIVE, INACTIVE, PENDING)
* @param user 요청하는 관리자 (OWNER 여야 함)
*/
@Operation(summary = "직원 상태 변경", description = "직원의 상태를 변경합니다. (예: 승인 대기 -> 활성, 활성 -> 비활성). **OWNER 권한**만 가능합니다.")
@PatchMapping("/{managerId}/status")
public CommonResponse<String> updateManagerStatus(
@PathVariable Long managerId,
@RequestBody @Valid ManagerStatusUpdateReq req,
@AuthenticationPrincipal PrincipalDetails user
) {
officeManagerService.updateManagerStatus(
managerId,
req.status(),
user.getManager()
);

return CommonResponse.success("직원 상태가 변경되었습니다.");
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mobility.api.domain.office.controller;

import com.mobility.api.domain.dispatch.entity.Dispatch;
import com.mobility.api.domain.office.dto.request.CancelDispatchReq;
import com.mobility.api.domain.office.dto.request.CreateDispatchReq;
import com.mobility.api.domain.office.dto.request.DispatchSearchDto;
import com.mobility.api.domain.office.dto.request.UpdateDispatchReq;
Expand All @@ -23,7 +24,9 @@
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -168,9 +171,11 @@ public CommonResponse<List<DispatchFeedRes>> getDispatchFeed(
@Operation(summary = "배차 등록", description = "")
@RequestMapping(path = "/dispatch", method = RequestMethod.POST)
public CommonResponse<Object> createDispatch(
@AuthenticationPrincipal PrincipalDetails user,
@Valid @RequestBody CreateDispatchReq createDispatchReq
) {
officeService.saveDispatch(createDispatchReq);

officeService.saveDispatch(createDispatchReq, user.getManager());

return CommonResponse.success(null);
}
Expand All @@ -186,6 +191,7 @@ public CommonResponse<Object> createDispatch(
@Operation(summary = "배차 수정", description = "")
@RequestMapping(path = "/dispatch/{dispatch_id}", method = RequestMethod.PATCH)
public CommonResponse<Dispatch> updateDispatch(
@AuthenticationPrincipal PrincipalDetails user,
@PathVariable("dispatch_id") Long dispatchId,
@RequestBody UpdateDispatchReq updateDispatchReq
) {
Expand All @@ -203,9 +209,11 @@ public CommonResponse<Dispatch> updateDispatch(
@Operation(summary = "배차 취소 (삭제)", description = "")
@RequestMapping(path = "/dispatch-cancel/{dispatch_id}", method = RequestMethod.POST)
public CommonResponse<Object> cancelDispatch(
@PathVariable("dispatch_id") Long dispatchId
@AuthenticationPrincipal PrincipalDetails user,
@PathVariable("dispatch_id") Long dispatchId,
@RequestBody CancelDispatchReq req
) {
officeService.cancelDispatch(dispatchId);
officeService.cancelDispatch(dispatchId, req, user.getManager());
return CommonResponse.success(null); // FIXME return값 수정
}

Expand Down Expand Up @@ -253,11 +261,25 @@ public CommonResponse<String> createTransporter(
*/
@Operation(summary = "기사 리스트 조회", description = "")
@RequestMapping(path = "/transporter", method = RequestMethod.GET)
public CommonResponse<List<TransporterRes>> getMyTransporters(
@AuthenticationPrincipal PrincipalDetails user
public CommonResponse<Page<TransporterRes>> getMyTransporters(
@AuthenticationPrincipal PrincipalDetails user,
@RequestParam(required = false) String status, // 필터: 없을 수도 있음
@RequestParam(defaultValue = "0") int page, // 페이지: 안 보내면 0
@RequestParam(defaultValue = "20") int size // 크기: 안 보내면 20
) {

// 페이징 객체 생성 (최신순 정렬 예시: id 내림차순)
Pageable pageable = PageRequest.of(page, size, Sort.by("id").descending());

// userDetails.getUsername() -> 로그인한 관리자의 ID
List<TransporterRes> result = officeService.getMyTransporters(user.getManager());
// List<TransporterRes> result = officeService.getMyTransporters(user.getManager());

// 서비스 호출
Page<TransporterRes> result = officeService.getMyTransporters(
user.getManager(),
status,
pageable
);

return CommonResponse.success(result);
}
Expand All @@ -271,7 +293,7 @@ public CommonResponse<List<TransporterRes>> getMyTransporters(
*/
@Operation(summary = "기사 상태 변경", description = "")
@RequestMapping(path = "/transporter/{transporterId}/status", method = RequestMethod.PATCH)
public CommonResponse<Integer> changeTransporterStatus(
public CommonResponse<String> changeTransporterStatus(
@AuthenticationPrincipal PrincipalDetails user,
@PathVariable Long transporterId,
@RequestBody TransporterStatusUpdateReq req
Expand All @@ -283,7 +305,28 @@ public CommonResponse<Integer> changeTransporterStatus(
user.getManager()
);

return CommonResponse.success(0);
return CommonResponse.success("기사 상태 변경 성공");
}

/**
* <pre>
* 배차 노출범위 변경
* </pre>
* @param user
* @return
*/
@Operation(summary = "배차 노출범위 변경", description = "")
@RequestMapping(path = "/dispatch/{dispatchId}/exposure", method = RequestMethod.PATCH)
public CommonResponse<String> changeDispatchExposure(
@AuthenticationPrincipal PrincipalDetails user,
@PathVariable Long dispatchId
) {

// 서비스 호출 및 결과 받기
String changedStatus = officeService.changeDispatchExposure(dispatchId, user.getManager());

// 변경된 상태를 메시지나 데이터로 주면 프론트에서 UI 갱신하기 편함
return CommonResponse.success(changedStatus);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mobility.api.domain.office.dto.request;

public record CancelDispatchReq(
String cancelReason // 취소 사유
) {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.mobility.api.domain.office.dto.request;

import com.mobility.api.domain.dispatch.entity.Dispatch;
import com.mobility.api.domain.dispatch.enums.CallType;
import com.mobility.api.domain.dispatch.enums.ServiceType;
import com.mobility.api.domain.dispatch.enums.StatusType;
import com.mobility.api.domain.dispatch.enums.*;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down Expand Up @@ -46,20 +44,27 @@ public record CreateDispatchReq(
String clientPhoneNumber, // 고객 전화번호

// StatusType status, // 배차 상태
Long officeId, // FIXME 사무실 id, 토큰 등에서 받아오도록 변경해야 함
// CallType call, // 콜 타입

@Schema(description = "활성화 여부", example = "true")
Boolean active, // 활성화 여부

@Schema(description = "활성화 여부", example = "DELIVERY")
@Schema(description = "서비스 타입", example = "DELIVERY")
ServiceType service, // 탁송 / 대리

LocalDateTime createdAt // 생성 시간
@Schema(description = "배차 번호", example = "2024-0001")
String dispatchNumber, // 배차 번호

@Schema(description = "메모", example = "memo")
String memo, // 메모

@Schema(description = "결제 방식", example = "CASH")
PaymentType paymentType, // 결제 방식 (현금 / 후불 / 완후)

@Schema(description = "톨비 방식", example = "HIPASS")
TollType tollType // 톨비 방식 (톨포 / 톨별 / 하이패스)

) {
public CreateDispatchReq {
officeId = 1L; // FIXME 임시로 사무실 id는 1로 고정
}

public Dispatch toEntity() {
return Dispatch.builder()
Expand All @@ -72,10 +77,13 @@ public Dispatch toEntity() {
.charge(this.charge())
.clientPhoneNumber(this.clientPhoneNumber())
.status(StatusType.OPEN)
.officeId(this.officeId())
.call(CallType.INTERNAL)
.active(this.active())
.service(this.service())
.dispatchNumber(this.dispatchNumber)
.memo(this.memo)
.paymentType(this.paymentType)
.tollType(this.tollType)
.createdAt(LocalDateTime.now())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mobility.api.domain.office.dto.request;

import com.mobility.api.domain.office.enums.ManagerStatus;
import jakarta.validation.constraints.NotNull;

public record ManagerStatusUpdateReq(
@NotNull(message = "변경할 상태값은 필수입니다.")
ManagerStatus status
) {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.mobility.api.domain.office.dto.request;

import com.mobility.api.domain.dispatch.enums.CallType;
import com.mobility.api.domain.dispatch.enums.ServiceType;
import com.mobility.api.domain.dispatch.enums.StatusType;
import com.mobility.api.domain.dispatch.enums.*;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "배차 수정 request 객체")
Expand Down Expand Up @@ -42,6 +40,19 @@ public record UpdateDispatchReq(
Boolean active,

@Schema(description = "서비스 타입", example = "DELIVERY")
ServiceType service
) {
ServiceType service,

@Schema(description = "배차 번호", example = "2024-0001")
String dispatchNumber,

@Schema(description = "메모", example = "memo")
String memo,

@Schema(description = "결제 방식", example = "CASH")
PaymentType paymentType,

@Schema(description = "톨비 방식", example = "HIPASS")
TollType tollType

) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mobility.api.domain.office.dto.response;

import com.mobility.api.domain.office.entity.Manager;
import lombok.Builder;

@Builder
public record ManagerRes(
Long id,
String loginId,
String name,
String phone,
String email,
String role, // "OWNER", "STAFF" 등 권한 정보
String status,
String createdAt
) {
public static ManagerRes from(Manager manager) {
return ManagerRes.builder()
.id(manager.getId())
.loginId(manager.getLoginId())
.name(manager.getName())
.phone(manager.getPhone())
.email(manager.getEmail())
.role(manager.getRole().name())
.status(manager.getStatus().name())
.createdAt(manager.getCreatedAt().toString())
.build();
}
}
Loading