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
@@ -0,0 +1,34 @@
package DGU_AI_LAB.admin_be.domain.groups.controller;

import DGU_AI_LAB.admin_be.domain.groups.dto.response.GroupResponseDTO;
import DGU_AI_LAB.admin_be.domain.groups.service.GroupService;
import DGU_AI_LAB.admin_be.global.common.SuccessResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
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;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/groups")
public class GroupController {

private final GroupService groupService;

/**
* 모든 그룹 정보 조회 API
* GET /api/groups
*
* 그룹 ID와 그룹명을 반환합니다.
*/
@GetMapping("")
public ResponseEntity<SuccessResponse<?>> getGroups() {
List<GroupResponseDTO> groups = groupService.getAllGroups();
return SuccessResponse.ok(groups);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package DGU_AI_LAB.admin_be.domain.groups.dto.response;

import DGU_AI_LAB.admin_be.domain.groups.entity.Group;
import lombok.Builder;

@Builder
public record GroupResponseDTO(
Long ubuntuGid,
String groupName
) {
public static GroupResponseDTO fromEntity(Group group) {
return GroupResponseDTO.builder()
.ubuntuGid(group.getUbuntuGid())
.groupName(group.getGroupName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package DGU_AI_LAB.admin_be.domain.groups.service;

import DGU_AI_LAB.admin_be.domain.groups.dto.response.GroupResponseDTO;
import DGU_AI_LAB.admin_be.domain.groups.repository.GroupRepository;
import DGU_AI_LAB.admin_be.error.ErrorCode;
import DGU_AI_LAB.admin_be.error.exception.BusinessException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class GroupService {

private final GroupRepository groupRepository;

/**
* 모든 그룹 정보를 조회하는 API
* GET /api/groups
*/
public List<GroupResponseDTO> getAllGroups() {
log.info("[getAllGroups] 모든 그룹 정보 조회 시작");
var groups = groupRepository.findAll();

if (groups.isEmpty()) {
log.warn("[getAllGroups] 조회된 그룹 정보가 없습니다.");
throw new BusinessException(ErrorCode.NO_AVAILABLE_GROUPS);
}

var response = groups.stream()
.map(GroupResponseDTO::fromEntity)
.toList();

log.info("[getAllGroups] 모든 그룹 정보 조회 완료. {}개 그룹", response.size());
return response;
}
}
5 changes: 5 additions & 0 deletions src/main/java/DGU_AI_LAB/admin_be/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public enum ErrorCode {
INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "현재 비밀번호가 일치하지 않습니다."),
PASSWORD_CHANGE_SAME_AS_OLD(HttpStatus.BAD_REQUEST, "새 비밀번호가 현재 비밀번호와 동일합니다."),

/**
* Group Error
*/
NO_AVAILABLE_GROUPS(HttpStatus.NOT_FOUND, "존재하는 그룹 정보가 없습니다."),


/**
* Approval Error
Expand Down