Skip to content

Commit

Permalink
Merge branch 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
emost22 committed Aug 17, 2023
2 parents ca1dd29 + ea0ba9b commit f71b6b2
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -35,6 +36,8 @@ public Result execute(Dto input) {
@Data
@Validated
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Dto implements Business.Dto, Serializable {

/** questionID */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.sirius.spurt.service.business.user;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sirius.spurt.common.template.Business;
import com.sirius.spurt.service.business.user.CheckUserHasPinedBusiness.Dto;
import com.sirius.spurt.service.business.user.CheckUserHasPinedBusiness.Result;
import com.sirius.spurt.store.provider.user.UserProvider;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

@Component
@RequiredArgsConstructor
public class CheckUserHasPinedBusiness implements Business<Dto, Result> {
private final UserProvider userProvider;

@Override
public Result execute(Dto input) {
return Result.builder().hasPined(userProvider.checkHasPined(input.getUserId())).build();
}

@JsonIgnoreProperties
@Data
@Validated
@Builder
public static class Dto implements Business.Dto, Serializable {
private String userId;
}

@NoArgsConstructor
@AllArgsConstructor
@Data
@JsonIgnoreProperties
@Builder
public static class Result implements Business.Result, Serializable {
private boolean hasPined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sirius.spurt.common.resolver.user.LoginUser;
import com.sirius.spurt.service.business.user.CheckUserExistsBusiness;
import com.sirius.spurt.service.business.user.CheckUserHasPinedBusiness;
import com.sirius.spurt.service.controller.RestResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -15,6 +16,7 @@
@Slf4j
public class UserController {
private final CheckUserExistsBusiness checkUserExistsBusiness;
private final CheckUserHasPinedBusiness checkUserHasPinedBusiness;

/**
* @return
Expand All @@ -26,4 +28,15 @@ public RestResponse<CheckUserExistsBusiness.Result> checkUserExists(LoginUser lo
checkUserExistsBusiness.execute(
CheckUserExistsBusiness.Dto.builder().userId(loginUser.getUserId()).build()));
}

/**
* @return
* @title 유저 최초 핀 고정 확인 api
*/
@GetMapping("/pin")
public RestResponse<CheckUserHasPinedBusiness.Result> checkUserHasPined(LoginUser loginUser) {
return RestResponse.success(
checkUserHasPinedBusiness.execute(
CheckUserHasPinedBusiness.Dto.builder().userId(loginUser.getUserId()).build()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.sirius.spurt.store.provider.jobgroup.impl;

import static com.sirius.spurt.common.meta.ResultCode.NOT_EXIST_USER;

import com.sirius.spurt.common.exception.GlobalException;
import com.sirius.spurt.common.meta.JobGroup;
import com.sirius.spurt.store.provider.jobgroup.JobGroupProvider;
import com.sirius.spurt.store.repository.database.entity.UserEntity;
Expand All @@ -17,13 +20,29 @@ public class JobGroupProviderImpl implements JobGroupProvider {
@Transactional
public void saveJobGroup(final String userId, final String email, final JobGroup jobGroup) {
userRepository.save(
UserEntity.builder().userId(userId).email(email).jobGroup(jobGroup).build());
UserEntity.builder()
.userId(userId)
.email(email)
.jobGroup(jobGroup)
.hasPined(false)
.build());
}

@Override
@Transactional
public void updateJobGroup(final String userId, final String email, final JobGroup jobGroup) {
UserEntity userEntity = userRepository.findByUserId(userId);

if (userEntity == null) {
throw new GlobalException(NOT_EXIST_USER);
}

userRepository.save(
UserEntity.builder().userId(userId).email(email).jobGroup(jobGroup).build());
UserEntity.builder()
.userId(userId)
.email(email)
.jobGroup(jobGroup)
.hasPined(userEntity.getHasPined())
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class QuestionProviderImpl implements QuestionProvider {
private final UserRepository userRepository;

@Override
@Transactional
public void putPinQuestion(
final String questionId, final String userId, final Boolean pinIndicator) {
UserEntity userEntity = userRepository.findByUserId(userId);
Expand All @@ -51,6 +52,16 @@ public void putPinQuestion(
throw new GlobalException(NOT_QUESTION_OWNER);
}

if (!userEntity.getHasPined()) {
userRepository.save(
UserEntity.builder()
.userId(userId)
.email(userEntity.getEmail())
.jobGroup(userEntity.getJobGroup())
.hasPined(true)
.build());
}

QuestionEntity questionEntity =
QuestionEntity.builder()
.questionId(Long.valueOf(questionId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface UserProvider {
boolean checkUserExists(String userId);

UserVo getUserInfo(String userId);

boolean checkHasPined(String userId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.sirius.spurt.store.provider.user.impl;

import static com.sirius.spurt.common.meta.ResultCode.NOT_EXIST_USER;

import com.sirius.spurt.common.exception.GlobalException;
import com.sirius.spurt.store.provider.user.UserProvider;
import com.sirius.spurt.store.provider.user.vo.UserVo;
import com.sirius.spurt.store.repository.database.entity.UserEntity;
Expand All @@ -24,6 +27,17 @@ public boolean checkUserExists(String userId) {
return userRepository.existsByUserId(userId);
}

@Override
public boolean checkHasPined(String userId) {
UserEntity userEntity = userRepository.findByUserId(userId);

if (userEntity == null) {
throw new GlobalException(NOT_EXIST_USER);
}

return userEntity.getHasPined();
}

@Mapper
public interface UserProviderImplMapper {
UserProviderImpl.UserProviderImplMapper INSTANCE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public class UserEntity extends BaseEntity {

@Column(nullable = false)
private String email;

@Column(nullable = false)
private Boolean hasPined;
}
12 changes: 12 additions & 0 deletions src/test/java/com/sirius/spurt/UserControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.sirius.spurt.service.business.user.CheckUserExistsBusiness;
import com.sirius.spurt.service.business.user.CheckUserHasPinedBusiness;
import com.sirius.spurt.service.controller.user.UserController;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -14,6 +15,7 @@
@WebMvcTest(controllers = {UserController.class})
public class UserControllerTest extends BaseMvcTest {
@MockBean private CheckUserExistsBusiness checkUserExistsBusiness;
@MockBean private CheckUserHasPinedBusiness checkUserHasPinedBusiness;

@Test
void 유저_존재_확인() throws Exception {
Expand All @@ -24,4 +26,14 @@ public class UserControllerTest extends BaseMvcTest {
when(checkUserExistsBusiness.execute(dto)).thenReturn(result);
this.mockMvc.perform(get("/v1/user/exist")).andExpect(status().isOk()).andDo(print());
}

@Test
void 유저_최초_핀고정_확인() throws Exception {
CheckUserHasPinedBusiness.Dto dto =
CheckUserHasPinedBusiness.Dto.builder().userId("admin").build();
CheckUserHasPinedBusiness.Result result =
CheckUserHasPinedBusiness.Result.builder().hasPined(false).build();
when(checkUserHasPinedBusiness.execute(dto)).thenReturn(result);
this.mockMvc.perform(get("/v1/user/pin")).andExpect(status().isOk()).andDo(print());
}
}

0 comments on commit f71b6b2

Please sign in to comment.