Skip to content

Commit

Permalink
feat: add missing @transaction to service (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
vran-dev authored Jul 28, 2022
1 parent e5dc581 commit 4df8f9b
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public Integer create(DatabaseTypeCreateRequest request) {
}
}

@Transactional
public void update(DatabaseTypeUpdateRequest request) {
databaseTypeUpdateValidator.validRequestRequiredParams(request);
databaseTypeDao.selectOptionalById(request.getId()).ifPresent(data -> {
Expand Down Expand Up @@ -111,6 +110,7 @@ private DriverResult loadAndValidate(String remoteUrl, String localPath, String
return result;
}

@Transactional
public void deleteById(Integer id) {
databaseTypeDao.selectOptionalById(id).ifPresent(data -> {
if (DatabaseTypes.has(data.getDatabaseType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;
import java.util.Set;
Expand All @@ -39,6 +40,7 @@ public class DocumentDiscussionService {

private final EventPublisher eventPublisher;

@Transactional
public void deleteById(Integer groupId,
Integer projectId,
Integer discussionId) {
Expand Down Expand Up @@ -73,6 +75,7 @@ public Page<DiscussionResponse> list(Integer groupId,
}
}

@Transactional
public void create(Integer groupId, Integer projectId, Integer userId, DiscussionCreateRequest request) {
if (projectDao.exists(groupId, projectId)) {
DocumentDiscussion pojo = new DocumentDiscussion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -40,6 +41,7 @@ public DocumentTemplatePropertiesResponse getAllProperties() {
.build();
}

@Transactional
public void updateByType(DocumentTemplatePropertiesUpdateRequest request) {
List<DocumentTemplateProperty> pojoList = documentTemplatePropertiesUpdateRequestConverter.toPojo(request);
documentTemplatePropertyDao.batchInsertOnDuplicateKeyUpdateValue(pojoList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void update(GroupUpdateRequest request) {
eventPublisher.publish(new GroupUpdated(request.getId(), request.getName(), request.getDescription()));
}

@Transactional
public void delete(Integer groupId) {
groupDao.deleteById(groupId);
userRoleDao.deleteByGroupId(groupId);
Expand Down Expand Up @@ -130,10 +131,12 @@ public GroupResponse get(Integer groupId) {
return groupResponseConverter.toResponse(group, users);
}

@Transactional
public void removeMember(Integer groupId, Integer userId) {
userRoleDao.deleteByUserIdAndGroupId(userId, groupId);
}

@Transactional
public void addMember(Integer groupId, GroupMemberCreateRequest request) {
if (userRoleDao.hasRole(request.getUserId(), groupId)) {
throw DomainErrors.USER_ROLE_DUPLICATE.exception();
Expand All @@ -145,6 +148,7 @@ public void addMember(Integer groupId, GroupMemberCreateRequest request) {
userRoleDao.insertAndReturnId(pojo);
}

@Transactional
public void changeMemberRole(Integer groupId, Integer userId, String role) {
if (!userRoleDao.hasRole(userId, groupId, role)) {
// TODO 最多 20 个组长
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.Instant;
import java.time.LocalDateTime;
Expand All @@ -38,6 +39,8 @@ public class LoginService {

private final JwtTokens jwtTokens;

@Transactional

public AccessTokenRefreshResponse refreshAccessTokens(AccessTokenRefreshRequest request) {
Login login = loginDao.selectByRefreshToken(request.getRefreshToken())
.orElseThrow(DomainErrors.INVALID_REFRESH_TOKEN_OPERATION::exception);
Expand Down Expand Up @@ -71,6 +74,8 @@ public AccessTokenRefreshResponse refreshAccessTokens(AccessTokenRefreshRequest
return new AccessTokenRefreshResponse(accessToken, accessTokenExpireAtMilli);
}

@Transactional

public LoginKeyResponse generate(Integer userId) {
User user = userDao.selectById(userId);
String accessToken = jwtTokens.accessToken(user.getEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.databasir.dao.tables.pojos.TableDocument;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.function.Function;
Expand All @@ -41,6 +42,8 @@ public class MockDataService {

private final MockDataValidator mockDataValidator;

@Transactional

public String generateMockInsertSql(Integer projectId, MockDataGenerateCondition condition) {
mockDataValidator.validProject(projectId);
DatabaseDocument databaseDoc =
Expand All @@ -50,6 +53,8 @@ public String generateMockInsertSql(Integer projectId, MockDataGenerateCondition
return mockDataGenerator.createInsertSql(projectId, databaseDoc.getId(), tableDoc.getName());
}

@Transactional

public void saveMockRules(Integer projectId,
Integer tableId,
List<ColumnMockRuleSaveRequest> rules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ public List<ProjectSimpleTaskResponse> listManualTasks(Integer projectId, Projec
return projectSimpleTaskResponseConverter.of(tasks);
}

@Transactional

public void cancelTask(Integer projectId, Integer taskId) {
if (!projectDao.existsById(projectId)) {
throw DomainErrors.PROJECT_NOT_FOUND.exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.databasir.dao.tables.pojos.SysMail;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.Optional;
Expand Down Expand Up @@ -40,6 +41,8 @@ public void deleteSystemEmail() {
});
}

@Transactional

public void updateEmailSetting(SystemEmailUpdateRequest request) {
SysMail sysMail = new SysMail();
sysMail.setSmtpHost(request.getSmtpHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public void addFavorites(Integer projectId, Integer userId) {
}
}

@Transactional

public void removeFavorites(Integer projectId, Integer userId) {
if (userFavoriteProjectDao.exists(userId, projectId)) {
userFavoriteProjectDao.delete(userId, projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ public void switchEnableStatus(Integer userId, Boolean enable) {
}
}

@Transactional
public void removeSysOwnerFrom(Integer userId) {
if (userRoleDao.hasRole(userId, SYS_OWNER)) {
userRoleDao.deleteRole(userId, SYS_OWNER);
}
}

@Transactional

public void addSysOwnerTo(Integer userId) {
if (!userRoleDao.hasRole(userId, SYS_OWNER)) {
UserRole role = new UserRole();
Expand All @@ -158,6 +161,7 @@ public void addSysOwnerTo(Integer userId) {
}
}

@Transactional
public void updatePassword(Integer userId, UserPasswordUpdateRequest request) {
if (!Objects.equals(request.getNewPassword(), request.getConfirmNewPassword())) {
throw DomainErrors.UPDATE_PASSWORD_CONFIRM_FAILED.exception();
Expand All @@ -171,6 +175,7 @@ public void updatePassword(Integer userId, UserPasswordUpdateRequest request) {
loginDao.deleteByUserId(userId);
}

@Transactional
public void updateNickname(Integer userId, UserNicknameUpdateRequest request) {
User user = userDao.selectById(userId);
user.setNickname(request.getNickname());
Expand Down

0 comments on commit 4df8f9b

Please sign in to comment.