Merge pull request 'feature/admin' (#7) from feature/admin into main
Reviewed-on: #7
This commit is contained in:
commit
c0ce7de761
|
|
@ -1,24 +0,0 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.BaseEntity;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Entity
|
|
||||||
@Table(name = "administrator_role")
|
|
||||||
public class AdministratorRole extends BaseEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
|
||||||
@JoinColumn(name = "administrator_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
|
||||||
private Administrator administrator;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
|
||||||
@JoinColumn(name = "role_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
|
||||||
private Role role;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.BaseEntity;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Entity
|
|
||||||
@Table(name = "menu")
|
|
||||||
public class Menu extends BaseEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(name = "uri", length = 100, nullable = false)
|
|
||||||
private String uri;
|
|
||||||
|
|
||||||
@Column(name = "name", length = 100, nullable = false)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Column(name = "sort_order", nullable = false)
|
|
||||||
private Integer sortOrder;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
|
||||||
@JoinColumn(name = "menu_group_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
|
||||||
private MenuGroup menuGroup;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.BaseEntity;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Entity
|
|
||||||
@Table(name = "menu_group")
|
|
||||||
public class MenuGroup extends BaseEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(name = "uri", length = 100, nullable = false)
|
|
||||||
private String uri;
|
|
||||||
|
|
||||||
@Column(name = "name", length = 100, nullable = false)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Column(name = "sort_order", nullable = false)
|
|
||||||
private Integer sortOrder;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.BaseEntity;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Entity
|
|
||||||
@Table(name = "role_menu")
|
|
||||||
public class RoleMenu extends BaseEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
|
||||||
@JoinColumn(name = "role_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
|
||||||
private Role role;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
|
||||||
@JoinColumn(name = "menu_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
|
||||||
private Menu menu;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bpgroup.poc.admin.domain;
|
package com.bpgroup.poc.admin.domain.entity;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.EntityListeners;
|
import jakarta.persistence.EntityListeners;
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
package com.bpgroup.poc.admin.domain.entity.administrator;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.BaseEntity;
|
import com.bpgroup.poc.admin.domain.entity.BaseEntity;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -26,7 +26,7 @@ public class Administrator extends BaseEntity {
|
||||||
@Column(name = "name", length = 100, nullable = false)
|
@Column(name = "name", length = 100, nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@OneToOne(mappedBy = "administrator", fetch = FetchType.LAZY)
|
@Embedded
|
||||||
private AdministratorRole administratorRole;
|
private AdministratorRole administratorRole;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
|
|
@ -43,6 +43,10 @@ public class Administrator extends BaseEntity {
|
||||||
this.password = administrator.password;
|
this.password = administrator.password;
|
||||||
this.email = administrator.email;
|
this.email = administrator.email;
|
||||||
this.name = administrator.name;
|
this.name = administrator.name;
|
||||||
|
this.administratorRole = administrator.administratorRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAdministratorRole(AdministratorRole administratorRole) {
|
||||||
|
this.administratorRole = administratorRole;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
package com.bpgroup.poc.admin.domain.entity.administrator;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.bpgroup.poc.admin.domain.entity.administrator;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.Role;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Embeddable
|
||||||
|
public class AdministratorRole {
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "role_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
|
private Role role;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static AdministratorRole of(Role role) {
|
||||||
|
AdministratorRole administratorRole = new AdministratorRole();
|
||||||
|
administratorRole.role = role;
|
||||||
|
return administratorRole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.exception;
|
package com.bpgroup.poc.admin.domain.entity.exception;
|
||||||
|
|
||||||
public class DuplicationAdministratorException extends RuntimeException {
|
public class DuplicationAdministratorException extends RuntimeException {
|
||||||
public DuplicationAdministratorException(String loginId) {
|
public DuplicationAdministratorException(String loginId) {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.exception;
|
package com.bpgroup.poc.admin.domain.entity.exception;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.DomainException;
|
import com.bpgroup.poc.admin.domain.DomainException;
|
||||||
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.bpgroup.poc.admin.domain.entity.menu;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.BaseEntity;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "menu")
|
||||||
|
public class Menu extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "uri", length = 100, nullable = false)
|
||||||
|
private String uri;
|
||||||
|
|
||||||
|
@Column(name = "name", length = 100, nullable = false)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "sort_order", nullable = false)
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "menu_group_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
|
private MenuGroup menuGroup;
|
||||||
|
|
||||||
|
public void setMenuGroup(MenuGroup menuGroup) {
|
||||||
|
this.menuGroup = menuGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static Menu of(String uri, String name, Integer sortOrder) {
|
||||||
|
Menu menu = new Menu();
|
||||||
|
menu.uri = uri;
|
||||||
|
menu.name = name;
|
||||||
|
menu.sortOrder = sortOrder;
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Menu entity) {
|
||||||
|
this.uri = entity.uri;
|
||||||
|
this.name = entity.name;
|
||||||
|
this.sortOrder = entity.sortOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.bpgroup.poc.admin.domain.entity.menu;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.BaseEntity;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "menu_group")
|
||||||
|
public class MenuGroup extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "uri", length = 100, nullable = false)
|
||||||
|
private String uri;
|
||||||
|
|
||||||
|
@Column(name = "name", length = 100, nullable = false)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "sort_order", nullable = false)
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "menuGroup", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
private List<Menu> menus = new ArrayList<>();
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static MenuGroup of(String uri, String name, Integer sortOrder) {
|
||||||
|
MenuGroup menuGroup = new MenuGroup();
|
||||||
|
menuGroup.uri = uri;
|
||||||
|
menuGroup.name = name;
|
||||||
|
menuGroup.sortOrder = sortOrder;
|
||||||
|
return menuGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMenu(Menu entity) {
|
||||||
|
this.menus.add(entity);
|
||||||
|
entity.setMenuGroup(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(MenuGroup entity) {
|
||||||
|
this.uri = entity.uri;
|
||||||
|
this.name = entity.name;
|
||||||
|
this.sortOrder = entity.sortOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.bpgroup.poc.admin.domain.entity.menu;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface MenuGroupRepository extends JpaRepository<MenuGroup, Long> {
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
package com.bpgroup.poc.admin.domain.entity.menu;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
package com.bpgroup.poc.admin.domain.entity.role;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.BaseEntity;
|
import com.bpgroup.poc.admin.domain.entity.BaseEntity;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -23,7 +23,7 @@ public class Role extends BaseEntity {
|
||||||
@Column(name = "description")
|
@Column(name = "description")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "role", fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "role", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private Set<RoleMenu> roleMenus = new HashSet<>();
|
private Set<RoleMenu> roleMenus = new HashSet<>();
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
|
|
@ -39,4 +39,8 @@ public class Role extends BaseEntity {
|
||||||
this.name = updateRole.name;
|
this.name = updateRole.name;
|
||||||
this.description = updateRole.description;
|
this.description = updateRole.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteRoleMenus() {
|
||||||
|
this.roleMenus.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.bpgroup.poc.admin.domain.entity.role;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.BaseEntity;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.Menu;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "role_menu")
|
||||||
|
public class RoleMenu extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "role_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
|
private Role role;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "menu_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
|
private Menu menu;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static RoleMenu of(Role role, Menu menu) {
|
||||||
|
RoleMenu roleMenu = new RoleMenu();
|
||||||
|
roleMenu.role = role;
|
||||||
|
roleMenu.menu = menu;
|
||||||
|
return roleMenu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.bpgroup.poc.admin.domain.entity.role;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface RoleMenuRepository extends JpaRepository<RoleMenu, Long> {
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.entity;
|
package com.bpgroup.poc.admin.domain.entity.role;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.bpgroup.poc.admin.security.authentication.service;
|
package com.bpgroup.poc.admin.security.authentication.service;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Administrator;
|
import com.bpgroup.poc.admin.domain.entity.administrator.Administrator;
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.AdministratorRepository;
|
import com.bpgroup.poc.admin.domain.entity.administrator.AdministratorRepository;
|
||||||
import com.bpgroup.poc.admin.security.authentication.service.exception.AdministratorNotFoundException;
|
import com.bpgroup.poc.admin.security.authentication.service.exception.AdministratorNotFoundException;
|
||||||
import com.bpgroup.poc.admin.security.authentication.service.exception.DoNotHaveAnyMenuException;
|
import com.bpgroup.poc.admin.security.authentication.service.exception.DoNotHaveAnyMenuException;
|
||||||
import com.bpgroup.poc.admin.security.authentication.service.exception.InvalidPasswordException;
|
import com.bpgroup.poc.admin.security.authentication.service.exception.InvalidPasswordException;
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@ import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static com.bpgroup.poc.admin.domain.admin.entity.QAdministrator.administrator;
|
import static com.bpgroup.poc.admin.domain.entity.administrator.QAdministrator.administrator;
|
||||||
import static com.bpgroup.poc.admin.domain.admin.entity.QAdministratorRole.administratorRole;
|
import static com.bpgroup.poc.admin.domain.entity.administrator.QAdministratorRole.administratorRole;
|
||||||
import static com.bpgroup.poc.admin.domain.admin.entity.QMenu.menu;
|
import static com.bpgroup.poc.admin.domain.entity.menu.QMenu.menu;
|
||||||
import static com.bpgroup.poc.admin.domain.admin.entity.QMenuGroup.menuGroup;
|
import static com.bpgroup.poc.admin.domain.entity.menu.QMenuGroup.menuGroup;
|
||||||
import static com.bpgroup.poc.admin.domain.admin.entity.QRole.role;
|
import static com.bpgroup.poc.admin.domain.entity.role.QRole.role;
|
||||||
import static com.bpgroup.poc.admin.domain.admin.entity.QRoleMenu.roleMenu;
|
import static com.bpgroup.poc.admin.domain.entity.role.QRoleMenu.roleMenu;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
|
@ -30,7 +30,6 @@ public class MenuQueryRepository {
|
||||||
roleMenu.menu.sortOrder
|
roleMenu.menu.sortOrder
|
||||||
)
|
)
|
||||||
.from(administrator)
|
.from(administrator)
|
||||||
.innerJoin(administrator.administratorRole, administratorRole)
|
|
||||||
.innerJoin(administratorRole.role, role)
|
.innerJoin(administratorRole.role, role)
|
||||||
.innerJoin(role.roleMenus, roleMenu)
|
.innerJoin(role.roleMenus, roleMenu)
|
||||||
.innerJoin(roleMenu.menu, menu)
|
.innerJoin(roleMenu.menu, menu)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.bpgroup.poc.admin.domain.admin.entity.QAdministrator.administrator;
|
import static com.bpgroup.poc.admin.domain.entity.administrator.QAdministrator.administrator;
|
||||||
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
|
@ -26,7 +27,7 @@ public class AdministratorManagementQueryRepository {
|
||||||
.fetch();
|
.fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdministratorFind.Response findByLoginId(String loginId) {
|
public AdministratorFind.Response find(String loginId) {
|
||||||
return queryFactory.select(Projections.fields(AdministratorFind.Response.class,
|
return queryFactory.select(Projections.fields(AdministratorFind.Response.class,
|
||||||
administrator.id,
|
administrator.id,
|
||||||
administrator.loginId,
|
administrator.loginId,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@ import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorCreat
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorDelete;
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorDelete;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorFind;
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorFind;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorUpdate;
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorUpdate;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.management.service.AdministratorCreateCommand;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.management.service.AdministratorCreateResult;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.management.service.AdministratorManagementService;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.management.service.AdministratorUpdateCommand;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
@ -20,32 +24,37 @@ import java.util.List;
|
||||||
public class AdministratorManagementRestController {
|
public class AdministratorManagementRestController {
|
||||||
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
private final AdministratorManagementService administratorManagementService;
|
|
||||||
|
private final AdministratorManagementService service;
|
||||||
|
private final AdministratorManagementQueryRepository queryRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 전체 조회
|
* 전체 조회
|
||||||
|
*
|
||||||
* @return 응답
|
* @return 응답
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public ResponseEntity<?> getAdministrators() {
|
public ResponseEntity<?> getAdministrators() {
|
||||||
List<AdministratorFind.Response> response = administratorManagementService.findAll();
|
List<AdministratorFind.Response> response = queryRepository.findAll();
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 조회
|
* 조회
|
||||||
|
*
|
||||||
* @param loginId 관리자 ID
|
* @param loginId 관리자 ID
|
||||||
* @return 응답
|
* @return 응답
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{loginId}")
|
@GetMapping("/{loginId}")
|
||||||
public ResponseEntity<?> getAdministrator(@PathVariable @NotBlank String loginId) {
|
public ResponseEntity<?> getAdministrator(@PathVariable @NotBlank String loginId) {
|
||||||
AdministratorFind.Response response = administratorManagementService.find(loginId);
|
AdministratorFind.Response response = queryRepository.find(loginId);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 관리자 등록
|
* 관리자 등록
|
||||||
* @param request 요청
|
*
|
||||||
|
* @param request 요청
|
||||||
* @param bindingResult Validation 결과
|
* @param bindingResult Validation 결과
|
||||||
* @return 응답
|
* @return 응답
|
||||||
*/
|
*/
|
||||||
|
|
@ -54,9 +63,15 @@ public class AdministratorManagementRestController {
|
||||||
@RequestBody @Validated AdministratorCreate.Request request,
|
@RequestBody @Validated AdministratorCreate.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
request.setPassword(passwordEncoder.encode(request.getPassword()));
|
AdministratorCreateResult result = service.create(
|
||||||
AdministratorCreate.Response response = administratorManagementService.create(request);
|
AdministratorCreateCommand.builder()
|
||||||
return ResponseEntity.ok(response);
|
.loginId(request.getLoginId())
|
||||||
|
.password(passwordEncoder.encode(request.getPassword()))
|
||||||
|
.email(request.getEmail())
|
||||||
|
.name(request.getName())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
return ResponseEntity.ok(AdministratorCreate.Response.success(result.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
|
|
@ -64,13 +79,21 @@ public class AdministratorManagementRestController {
|
||||||
@RequestBody @Validated AdministratorUpdate.Request request,
|
@RequestBody @Validated AdministratorUpdate.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
request.setPassword(passwordEncoder.encode(request.getPassword()));
|
service.update(
|
||||||
AdministratorUpdate.Response response = administratorManagementService.update(request);
|
AdministratorUpdateCommand.builder()
|
||||||
return ResponseEntity.ok(response);
|
.password(passwordEncoder.encode(request.getPassword()))
|
||||||
|
.name(request.getName())
|
||||||
|
.email(request.getEmail())
|
||||||
|
.roleId(request.getRoleId())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(AdministratorUpdate.Response.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 관리자 삭제
|
* 관리자 삭제
|
||||||
|
*
|
||||||
* @param request 요청
|
* @param request 요청
|
||||||
* @param bindingResult Validation 결과
|
* @param bindingResult Validation 결과
|
||||||
* @return 응답
|
* @return 응답
|
||||||
|
|
@ -80,8 +103,8 @@ public class AdministratorManagementRestController {
|
||||||
@RequestBody @Validated AdministratorDelete.Request request,
|
@RequestBody @Validated AdministratorDelete.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
AdministratorDelete.Response response = administratorManagementService.delete(request);
|
service.delete(request.getId());
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(AdministratorDelete.Response.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
package com.bpgroup.poc.admin.web.main.admin.management;
|
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.command.AdministratorCreateCommand;
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.command.AdministratorUpdateCommand;
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Administrator;
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.AdministratorRepository;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorCreate;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorDelete;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorFind;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorUpdate;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Transactional
|
|
||||||
public class AdministratorManagementService {
|
|
||||||
|
|
||||||
private final AdministratorManagementQueryRepository queryRepository;
|
|
||||||
private final AdministratorRepository repository;
|
|
||||||
|
|
||||||
public List<AdministratorFind.Response> findAll() {
|
|
||||||
return queryRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdministratorFind.Response find(@NotBlank String loginId) {
|
|
||||||
return queryRepository.findByLoginId(loginId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdministratorCreate.Response create(AdministratorCreate.Request request) {
|
|
||||||
Administrator admin = repository.save(
|
|
||||||
AdministratorCreateCommand.builder()
|
|
||||||
.loginId(request.getLoginId())
|
|
||||||
.password(request.getPassword())
|
|
||||||
.email(request.getEmail())
|
|
||||||
.name(request.getName())
|
|
||||||
.build()
|
|
||||||
.toEntity()
|
|
||||||
);
|
|
||||||
|
|
||||||
return AdministratorCreate.Response.success(admin.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdministratorUpdate.Response update(AdministratorUpdate.Request request) {
|
|
||||||
Optional<Administrator> findAdministrator = repository.findById(request.getId());
|
|
||||||
if (findAdministrator.isEmpty()) {
|
|
||||||
return AdministratorUpdate.Response.fail("ADMINISTRATOR_NOT_FOUND");
|
|
||||||
}
|
|
||||||
|
|
||||||
Administrator administrator = findAdministrator.get();
|
|
||||||
administrator.update(
|
|
||||||
AdministratorUpdateCommand.of(
|
|
||||||
request.getId(),
|
|
||||||
request.getPassword(),
|
|
||||||
request.getEmail(),
|
|
||||||
request.getName()
|
|
||||||
).toEntity()
|
|
||||||
);
|
|
||||||
|
|
||||||
return AdministratorUpdate.Response.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdministratorDelete.Response delete(AdministratorDelete.Request request) {
|
|
||||||
repository.deleteById(request.getId());
|
|
||||||
return AdministratorDelete.Response.success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -13,15 +13,14 @@ public class AdministratorCreate {
|
||||||
public static class Request {
|
public static class Request {
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String loginId;
|
private String loginId;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
@NotBlank
|
||||||
|
private String roleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,14 @@ public class AdministratorUpdate {
|
||||||
public static class Request {
|
public static class Request {
|
||||||
@NotNull
|
@NotNull
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Long roleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.command;
|
package com.bpgroup.poc.admin.web.main.admin.management.service;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Administrator;
|
import com.bpgroup.poc.admin.domain.entity.administrator.Administrator;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
@ -9,26 +10,25 @@ import lombok.ToString;
|
||||||
@Getter
|
@Getter
|
||||||
@ToString
|
@ToString
|
||||||
public class AdministratorCreateCommand {
|
public class AdministratorCreateCommand {
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String loginId;
|
private String loginId;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
public static AdministratorCreateCommand of(String loginId, String password, String email, String name) {
|
public static AdministratorCreateCommand of(String loginId, String password, String email, String name, Long roleId) {
|
||||||
AdministratorCreateCommand command = new AdministratorCreateCommand();
|
AdministratorCreateCommand command = new AdministratorCreateCommand();
|
||||||
command.loginId = loginId;
|
command.loginId = loginId;
|
||||||
command.password = password;
|
command.password = password;
|
||||||
command.email = email;
|
command.email = email;
|
||||||
command.name = name;
|
command.name = name;
|
||||||
|
command.roleId = roleId;
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.management.service;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class AdministratorCreateResult {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static AdministratorCreateResult of(Long id) {
|
||||||
|
AdministratorCreateResult result = new AdministratorCreateResult();
|
||||||
|
result.id = id;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.management.service;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.administrator.Administrator;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.administrator.AdministratorRepository;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.administrator.AdministratorRole;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.Role;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.RoleRepository;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Validated
|
||||||
|
@Transactional
|
||||||
|
public class AdministratorManagementService {
|
||||||
|
|
||||||
|
private final AdministratorRepository administratorRepository;
|
||||||
|
private final RoleRepository roleRepository;
|
||||||
|
|
||||||
|
public AdministratorCreateResult create(
|
||||||
|
@NotNull @Valid AdministratorCreateCommand command
|
||||||
|
) {
|
||||||
|
Optional<Role> findRole = roleRepository.findById(command.getRoleId());
|
||||||
|
if (findRole.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Not found role");
|
||||||
|
}
|
||||||
|
|
||||||
|
Role role = findRole.get();
|
||||||
|
Administrator administrator = command.toEntity();
|
||||||
|
administrator.setAdministratorRole(
|
||||||
|
AdministratorRole.builder()
|
||||||
|
.role(role)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
Administrator savedAdministrator = administratorRepository.save(administrator);
|
||||||
|
|
||||||
|
return AdministratorCreateResult.builder()
|
||||||
|
.id(savedAdministrator.getId())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(
|
||||||
|
@NotNull @Valid AdministratorUpdateCommand command
|
||||||
|
) {
|
||||||
|
Optional<Administrator> findAdministrator = administratorRepository.findById(command.getId());
|
||||||
|
if (findAdministrator.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Not found administrator");
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Role> findRole = roleRepository.findById(command.getRoleId());
|
||||||
|
if (findRole.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Not found role");
|
||||||
|
}
|
||||||
|
|
||||||
|
Role role = findRole.get();
|
||||||
|
Administrator administrator = findAdministrator.get();
|
||||||
|
administrator.setAdministratorRole(
|
||||||
|
AdministratorRole.builder()
|
||||||
|
.role(role)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
administrator.update(administrator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(@NotNull Long id) {
|
||||||
|
Optional<Administrator> findAdministrator = administratorRepository.findById(id);
|
||||||
|
if (findAdministrator.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Not found administrator");
|
||||||
|
}
|
||||||
|
|
||||||
|
administratorRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,33 +1,34 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.command;
|
package com.bpgroup.poc.admin.web.main.admin.management.service;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Administrator;
|
import com.bpgroup.poc.admin.domain.entity.administrator.Administrator;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ToString
|
@ToString
|
||||||
public class AdministratorUpdateCommand {
|
public class AdministratorUpdateCommand {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
public static AdministratorUpdateCommand of(Long id, String password, String email, String name) {
|
@Builder
|
||||||
|
public static AdministratorUpdateCommand of(Long id, String password, String email, String name, Long roleId) {
|
||||||
AdministratorUpdateCommand command = new AdministratorUpdateCommand();
|
AdministratorUpdateCommand command = new AdministratorUpdateCommand();
|
||||||
command.id = id;
|
command.id = id;
|
||||||
command.password = password;
|
command.password = password;
|
||||||
command.email = email;
|
command.email = email;
|
||||||
command.name = name;
|
command.name = name;
|
||||||
|
command.roleId = roleId;
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.menu.service.*;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.menu.reqres.*;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/admin/menu")
|
||||||
|
public class MenuRestController {
|
||||||
|
|
||||||
|
private final MenuService service;
|
||||||
|
|
||||||
|
@PostMapping("/create/menu-group")
|
||||||
|
public ResponseEntity<?> createMenuGroup(
|
||||||
|
@RequestBody @Valid MenuGroupCreate.Request request,
|
||||||
|
BindingResult bindingResult
|
||||||
|
) {
|
||||||
|
service.createMenuGroup(
|
||||||
|
MenuGroupCreateCommand.builder()
|
||||||
|
.name(request.getName())
|
||||||
|
.uri(request.getUri())
|
||||||
|
.sortOrder(request.getSortOrder())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(MenuGroupCreate.Response.success());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update/menu-group")
|
||||||
|
public ResponseEntity<?> updateMenuGroup(
|
||||||
|
@RequestBody @Valid MenuGroupUpdate.Request request,
|
||||||
|
BindingResult bindingResult
|
||||||
|
) {
|
||||||
|
service.updateMenuGroup(
|
||||||
|
MenuGroupUpdateCommand.builder()
|
||||||
|
.id(request.getId())
|
||||||
|
.name(request.getName())
|
||||||
|
.uri(request.getUri())
|
||||||
|
.sortOrder(request.getSortOrder())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(MenuGroupCreate.Response.success());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete/menu-group")
|
||||||
|
public ResponseEntity<?> deleteMenuGroup(
|
||||||
|
@RequestBody @Valid MenuGroupDelete.Request request,
|
||||||
|
BindingResult bindingResult
|
||||||
|
) {
|
||||||
|
service.deleteMenuGroup(request.getId());
|
||||||
|
|
||||||
|
return ResponseEntity.ok(MenuGroupDelete.Response.success());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create/menu")
|
||||||
|
public ResponseEntity<?> createMenu(
|
||||||
|
@RequestBody @Valid MenuCreate.Request request,
|
||||||
|
BindingResult bindingResult
|
||||||
|
) {
|
||||||
|
service.createMenu(
|
||||||
|
MenuCreateCommand.builder()
|
||||||
|
.menuGroupId(request.getMenuGroupId())
|
||||||
|
.name(request.getName())
|
||||||
|
.uri(request.getUri())
|
||||||
|
.sortOrder(request.getSortOrder())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
return ResponseEntity.ok(MenuCreate.Response.success());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update/menu")
|
||||||
|
public ResponseEntity<?> updateMenu(
|
||||||
|
@RequestBody @Valid MenuUpdate.Request request,
|
||||||
|
BindingResult bindingResult
|
||||||
|
) {
|
||||||
|
service.updateMenu(
|
||||||
|
MenuUpdateCommand.builder()
|
||||||
|
.id(request.getId())
|
||||||
|
.name(request.getName())
|
||||||
|
.uri(request.getUri())
|
||||||
|
.sortOrder(request.getSortOrder())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(MenuGroupCreate.Response.success());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete/menu")
|
||||||
|
public ResponseEntity<?> deleteMenu(
|
||||||
|
@RequestBody @Valid MenuDelete.Request request,
|
||||||
|
BindingResult bindingResult
|
||||||
|
) {
|
||||||
|
service.deleteMenu(request.getId());
|
||||||
|
|
||||||
|
return ResponseEntity.ok(MenuDelete.Response.success());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.reqres;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.common.CommonResponse;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
public class MenuCreate {
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Request {
|
||||||
|
@NotNull
|
||||||
|
private Long menuGroupId;
|
||||||
|
@NotBlank
|
||||||
|
private String uri;
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Integer sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public static class Response extends CommonResponse {
|
||||||
|
@Builder
|
||||||
|
public static Response success() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "0000";
|
||||||
|
response.resultMessage = "Success";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static Response fail() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "9999";
|
||||||
|
response.resultMessage = "Fail";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.reqres;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.common.CommonResponse;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
public class MenuDelete {
|
||||||
|
@Data
|
||||||
|
public static class Request {
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public static class Response extends CommonResponse {
|
||||||
|
@Builder
|
||||||
|
public static Response success() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "0000";
|
||||||
|
response.resultMessage = "Success";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static Response fail(String resultMessage) {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "9999";
|
||||||
|
response.resultMessage = resultMessage;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.reqres;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.common.CommonResponse;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
public class MenuGroupCreate {
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Request {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String uri;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Integer sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public static class Response extends CommonResponse {
|
||||||
|
@Builder
|
||||||
|
public static Response success() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "0000";
|
||||||
|
response.resultMessage = "Success";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static Response fail() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "9999";
|
||||||
|
response.resultMessage = "Fail";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.reqres;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.common.CommonResponse;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
public class MenuGroupDelete {
|
||||||
|
@Data
|
||||||
|
public static class Request {
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public static class Response extends CommonResponse {
|
||||||
|
@Builder
|
||||||
|
public static Response success() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "0000";
|
||||||
|
response.resultMessage = "Success";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static Response fail(String resultMessage) {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "9999";
|
||||||
|
response.resultMessage = resultMessage;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.reqres;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.common.CommonResponse;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
public class MenuGroupUpdate {
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Request {
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
|
@NotBlank
|
||||||
|
private String uri;
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Integer sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public static class Response extends CommonResponse {
|
||||||
|
@Builder
|
||||||
|
public static Response success() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "0000";
|
||||||
|
response.resultMessage = "Success";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static Response fail(String resultMessage) {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "9999";
|
||||||
|
response.resultMessage = resultMessage;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.reqres;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.common.CommonResponse;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
public class MenuUpdate {
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Request {
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
|
@NotBlank
|
||||||
|
private String uri;
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Integer sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public static class Response extends CommonResponse {
|
||||||
|
@Builder
|
||||||
|
public static Response success() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "0000";
|
||||||
|
response.resultMessage = "Success";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static Response fail(String resultMessage) {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "9999";
|
||||||
|
response.resultMessage = resultMessage;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.service;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.Menu;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class MenuCreateCommand {
|
||||||
|
@NotNull
|
||||||
|
private Long menuGroupId;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String uri;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static MenuCreateCommand of(Long menuGroupId, String uri, String name, Integer sortOrder) {
|
||||||
|
MenuCreateCommand command = new MenuCreateCommand();
|
||||||
|
command.menuGroupId = menuGroupId;
|
||||||
|
command.uri = uri;
|
||||||
|
command.name = name;
|
||||||
|
command.sortOrder = sortOrder;
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Menu toEntity() {
|
||||||
|
return Menu.builder()
|
||||||
|
.uri(uri)
|
||||||
|
.name(name)
|
||||||
|
.sortOrder(sortOrder)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.service;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuGroup;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class MenuGroupCreateCommand {
|
||||||
|
@NotBlank
|
||||||
|
private String uri;
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static MenuGroupCreateCommand of(String uri, String name, Integer sortOrder) {
|
||||||
|
MenuGroupCreateCommand command = new MenuGroupCreateCommand();
|
||||||
|
command.uri = uri;
|
||||||
|
command.name = name;
|
||||||
|
command.sortOrder = sortOrder;
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MenuGroup toEntity() {
|
||||||
|
return MenuGroup.builder()
|
||||||
|
.uri(uri)
|
||||||
|
.name(name)
|
||||||
|
.sortOrder(sortOrder)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.service;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuGroup;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class MenuGroupUpdateCommand {
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
|
@NotBlank
|
||||||
|
private String uri;
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static MenuGroupUpdateCommand of(Long id, String uri, String name, Integer sortOrder) {
|
||||||
|
MenuGroupUpdateCommand command = new MenuGroupUpdateCommand();
|
||||||
|
command.id = id;
|
||||||
|
command.uri = uri;
|
||||||
|
command.name = name;
|
||||||
|
command.sortOrder = sortOrder;
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MenuGroup toEntity() {
|
||||||
|
return MenuGroup.builder()
|
||||||
|
.uri(uri)
|
||||||
|
.name(name)
|
||||||
|
.sortOrder(sortOrder)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.service;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.Menu;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuGroup;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuGroupRepository;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuRepository;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Validated
|
||||||
|
@Transactional
|
||||||
|
public class MenuService {
|
||||||
|
|
||||||
|
private final MenuGroupRepository menuGroupRepository;
|
||||||
|
private final MenuRepository menuRepository;
|
||||||
|
|
||||||
|
public void createMenuGroup(
|
||||||
|
@NotNull @Valid MenuGroupCreateCommand command
|
||||||
|
) {
|
||||||
|
menuGroupRepository.save(command.toEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateMenuGroup(
|
||||||
|
@NotNull @Valid MenuGroupUpdateCommand command
|
||||||
|
) {
|
||||||
|
Optional<MenuGroup> findMenuGroup = menuGroupRepository.findById(command.getId());
|
||||||
|
if (findMenuGroup.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("MenuGroup not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
findMenuGroup.get().update(command.toEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteMenuGroup(@NotNull Long id) {
|
||||||
|
Optional<MenuGroup> findMenuGroup = menuGroupRepository.findById(id);
|
||||||
|
if (findMenuGroup.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("MenuGroup not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
menuGroupRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createMenu(
|
||||||
|
@NotNull @Valid MenuCreateCommand command
|
||||||
|
) {
|
||||||
|
Optional<MenuGroup> findMenuGroup = menuGroupRepository.findById(command.getMenuGroupId());
|
||||||
|
if (findMenuGroup.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("MenuGroup not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu menu = command.toEntity();
|
||||||
|
MenuGroup menuGroup = findMenuGroup.get();
|
||||||
|
menuGroup.addMenu(menu);
|
||||||
|
|
||||||
|
menuRepository.save(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateMenu(
|
||||||
|
@NotNull @Valid MenuUpdateCommand build
|
||||||
|
) {
|
||||||
|
Optional<Menu> findMenu = menuRepository.findById(build.getId());
|
||||||
|
if (findMenu.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Menu not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
findMenu.get().update(build.toEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteMenu(@NotNull Long id) {
|
||||||
|
Optional<Menu> findMenu = menuRepository.findById(id);
|
||||||
|
if (findMenu.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Menu not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
menuRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu.service;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.Menu;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class MenuUpdateCommand {
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
|
@NotBlank
|
||||||
|
private String uri;
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
@NotNull
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static MenuUpdateCommand of(Long id, String uri, String name, Integer sortOrder) {
|
||||||
|
MenuUpdateCommand command = new MenuUpdateCommand();
|
||||||
|
command.id = id;
|
||||||
|
command.uri = uri;
|
||||||
|
command.name = name;
|
||||||
|
command.sortOrder = sortOrder;
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Menu toEntity() {
|
||||||
|
return Menu.builder()
|
||||||
|
.uri(uri)
|
||||||
|
.name(name)
|
||||||
|
.sortOrder(sortOrder)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package com.bpgroup.poc.admin.web.main.admin.role;
|
package com.bpgroup.poc.admin.web.main.admin.role;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleAddMenu;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleCreate;
|
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleCreate;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleDelete;
|
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleDelete;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleUpdate;
|
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleUpdate;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.role.service.*;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
@ -12,6 +14,10 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/admin/role")
|
@RequestMapping("/admin/role")
|
||||||
|
|
@ -20,7 +26,6 @@ public class RoleRestController {
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 권한 등록
|
* 권한 등록
|
||||||
*/
|
*/
|
||||||
|
|
@ -29,8 +34,14 @@ public class RoleRestController {
|
||||||
@RequestBody @Valid RoleCreate.Request request,
|
@RequestBody @Valid RoleCreate.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
RoleCreate.Response response = roleService.create(request);
|
RoleCreateResult result = roleService.create(
|
||||||
return ResponseEntity.ok(response);
|
RoleCreateCommand.builder()
|
||||||
|
.name(request.getName())
|
||||||
|
.description(request.getDescription())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(RoleCreate.Response.success(result.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,8 +52,15 @@ public class RoleRestController {
|
||||||
@RequestBody @Valid RoleUpdate.Request request,
|
@RequestBody @Valid RoleUpdate.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
RoleUpdate.Response response = roleService.update(request);
|
roleService.update(
|
||||||
return ResponseEntity.ok(response);
|
RoleUpdateCommand.builder()
|
||||||
|
.id(request.getId())
|
||||||
|
.name(request.getName())
|
||||||
|
.description(request.getDescription())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(RoleUpdate.Response.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,8 +71,32 @@ public class RoleRestController {
|
||||||
@RequestBody @Valid RoleDelete.Request request,
|
@RequestBody @Valid RoleDelete.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
RoleDelete.Response response = roleService.delete(request);
|
roleService.delete(request.getId());
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(RoleDelete.Response.success());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 권한 내 메뉴 추가
|
||||||
|
* DELETE -> INSERT
|
||||||
|
*/
|
||||||
|
@PostMapping("/put/menu")
|
||||||
|
public ResponseEntity<?> addMenu(
|
||||||
|
@RequestBody @Valid List<RoleAddMenu.Request> request,
|
||||||
|
BindingResult bindingResult
|
||||||
|
) {
|
||||||
|
roleService.deleteRoleMenu(request.get(0).getRoleId());
|
||||||
|
|
||||||
|
Set<RoleAddMenuCommand> commands = request.stream()
|
||||||
|
.map(c -> RoleAddMenuCommand.builder()
|
||||||
|
.roleId(c.getRoleId())
|
||||||
|
.menuId(c.getMenuId())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
roleService.addRoleMenu(commands);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(RoleAddMenu.Response.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
package com.bpgroup.poc.admin.web.main.admin.role;
|
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Role;
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.RoleRepository;
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.command.RoleCreateCommand;
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.command.RoleUpdateCommand;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleCreate;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleDelete;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleUpdate;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class RoleService {
|
|
||||||
|
|
||||||
private final RoleRepository repository;
|
|
||||||
private final RoleQueryRepository queryRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ROLE 생성
|
|
||||||
*/
|
|
||||||
public RoleCreate.Response create(RoleCreate.Request request) {
|
|
||||||
Role role = repository.save(
|
|
||||||
RoleCreateCommand.builder()
|
|
||||||
.name(request.getName())
|
|
||||||
.description(request.getDescription())
|
|
||||||
.build()
|
|
||||||
.toEntity()
|
|
||||||
);
|
|
||||||
|
|
||||||
return RoleCreate.Response.success(role.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ROLE 수정
|
|
||||||
*/
|
|
||||||
public RoleUpdate.Response update(RoleUpdate.Request request) {
|
|
||||||
Optional<Role> role = repository.findById(request.getId());
|
|
||||||
if (role.isEmpty()) {
|
|
||||||
return RoleUpdate.Response.fail("ROLE_NOT_FOUND");
|
|
||||||
}
|
|
||||||
|
|
||||||
Role findRole = role.get();
|
|
||||||
Role updateRole = RoleUpdateCommand.builder()
|
|
||||||
.name(request.getName())
|
|
||||||
.description(request.getDescription())
|
|
||||||
.build()
|
|
||||||
.toEntity();
|
|
||||||
|
|
||||||
findRole.update(updateRole);
|
|
||||||
|
|
||||||
return RoleUpdate.Response.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleDelete.Response delete(RoleDelete.Request request) {
|
|
||||||
try {
|
|
||||||
repository.deleteById(request.getId());
|
|
||||||
return RoleDelete.Response.success();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return RoleDelete.Response.fail("Role Delete Fail");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.role.reqres;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.web.common.CommonResponse;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
public class RoleAddMenu {
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Request {
|
||||||
|
@NotNull
|
||||||
|
private Long roleId;
|
||||||
|
@NotNull
|
||||||
|
private Long menuId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public static class Response extends CommonResponse {
|
||||||
|
@Builder
|
||||||
|
public static Response success() {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "0000";
|
||||||
|
response.resultMessage = "Success";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static Response fail(String resultMessage) {
|
||||||
|
Response response = new Response();
|
||||||
|
response.resultCode = "9999";
|
||||||
|
response.resultMessage = resultMessage;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.role.service;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class RoleAddMenuCommand {
|
||||||
|
@NotNull
|
||||||
|
private Long roleId;
|
||||||
|
@NotNull
|
||||||
|
private Long menuId;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static RoleAddMenuCommand of(Long roleId, Long menuId) {
|
||||||
|
RoleAddMenuCommand command = new RoleAddMenuCommand();
|
||||||
|
command.roleId = roleId;
|
||||||
|
command.menuId = menuId;
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.command;
|
package com.bpgroup.poc.admin.web.main.admin.role.service;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Role;
|
import com.bpgroup.poc.admin.domain.entity.role.Role;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.role.service;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class RoleCreateResult {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public static RoleCreateResult of(Long id) {
|
||||||
|
RoleCreateResult result = new RoleCreateResult();
|
||||||
|
result.id = id;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.role.service;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.Menu;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuRepository;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.Role;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.RoleMenu;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.RoleMenuRepository;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.RoleRepository;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Validated
|
||||||
|
@Transactional
|
||||||
|
public class RoleService {
|
||||||
|
|
||||||
|
private final RoleRepository roleRepository;
|
||||||
|
private final MenuRepository menuRepository;
|
||||||
|
private final RoleMenuRepository roleMenuRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ROLE 생성
|
||||||
|
*/
|
||||||
|
public RoleCreateResult create(
|
||||||
|
@NotNull @Valid RoleCreateCommand command
|
||||||
|
) {
|
||||||
|
Role role = roleRepository.save(command.toEntity());
|
||||||
|
|
||||||
|
return RoleCreateResult.builder()
|
||||||
|
.id(role.getId())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ROLE 수정
|
||||||
|
*/
|
||||||
|
public void update(
|
||||||
|
@NotNull @Valid RoleUpdateCommand command
|
||||||
|
) {
|
||||||
|
Optional<Role> findRole = roleRepository.findById(command.getId());
|
||||||
|
if (findRole.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Role Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Role role = findRole.get();
|
||||||
|
role.update(command.toEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(@NotNull Long id) {
|
||||||
|
Optional<Role> findRole = roleRepository.findById(id);
|
||||||
|
if (findRole.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Role Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Role role = findRole.get();
|
||||||
|
roleRepository.deleteById(role.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRoleMenu(
|
||||||
|
@NotNull @Valid Set<RoleAddMenuCommand> commands
|
||||||
|
) {
|
||||||
|
RoleAddMenuCommand command = commands.stream().findFirst().orElseThrow();
|
||||||
|
Optional<Role> findRole = roleRepository.findById(command.getRoleId());
|
||||||
|
if (findRole.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Role Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Role role = findRole.get();
|
||||||
|
commands.forEach(c -> {
|
||||||
|
Optional<Menu> findMenu = menuRepository.findById(c.getMenuId());
|
||||||
|
if (findMenu.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Menu Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu menu = findMenu.get();
|
||||||
|
RoleMenu roleMenu = RoleMenu.of(role, menu);
|
||||||
|
roleMenuRepository.save(roleMenu);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteRoleMenu(@NotNull Long roleId) {
|
||||||
|
Optional<Role> findRole = roleRepository.findById(roleId);
|
||||||
|
if (findRole.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Role Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Role role = findRole.get();
|
||||||
|
role.deleteRoleMenus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
package com.bpgroup.poc.admin.domain.admin.command;
|
package com.bpgroup.poc.admin.web.main.admin.role.service;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Role;
|
import com.bpgroup.poc.admin.domain.entity.role.Role;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
@ -10,14 +11,16 @@ import lombok.ToString;
|
||||||
@ToString
|
@ToString
|
||||||
public class RoleUpdateCommand {
|
public class RoleUpdateCommand {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
public static RoleUpdateCommand of(String name, String description) {
|
public static RoleUpdateCommand of(Long id, String name, String description) {
|
||||||
RoleUpdateCommand command = new RoleUpdateCommand();
|
RoleUpdateCommand command = new RoleUpdateCommand();
|
||||||
|
command.id = id;
|
||||||
command.name = name;
|
command.name = name;
|
||||||
command.description = description;
|
command.description = description;
|
||||||
return command;
|
return command;
|
||||||
|
|
@ -1,14 +1,17 @@
|
||||||
package com.bpgroup.poc.admin.web.main.admin.administrator;
|
package com.bpgroup.poc.admin.web.main.admin.administrator;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.command.AdministratorCreateCommand;
|
import com.bpgroup.poc.admin.domain.entity.administrator.Administrator;
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Administrator;
|
import com.bpgroup.poc.admin.domain.entity.administrator.AdministratorRepository;
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.AdministratorRepository;
|
import com.bpgroup.poc.admin.domain.entity.administrator.AdministratorRole;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.Role;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.RoleRepository;
|
||||||
import com.bpgroup.poc.admin.env.MariaDBTestEnv;
|
import com.bpgroup.poc.admin.env.MariaDBTestEnv;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.AdministratorManagementQueryRepository;
|
import com.bpgroup.poc.admin.web.main.admin.management.service.AdministratorCreateCommand;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.AdministratorManagementService;
|
import com.bpgroup.poc.admin.web.main.admin.management.service.AdministratorCreateResult;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorCreate;
|
import com.bpgroup.poc.admin.web.main.admin.management.service.AdministratorManagementService;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorDelete;
|
import com.bpgroup.poc.admin.web.main.admin.management.service.AdministratorUpdateCommand;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdministratorUpdate;
|
import jakarta.validation.ConstraintViolationException;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -16,100 +19,180 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@DisplayName("AdministratorService 테스트")
|
@DisplayName("AdministratorService 테스트")
|
||||||
public class AdministratorServiceTest extends MariaDBTestEnv {
|
class AdministratorServiceTest extends MariaDBTestEnv {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AdministratorManagementService service;
|
private AdministratorManagementService service;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AdministratorRepository repository;
|
private AdministratorRepository administratorRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AdministratorManagementQueryRepository queryRepository;
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
repository.deleteAll();
|
administratorRepository.deleteAll();
|
||||||
|
roleRepository.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Administrator 등록 테스트")
|
|
||||||
@Test
|
@Test
|
||||||
public void createAdministratorTest() {
|
void createAdministratorTest() {
|
||||||
// given
|
Role role = getSaveRole();
|
||||||
AdministratorCreate.Request request = new AdministratorCreate.Request();
|
flushAndClear();
|
||||||
request.setLoginId("test");
|
|
||||||
request.setPassword("test");
|
|
||||||
request.setEmail("test");
|
|
||||||
request.setName("test");
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
AdministratorCreate.Response response = service.create(request);
|
AdministratorCreateResult createResult = service.create(
|
||||||
|
AdministratorCreateCommand.builder()
|
||||||
|
.loginId("test")
|
||||||
|
.password("test")
|
||||||
|
.email("test")
|
||||||
|
.name("test")
|
||||||
|
.roleId(role.getId())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(response.getResultCode()).isEqualTo("0000");
|
assertThat(createResult.getId()).isNotNull();
|
||||||
|
|
||||||
|
Administrator findAdministrator = administratorRepository.findById(createResult.getId()).orElseThrow();
|
||||||
|
assertThat(findAdministrator.getAdministratorRole().getRole().getName()).isEqualTo("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Administrator 수정 테스트")
|
@DisplayName("Administrator 수정 테스트")
|
||||||
@Test
|
@Test
|
||||||
public void updateAdministratorTest() {
|
void updateAdministratorTest() {
|
||||||
// given
|
// given
|
||||||
Administrator administrator = repository.save(
|
Role saveRole = getSaveRole();
|
||||||
AdministratorCreateCommand.builder()
|
flushAndClear();
|
||||||
.loginId("test")
|
|
||||||
.password("test")
|
Administrator saveAdministrator = createAdministrator(saveRole);
|
||||||
.email("test")
|
flushAndClear();
|
||||||
.name("test")
|
|
||||||
|
Role updateRole = roleRepository.save(
|
||||||
|
Role.builder()
|
||||||
|
.name("test2")
|
||||||
|
.description("test2")
|
||||||
.build()
|
.build()
|
||||||
.toEntity()
|
|
||||||
);
|
);
|
||||||
AdministratorUpdate.Request updateRequest = new AdministratorUpdate.Request();
|
flushAndClear();
|
||||||
updateRequest.setId(administrator.getId());
|
|
||||||
updateRequest.setPassword("test2");
|
|
||||||
updateRequest.setEmail("test2");
|
|
||||||
updateRequest.setName("test2");
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
AdministratorUpdate.Response updateResponse = service.update(updateRequest);
|
service.update(
|
||||||
|
AdministratorUpdateCommand.builder()
|
||||||
|
.id(saveAdministrator.getId())
|
||||||
|
.password("test2")
|
||||||
|
.email("test2")
|
||||||
|
.name("test2")
|
||||||
|
.roleId(updateRole.getId())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(updateResponse.getResultCode()).isEqualTo("0000");
|
Administrator findAdministrator = administratorRepository.findById(saveAdministrator.getId()).orElseThrow();
|
||||||
|
|
||||||
flushAndClear();
|
|
||||||
Administrator findAdministrator = repository.findById(administrator.getId()).orElseThrow();
|
|
||||||
assertThat(findAdministrator.getPassword()).isEqualTo("test2");
|
assertThat(findAdministrator.getPassword()).isEqualTo("test2");
|
||||||
assertThat(findAdministrator.getEmail()).isEqualTo("test2");
|
assertThat(findAdministrator.getEmail()).isEqualTo("test2");
|
||||||
assertThat(findAdministrator.getName()).isEqualTo("test2");
|
assertThat(findAdministrator.getName()).isEqualTo("test2");
|
||||||
|
|
||||||
|
assertThat(findAdministrator.getAdministratorRole().getRole().getName()).isEqualTo("test2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Administrator 삭제 테스트")
|
@DisplayName("Administrator 삭제 테스트")
|
||||||
@Test
|
@Test
|
||||||
public void deleteAdministratorTest() {
|
void deleteAdministratorTest() {
|
||||||
// given
|
// given
|
||||||
Administrator administrator = repository.save(
|
Role saveRole = getSaveRole();
|
||||||
AdministratorCreateCommand.builder()
|
flushAndClear();
|
||||||
.loginId("test")
|
|
||||||
.password("test")
|
|
||||||
.email("test")
|
|
||||||
.name("test")
|
|
||||||
.build()
|
|
||||||
.toEntity()
|
|
||||||
);
|
|
||||||
|
|
||||||
AdministratorDelete.Request request = new AdministratorDelete.Request();
|
Administrator saveAdministrator = createAdministrator(saveRole);
|
||||||
request.setId(administrator.getId());
|
flushAndClear();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
AdministratorDelete.Response deleteResponse = service.delete(request);
|
service.delete(saveAdministrator.getId());
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(deleteResponse.getResultCode()).isEqualTo("0000");
|
assertThat(administratorRepository.findById(saveAdministrator.getId())).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Administrator 삭제 시 Administrator 동시 삭제 테스트")
|
||||||
|
@Test
|
||||||
|
void deleteAdministratorAndAdministratorRoleTest() {
|
||||||
|
// given
|
||||||
|
Role saveRole = getSaveRole();
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
assertThat(repository.findById(administrator.getId())).isEmpty();
|
|
||||||
|
Administrator saveAdministrator = createAdministrator(saveRole);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
service.delete(saveAdministrator.getId());
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(administratorRepository.findById(saveAdministrator.getId())).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Role getSaveRole() {
|
||||||
|
return roleRepository.save(
|
||||||
|
Role.builder()
|
||||||
|
.name("test")
|
||||||
|
.description("test")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Administrator createAdministrator(Role role) {
|
||||||
|
Administrator administrator = Administrator.builder()
|
||||||
|
.loginId("test2")
|
||||||
|
.password("test2")
|
||||||
|
.email("test2")
|
||||||
|
.name("test2")
|
||||||
|
.build();
|
||||||
|
administrator.setAdministratorRole(
|
||||||
|
AdministratorRole.builder()
|
||||||
|
.role(role)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return administratorRepository.save(administrator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("AdministratorService method 호출 유효성 검사 테스트")
|
||||||
|
void validationTest() {
|
||||||
|
// create
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId(null).password("password").email("email").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId("").password("password").email("email").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId("loginId").password(null).email("email").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId("loginId").password("").email("email").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId("loginId").password("password").email(null).name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId("loginId").password("password").email("").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId("loginId").password("password").email("email").name(null).roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId("loginId").password("password").email("email").name("").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.create(AdministratorCreateCommand.builder().loginId("loginId").password("password").email("email").name("name").roleId(null).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// update
|
||||||
|
assertThatThrownBy(() -> service.update(AdministratorUpdateCommand.builder().id(null).password("password").email("email").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.update(AdministratorUpdateCommand.builder().id(1L).password(null).email("email").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.update(AdministratorUpdateCommand.builder().id(1L).password("").email("email").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.update(AdministratorUpdateCommand.builder().id(1L).password("password").email(null).name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.update(AdministratorUpdateCommand.builder().id(1L).password("password").email("").name("name").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.update(AdministratorUpdateCommand.builder().id(1L).password("password").email("email").name(null).roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.update(AdministratorUpdateCommand.builder().id(1L).password("password").email("email").name("").roleId(1L).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> service.update(AdministratorUpdateCommand.builder().id(1L).password("password").email("email").name("name").roleId(null).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// delete
|
||||||
|
assertThatThrownBy(() -> service.delete(null)).isInstanceOf(ConstraintViolationException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,252 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.menu;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.Menu;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuGroup;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuGroupRepository;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuRepository;
|
||||||
|
import com.bpgroup.poc.admin.env.MariaDBTestEnv;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.menu.service.*;
|
||||||
|
import jakarta.validation.ConstraintViolationException;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@DisplayName("MenuService 테스트")
|
||||||
|
class MenuServiceTest extends MariaDBTestEnv {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MenuService menuService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MenuGroupRepository menuGroupRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MenuRepository menuRepository;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
menuGroupRepository.deleteAll();
|
||||||
|
menuRepository.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("MenuGroup 생성 테스트")
|
||||||
|
void createMenuGroupTest() {
|
||||||
|
// given
|
||||||
|
MenuGroupCreateCommand groupCreateCommand = MenuGroupCreateCommand.of("uri", "name", 1);
|
||||||
|
|
||||||
|
// when
|
||||||
|
menuService.createMenuGroup(groupCreateCommand);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
Assertions.assertThat(menuGroupRepository.findAll()).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("MenuGroup 수정 테스트")
|
||||||
|
void updateMenuGroupTest() {
|
||||||
|
// given
|
||||||
|
createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
menuService.updateMenuGroup(
|
||||||
|
MenuGroupUpdateCommand.builder()
|
||||||
|
.id(menuGroupRepository.findAll().get(0).getId())
|
||||||
|
.uri("uri2")
|
||||||
|
.name("name2")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
MenuGroup findMenuGroup = menuGroupRepository.findAll().get(0);
|
||||||
|
Assertions.assertThat(findMenuGroup.getUri()).isEqualTo("uri2");
|
||||||
|
Assertions.assertThat(findMenuGroup.getName()).isEqualTo("name2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("MenuGroup 삭제 테스트")
|
||||||
|
void deleteMenuGroupTest() {
|
||||||
|
// given
|
||||||
|
MenuGroup saveMenuGroup = createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
menuService.deleteMenuGroup(saveMenuGroup.getId());
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
Assertions.assertThat(menuGroupRepository.findById(saveMenuGroup.getId())).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private MenuGroup createMenuGroup() {
|
||||||
|
return menuGroupRepository.save(
|
||||||
|
MenuGroup.builder()
|
||||||
|
.uri("uri")
|
||||||
|
.name("name")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Menu 생성 테스트")
|
||||||
|
void createGroupTest() {
|
||||||
|
// given
|
||||||
|
MenuGroup saveMenuGroup = createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
menuService.createMenu(
|
||||||
|
MenuCreateCommand.builder()
|
||||||
|
.menuGroupId(saveMenuGroup.getId())
|
||||||
|
.uri("uri")
|
||||||
|
.name("name")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
Assertions.assertThat(menuRepository.findAll()).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Menu 수정 테스트")
|
||||||
|
void updateMenuTest() {
|
||||||
|
// given
|
||||||
|
MenuGroup saveMenuGroup = createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
Menu menu = Menu.builder()
|
||||||
|
.uri("uri")
|
||||||
|
.name("name")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build();
|
||||||
|
menu.setMenuGroup(saveMenuGroup);
|
||||||
|
|
||||||
|
Menu saveMenu = menuRepository.save(menu);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
menuService.updateMenu(
|
||||||
|
MenuUpdateCommand.builder()
|
||||||
|
.id(saveMenu.getId())
|
||||||
|
.uri("uri2")
|
||||||
|
.name("name2")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
Menu findMenu = menuRepository.findById(saveMenu.getId()).orElseThrow();
|
||||||
|
Assertions.assertThat(findMenu.getUri()).isEqualTo("uri2");
|
||||||
|
Assertions.assertThat(findMenu.getName()).isEqualTo("name2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Menu 삭제 테스트")
|
||||||
|
void deleteMenuTest() {
|
||||||
|
// given
|
||||||
|
MenuGroup saveMenuGroup = createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
Menu menu = Menu.builder()
|
||||||
|
.uri("uri")
|
||||||
|
.name("name")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build();
|
||||||
|
menu.setMenuGroup(saveMenuGroup);
|
||||||
|
|
||||||
|
Menu saveMenu = menuRepository.save(menu);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
menuService.deleteMenu(saveMenu.getId());
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
Assertions.assertThat(menuRepository.findById(saveMenu.getId())).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("MenuGroup 삭제 시 Menu 동시 삭제 테스트")
|
||||||
|
void deleteMenuGroupWithMenuTest() {
|
||||||
|
// given
|
||||||
|
MenuGroup saveMenuGroup = createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
menuService.createMenu(
|
||||||
|
MenuCreateCommand.builder()
|
||||||
|
.menuGroupId(saveMenuGroup.getId())
|
||||||
|
.uri("uri")
|
||||||
|
.name("name")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
menuService.deleteMenuGroup(menuGroupRepository.findAll().get(0).getId());
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
Assertions.assertThat(menuGroupRepository.findAll()).hasSize(0);
|
||||||
|
Assertions.assertThat(menuRepository.findAll()).hasSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("MenuService method 호출 유효성 검사 테스트")
|
||||||
|
void validationTest() {
|
||||||
|
// menuGroup create
|
||||||
|
assertThatThrownBy(() -> menuService.createMenuGroup(MenuGroupCreateCommand.builder().uri("").name("name").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenuGroup(MenuGroupCreateCommand.builder().uri(null).name("name").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenuGroup(MenuGroupCreateCommand.builder().uri("uri").name("").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenuGroup(MenuGroupCreateCommand.builder().uri("uri").name(null).sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenuGroup(MenuGroupCreateCommand.builder().uri("uri").name("name").sortOrder(null).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// menuGroup update
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenuGroup(MenuGroupUpdateCommand.builder().id(null).uri("uri").name("name").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenuGroup(MenuGroupUpdateCommand.builder().id(1L).uri("").name("name").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenuGroup(MenuGroupUpdateCommand.builder().id(1L).uri(null).name("name").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenuGroup(MenuGroupUpdateCommand.builder().id(1L).uri("uri").name("").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenuGroup(MenuGroupUpdateCommand.builder().id(1L).uri("uri").name(null).sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenuGroup(MenuGroupUpdateCommand.builder().id(1L).uri("uri").name("name").sortOrder(null).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// menuGroup delete
|
||||||
|
assertThatThrownBy(() -> menuService.deleteMenu(null)).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// menu create
|
||||||
|
assertThatThrownBy(() -> menuService.createMenu(MenuCreateCommand.of(null, "uri", "name", 1))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenu(MenuCreateCommand.of(1L, "", "name", 1))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenu(MenuCreateCommand.of(1L, null, "name", 1))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenu(MenuCreateCommand.of(1L, "uri", "", 1))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenu(MenuCreateCommand.of(1L, "uri", null, 1))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.createMenu(MenuCreateCommand.of(1L, "uri", "name", null))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// menu update
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenu(MenuUpdateCommand.builder().id(null).uri("uri").name("name").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenu(MenuUpdateCommand.builder().id(1L).uri("").name("name").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenu(MenuUpdateCommand.builder().id(1L).uri(null).name("name").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenu(MenuUpdateCommand.builder().id(1L).uri("uri").name("").sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenu(MenuUpdateCommand.builder().id(1L).uri("uri").name(null).sortOrder(1).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> menuService.updateMenu(MenuUpdateCommand.builder().id(1L).uri("uri").name("name").sortOrder(null).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// menu delete
|
||||||
|
assertThatThrownBy(() -> menuService.deleteMenu(null)).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,103 +1,264 @@
|
||||||
package com.bpgroup.poc.admin.web.main.admin.role;
|
package com.bpgroup.poc.admin.web.main.admin.role;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.Role;
|
import com.bpgroup.poc.admin.domain.entity.menu.Menu;
|
||||||
import com.bpgroup.poc.admin.domain.admin.entity.RoleRepository;
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuGroup;
|
||||||
import com.bpgroup.poc.admin.domain.admin.command.RoleCreateCommand;
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuGroupRepository;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.menu.MenuRepository;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.Role;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.RoleMenu;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.RoleMenuRepository;
|
||||||
|
import com.bpgroup.poc.admin.domain.entity.role.RoleRepository;
|
||||||
import com.bpgroup.poc.admin.env.MariaDBTestEnv;
|
import com.bpgroup.poc.admin.env.MariaDBTestEnv;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleCreate;
|
import com.bpgroup.poc.admin.web.main.admin.role.service.*;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleDelete;
|
import jakarta.validation.ConstraintViolationException;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.role.reqres.RoleUpdate;
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@DisplayName("Role Service 테스트")
|
@DisplayName("Role Service 테스트")
|
||||||
class RoleServiceTest extends MariaDBTestEnv {
|
class RoleServiceTest extends MariaDBTestEnv {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EntityManager entityManager;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RoleService roleService;
|
private RoleService roleService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RoleRepository roleRepository;
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MenuGroupRepository menuGroupRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MenuRepository menuRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleMenuRepository roleMenuRepository;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
roleRepository.deleteAll();
|
roleRepository.deleteAll();
|
||||||
|
menuRepository.deleteAll();
|
||||||
|
menuGroupRepository.deleteAll();
|
||||||
|
roleMenuRepository.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Role 생성 테스트")
|
@DisplayName("Role 생성 테스트")
|
||||||
void createRoleTest() {
|
void createRoleTest() {
|
||||||
// given
|
|
||||||
RoleCreate.Request request = new RoleCreate.Request();
|
|
||||||
request.setName("TEST");
|
|
||||||
request.setDescription("TEST");
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
RoleCreate.Response response = roleService.create(request);
|
RoleCreateResult createResult = roleService.create(
|
||||||
|
RoleCreateCommand.builder()
|
||||||
|
.name("TEST")
|
||||||
|
.description("TEST")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(response.getId()).isNotNull();
|
assertThat(createResult.getId()).isNotNull();
|
||||||
assertThat(response.getResultCode()).isEqualTo("0000");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Role 수정 테스트")
|
@DisplayName("Role 수정 테스트")
|
||||||
void updateRoleTest() {
|
void updateRoleTest() {
|
||||||
// given
|
// given
|
||||||
Role createRole = roleRepository.save(RoleCreateCommand.builder()
|
Role saveRole = createRole();
|
||||||
.name("TEST")
|
|
||||||
.description("TEST")
|
|
||||||
.build()
|
|
||||||
.toEntity());
|
|
||||||
|
|
||||||
RoleUpdate.Request request = new RoleUpdate.Request();
|
|
||||||
request.setId(createRole.getId());
|
|
||||||
request.setName("TEST2");
|
|
||||||
request.setDescription("TEST2");
|
|
||||||
|
|
||||||
// when
|
|
||||||
RoleUpdate.Response response = roleService.update(request);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(response.getResultCode()).isEqualTo("0000");
|
|
||||||
|
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
||||||
Role findRole = roleRepository.findById(createRole.getId()).orElseThrow();
|
// when
|
||||||
assertThat(findRole.getName()).isEqualTo("TEST2");
|
roleService.update(
|
||||||
assertThat(findRole.getDescription()).isEqualTo("TEST2");
|
RoleUpdateCommand.builder()
|
||||||
|
.id(saveRole.getId())
|
||||||
|
.name("TEST2")
|
||||||
|
.description("TEST2")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
Role role = roleRepository.findById(saveRole.getId()).orElseThrow();
|
||||||
|
assertThat(role.getName()).isEqualTo("TEST2");
|
||||||
|
assertThat(role.getDescription()).isEqualTo("TEST2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Role 삭제 테스트")
|
@DisplayName("Role 삭제 테스트")
|
||||||
void deleteRoleTest() {
|
void deleteRoleTest() {
|
||||||
// given
|
// given
|
||||||
Role createRole = roleRepository.save(RoleCreateCommand.builder()
|
Role saveRole = createRole();
|
||||||
.name("TEST")
|
flushAndClear();
|
||||||
.description("TEST")
|
|
||||||
.build()
|
|
||||||
.toEntity());
|
|
||||||
|
|
||||||
RoleDelete.Request request = new RoleDelete.Request();
|
|
||||||
request.setId(createRole.getId());
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
RoleDelete.Response response = roleService.delete(request);
|
roleService.delete(saveRole.getId());
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(response.getResultCode()).isEqualTo("0000");
|
assertThat(roleRepository.findById(saveRole.getId())).isEmpty();
|
||||||
|
|
||||||
flushAndClear();
|
|
||||||
assertThat(roleRepository.findById(createRole.getId())).isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Role Menu 추가 테스트")
|
||||||
|
void addMenuTest() {
|
||||||
|
// given
|
||||||
|
Role saveRole = createRole();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
MenuGroup menuGroup = createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
Menu menu1 = createMenu(menuGroup);
|
||||||
|
Menu menu2 = createMenu(menuGroup);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
roleService.addRoleMenu(
|
||||||
|
Set.of(
|
||||||
|
RoleAddMenuCommand.builder()
|
||||||
|
.roleId(saveRole.getId())
|
||||||
|
.menuId(menu1.getId())
|
||||||
|
.build(),
|
||||||
|
RoleAddMenuCommand.builder()
|
||||||
|
.roleId(saveRole.getId())
|
||||||
|
.menuId(menu2.getId())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(roleMenuRepository.findAll()).size().isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Role Menu 삭제 테스트")
|
||||||
|
void deleteRoleMenuTest() {
|
||||||
|
// given
|
||||||
|
Role saveRole = createRole();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
MenuGroup menuGroup = createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
Menu saveMenu1 = createMenu(menuGroup);
|
||||||
|
Menu saveMenu2 = createMenu(menuGroup);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
roleMenuRepository.save(
|
||||||
|
RoleMenu.builder()
|
||||||
|
.role(saveRole)
|
||||||
|
.menu(saveMenu1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
roleMenuRepository.save(
|
||||||
|
RoleMenu.builder()
|
||||||
|
.role(saveRole)
|
||||||
|
.menu(saveMenu2)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// when
|
||||||
|
roleService.deleteRoleMenu(saveRole.getId());
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(roleMenuRepository.findAll()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Role 삭제 시 Role Menu 동시 삭제 테스트")
|
||||||
|
void deleteRoleAndRoleMenuTest() {
|
||||||
|
// given
|
||||||
|
Role saveRole = createRole();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
MenuGroup menuGroup = createMenuGroup();
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
Menu saveMenu1 = createMenu(menuGroup);
|
||||||
|
Menu saveMenu2 = createMenu(menuGroup);
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
roleMenuRepository.save(
|
||||||
|
RoleMenu.builder()
|
||||||
|
.role(saveRole)
|
||||||
|
.menu(saveMenu1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
roleMenuRepository.save(
|
||||||
|
RoleMenu.builder()
|
||||||
|
.role(saveRole)
|
||||||
|
.menu(saveMenu2)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
// when
|
||||||
|
roleService.delete(saveRole.getId());
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(roleMenuRepository.findAll()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Role createRole() {
|
||||||
|
return roleRepository.save(
|
||||||
|
Role.builder()
|
||||||
|
.name("TEST")
|
||||||
|
.description("TEST")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MenuGroup createMenuGroup() {
|
||||||
|
return menuGroupRepository.save(
|
||||||
|
MenuGroup.builder()
|
||||||
|
.uri("TEST")
|
||||||
|
.name("TEST")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Menu createMenu(MenuGroup menuGroup) {
|
||||||
|
Menu menu = Menu.builder()
|
||||||
|
.uri("TEST")
|
||||||
|
.name("TEST")
|
||||||
|
.sortOrder(1)
|
||||||
|
.build();
|
||||||
|
menu.setMenuGroup(menuGroup);
|
||||||
|
return menuRepository.save(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("RoleService method 호출 유효성 검사 테스트")
|
||||||
|
void validationTest() {
|
||||||
|
// create
|
||||||
|
assertThatThrownBy(() -> roleService.create(RoleCreateCommand.builder().name(null).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> roleService.create(RoleCreateCommand.builder().name("").build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// update
|
||||||
|
assertThatThrownBy(() -> roleService.update(RoleUpdateCommand.builder().id(null).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> roleService.update(RoleUpdateCommand.builder().id(1L).name(null).build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> roleService.update(RoleUpdateCommand.builder().id(1L).name("").build())).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// delete
|
||||||
|
assertThatThrownBy(() -> roleService.delete(null)).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// add Role Menu
|
||||||
|
assertThatThrownBy(() -> roleService.addRoleMenu(Set.of(RoleAddMenuCommand.builder().roleId(null).menuId(null).build()))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
assertThatThrownBy(() -> roleService.addRoleMenu(Set.of(RoleAddMenuCommand.builder().roleId(1L).menuId(null).build()))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
|
// delete Role Menu
|
||||||
|
assertThatThrownBy(() -> roleService.deleteRoleMenu(null)).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue