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 @@ -9,7 +9,7 @@
@Data
@Builder
@AllArgsConstructor
public class DepartmentsCardDto {
public class DepartmentCardDo {
private BigInteger id;
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import com.gltkorea.icebang.common.dto.ApiResponse;
import com.gltkorea.icebang.domain.organization.dto.OrganizationCardDto;
import com.gltkorea.icebang.domain.organization.dto.OrganizationOptionsDto;
import com.gltkorea.icebang.domain.organization.dto.OrganizationOptionDto;
import com.gltkorea.icebang.domain.organization.service.OrganizationService;

import lombok.RequiredArgsConstructor;
Expand All @@ -28,7 +28,7 @@ public ResponseEntity<ApiResponse<List<OrganizationCardDto>>> getOrganizations()
}

@GetMapping("/{id}/options")
public ResponseEntity<ApiResponse<OrganizationOptionsDto>> getOrganizationDetails(
public ResponseEntity<ApiResponse<OrganizationOptionDto>> getOrganizationDetails(
@PathVariable BigInteger id) {
return ResponseEntity.ok(ApiResponse.success(organizationService.getOrganizationOptions(id)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.util.List;

import com.gltkorea.icebang.domain.department.dto.DepartmentsCardDto;
import com.gltkorea.icebang.domain.department.dto.DepartmentCardDo;
import com.gltkorea.icebang.domain.position.dto.PositionCardDto;
import com.gltkorea.icebang.domain.roles.dto.RolesCardDto;
import com.gltkorea.icebang.domain.roles.dto.RoleCardDto;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -13,8 +13,8 @@
@Builder
@Data
@AllArgsConstructor
public class OrganizationOptionsDto {
List<DepartmentsCardDto> departments;
public class OrganizationOptionDto {
List<DepartmentCardDo> departments;
List<PositionCardDto> positions;
List<RolesCardDto> roles;
List<RoleCardDto> roles;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gltkorea.icebang.domain.department.dto.DepartmentsCardDto;
import com.gltkorea.icebang.domain.department.dto.DepartmentCardDo;
import com.gltkorea.icebang.domain.organization.dto.OrganizationCardDto;
import com.gltkorea.icebang.domain.organization.dto.OrganizationOptionsDto;
import com.gltkorea.icebang.domain.organization.dto.OrganizationOptionDto;
import com.gltkorea.icebang.domain.position.dto.PositionCardDto;
import com.gltkorea.icebang.domain.roles.dto.RolesCardDto;
import com.gltkorea.icebang.domain.roles.dto.RoleCardDto;
import com.gltkorea.icebang.mapper.OrganizationMapper;

import lombok.RequiredArgsConstructor;
Expand All @@ -25,12 +25,12 @@ public List<OrganizationCardDto> getAllOrganizationList() {
return organizationMapper.findAllOrganizations();
}

public OrganizationOptionsDto getOrganizationOptions(BigInteger id) {
List<DepartmentsCardDto> departments = organizationMapper.findDepartmentsByOrganizationId(id);
public OrganizationOptionDto getOrganizationOptions(BigInteger id) {
List<DepartmentCardDo> departments = organizationMapper.findDepartmentsByOrganizationId(id);
List<PositionCardDto> positions = organizationMapper.findPositionsByOrganizationId(id);
List<RolesCardDto> roles = organizationMapper.findRolesByOrganizationId(id);
List<RoleCardDto> roles = organizationMapper.findRolesByOrganizationId(id);

return OrganizationOptionsDto.builder()
return OrganizationOptionDto.builder()
.departments(departments)
.positions(positions)
.roles(roles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RolesCardDto {
public class RoleCardDto {
private BigInteger id;
private String name;
private String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import com.gltkorea.icebang.domain.department.dto.DepartmentsCardDto;
import com.gltkorea.icebang.domain.department.dto.DepartmentCardDo;
import com.gltkorea.icebang.domain.organization.dto.OrganizationCardDto;
import com.gltkorea.icebang.domain.position.dto.PositionCardDto;
import com.gltkorea.icebang.domain.roles.dto.RolesCardDto;
import com.gltkorea.icebang.domain.roles.dto.RoleCardDto;

@Mapper
public interface OrganizationMapper {
List<OrganizationCardDto> findAllOrganizations();

List<DepartmentsCardDto> findDepartmentsByOrganizationId(
List<DepartmentCardDo> findDepartmentsByOrganizationId(
@Param("organizationId") BigInteger organizationId);

List<PositionCardDto> findPositionsByOrganizationId(
@Param("organizationId") BigInteger organizationId);

List<RolesCardDto> findRolesByOrganizationId(@Param("organizationId") BigInteger organizationId);
List<RoleCardDto> findRolesByOrganizationId(@Param("organizationId") BigInteger organizationId);
}
4 changes: 3 additions & 1 deletion apps/user-service/src/main/resources/application-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ spring:
sql:
init:
mode: always
schema-locations: classpath:sql/schema.sql
schema-locations:
- classpath:sql/00-drop-maria.sql
- classpath:sql/01-schema.sql
data-locations:
- classpath:sql/00-truncate.sql
- classpath:sql/01-insert-internal-users.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ spring:
sql:
init:
mode: always
schema-locations: classpath:sql/schema.sql
schema-locations:
- classpath:sql/00-drop-maria.sql
- classpath:sql/01-schema.sql
encoding: UTF-8

mybatis:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ spring:
sql:
init:
mode: always
schema-locations: classpath:sql/schema.sql
schema-locations:
- classpath:sql/00-drop-h2.sql
- classpath:sql/01-schema.sql
encoding: UTF-8

mybatis:
Expand Down
16 changes: 6 additions & 10 deletions apps/user-service/src/main/resources/mybatis/mapper/AuthMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,30 @@

<mapper namespace="com.gltkorea.icebang.mapper.AuthMapper">

<!-- 이메일 중복 여부 확인 -->
<select id="existsByEmail" parameterType="string" resultType="boolean">
SELECT EXISTS(
SELECT 1
FROM users
FROM user
WHERE email = #{email}
)
</select>

<!-- 1. users INSERT & PK 반환 -->
<insert id="insertUser" parameterType="com.gltkorea.icebang.domain.auth.dto.RegisterDto" useGeneratedKeys="true" keyProperty="id">
INSERT INTO users (name, email, password)
INSERT INTO user (name, email, password)
VALUES (#{name}, #{email}, #{password});
</insert>

<!-- 2. user_organizations INSERT -->
<insert id="insertUserOrganization" parameterType="com.gltkorea.icebang.domain.auth.dto.RegisterDto" useGeneratedKeys="true" keyProperty="userOrgId">
INSERT INTO user_organizations (user_id, organization_id, department_id, position_id, status)
VALUES (#{id}, #{orgId}, #{deptId}, #{positionId}, #{status});
INSERT INTO user_organization (user_id, organization_id, department_id, position_id, status)
VALUES (#{id}, #{organizationId}, #{departmentId}, #{positionId}, #{status});
</insert>

<!-- 3. user_roles INSERT (foreach) -->
<insert id="insertUserRoles" parameterType="com.gltkorea.icebang.domain.auth.dto.RegisterDto">
INSERT INTO user_roles (user_organization_id, role_id)
INSERT INTO user_role (user_organization_id, role_id)
VALUES
<foreach collection="roleIds" item="roleId" separator=",">
(#{userOrgId}, #{roleId})
</foreach>
</insert>

</mapper>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</select>

<select id="findDepartmentsByOrganizationId"
resultType="com.gltkorea.icebang.domain.department.dto.DepartmentsCardDto">
resultType="com.gltkorea.icebang.domain.department.dto.DepartmentCardDo">
SELECT
id,
name
Expand All @@ -34,7 +34,7 @@
</select>

<select id="findRolesByOrganizationId"
resultType="com.gltkorea.icebang.domain.roles.dto.RolesCardDto">
resultType="com.gltkorea.icebang.domain.roles.dto.RoleCardDto">
SELECT
id,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
cron_expression AS cronExpression,
is_active AS isActive
FROM
schedules
schedule
WHERE
is_active = #{isActive}
</select>
Expand Down
6 changes: 6 additions & 0 deletions apps/user-service/src/main/resources/sql/00-drop-h2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SET FOREIGN_KEY_CHECKS = 0;

-- H2에서 모든 테이블과 객체를 삭제하는 올바른 구문
DROP ALL OBJECTS;

SET FOREIGN_KEY_CHECKS = 1;
18 changes: 18 additions & 0 deletions apps/user-service/src/main/resources/sql/00-drop-maria.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SET FOREIGN_KEY_CHECKS = 0;
SET @tables = NULL;

-- 1. 데이터베이스 내 모든 테이블 목록을 가져와 변수에 저장
-- 백틱(`)을 사용하여 테이블 이름에 공백이나 특수 문자가 있어도 안전하게 처리합니다.
SELECT GROUP_CONCAT(CONCAT('`', table_name, '`')) INTO @tables
FROM information_schema.tables
WHERE table_schema = DATABASE();

-- 2. 변수 값이 NULL인 경우를 대비하여 조건문 추가 및 DROP TABLE 구문 생성
SET @drop_tables_sql = IFNULL(CONCAT('DROP TABLE ', @tables), 'SELECT "No tables to drop";');

-- 3. 동적 SQL 실행
PREPARE stmt FROM @drop_tables_sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET FOREIGN_KEY_CHECKS = 1;
25 changes: 11 additions & 14 deletions apps/user-service/src/main/resources/sql/00-truncate.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
-- 데이터 초기화 전에 추가
SET FOREIGN_KEY_CHECKS = 0;
-- 데이터 초기화 스크립트 (외래 키 제약조건이 없는 스키마용)

-- 역순으로 TRUNCATE (참조되는 테이블을 나중에)
TRUNCATE TABLE user_roles;
TRUNCATE TABLE role_permissions;
TRUNCATE TABLE user_organizations;
TRUNCATE TABLE users;
TRUNCATE TABLE positions;
TRUNCATE TABLE departments;
TRUNCATE TABLE roles;
TRUNCATE TABLE permissions;
TRUNCATE TABLE organizations;

SET FOREIGN_KEY_CHECKS = 1;
-- 사용자 및 조직 관련 테이블
TRUNCATE TABLE `user_role`;
TRUNCATE TABLE `role_permission`;
TRUNCATE TABLE `user_organization`;
TRUNCATE TABLE `user`;
TRUNCATE TABLE `position`;
TRUNCATE TABLE `department`;
TRUNCATE TABLE `role`;
TRUNCATE TABLE `permission`;
TRUNCATE TABLE `organization`;
Loading
Loading