Skip to content

Commit

Permalink
[BE] feat: Lombok 라이브러리 추가 (#415) (#452)
Browse files Browse the repository at this point in the history
* build: lombok 의존성 추가

* feat: lombok 적용
  • Loading branch information
seokjin8678 authored Oct 5, 2023
1 parent 8c6e756 commit 8c06f8c
Show file tree
Hide file tree
Showing 38 changed files with 97 additions and 195 deletions.
6 changes: 6 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ dependencies {

// Firebase
implementation 'com.google.firebase:firebase-admin:8.1.0'

// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,20 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
@RequiredArgsConstructor
public class AdminService {

private final FestivalRepository festivalRepository;
private final StageRepository stageRepository;
private final TicketRepository ticketRepository;
private final SchoolRepository schoolRepository;

public AdminService(FestivalRepository festivalRepository, StageRepository stageRepository,
TicketRepository ticketRepository,
SchoolRepository schoolRepository) {
this.festivalRepository = festivalRepository;
this.stageRepository = stageRepository;
this.ticketRepository = ticketRepository;
this.schoolRepository = schoolRepository;
}

@Transactional(readOnly = true)
public AdminResponse getAdminResponse() {
List<School> allSchool = schoolRepository.findAll();
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/java/com/festago/admin/domain/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@Entity
@Table(
Expand All @@ -17,6 +19,7 @@
)
}
)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Admin extends BaseTimeEntity {

@Id
Expand All @@ -27,9 +30,6 @@ public class Admin extends BaseTimeEntity {

private String password;

protected Admin() {
}

public Admin(String username, String password) {
this(null, username, password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@
import com.festago.common.exception.ForbiddenException;
import com.festago.common.exception.UnauthorizedException;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class AdminAuthService {

private static final String ROOT_ADMIN = "admin";

private final AuthProvider authProvider;
private final AdminRepository adminRepository;

public AdminAuthService(AuthProvider authProvider, AdminRepository adminRepository) {
this.authProvider = authProvider;
this.adminRepository = adminRepository;
}

@Transactional(readOnly = true)
public String login(AdminLoginRequest request) {
Admin admin = findAdmin(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@
import com.festago.auth.domain.UserInfo;
import com.festago.auth.dto.LoginMemberDto;
import com.festago.auth.dto.LoginResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AuthFacadeService {

private final AuthService authService;
private final OAuth2Clients oAuth2Clients;
private final AuthProvider authProvider;

public AuthFacadeService(AuthService authService, OAuth2Clients oAuth2Clients,
AuthProvider authProvider) {
this.authService = authService;
this.oAuth2Clients = oAuth2Clients;
this.authProvider = authProvider;
}

public LoginResponse login(SocialType socialType, String oAuthToken) {
UserInfo userInfo = getUserInfo(socialType, oAuthToken);
LoginMemberDto loginMember = authService.login(userInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@
import com.festago.member.domain.Member;
import com.festago.member.repository.MemberRepository;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
@Slf4j
public class AuthService {

private static final Logger log = LoggerFactory.getLogger(AuthService.class);

private final MemberRepository memberRepository;

public AuthService(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}

public LoginMemberDto login(UserInfo userInfo) {
Optional<Member> originMember =
memberRepository.findBySocialIdAndSocialType(userInfo.socialId(), userInfo.socialType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@
import com.festago.presentation.auth.AuthenticateContext;
import com.festago.presentation.auth.RoleArgumentResolver;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class LoginConfig implements WebMvcConfigurer {

private final AuthExtractor authExtractor;
private final AuthenticateContext authenticateContext;

public LoginConfig(AuthExtractor authExtractor, AuthenticateContext context) {
this.authExtractor = authExtractor;
this.authenticateContext = context;
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(new RoleArgumentResolver(Role.MEMBER, authenticateContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.festago.entry.domain.EntryCode;
import com.festago.entry.domain.EntryCodePayload;
import java.util.Date;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class EntryCodeManager {

private static final int MILLISECOND_FACTOR = 1_000;
Expand All @@ -15,11 +17,6 @@ public class EntryCodeManager {
private final EntryCodeProvider entryCodeProvider;
private final EntryCodeExtractor entryCodeExtractor;

public EntryCodeManager(EntryCodeProvider entryCodeProvider, EntryCodeExtractor entryCodeExtractor) {
this.entryCodeProvider = entryCodeProvider;
this.entryCodeExtractor = entryCodeExtractor;
}

public EntryCode provide(EntryCodePayload entryCodePayload, long currentTimeMillis) {
Date expiredAt = new Date(currentTimeMillis + (DEFAULT_PERIOD + DEFAULT_OFFSET) * MILLISECOND_FACTOR);
String code = entryCodeProvider.provide(entryCodePayload, expiredAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,21 @@
import com.festago.ticketing.repository.MemberTicketRepository;
import java.time.Clock;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class EntryService {

private final EntryCodeManager entryCodeManager;
private final MemberTicketRepository memberTicketRepository;
private final ApplicationEventPublisher publisher;
private final Clock clock;

public EntryService(EntryCodeManager entryCodeManager, MemberTicketRepository memberTicketRepository,
ApplicationEventPublisher publisher, Clock clock) {
this.entryCodeManager = entryCodeManager;
this.memberTicketRepository = memberTicketRepository;
this.publisher = publisher;
this.clock = clock;
}

public EntryCodeResponse createEntryCode(Long memberId, Long memberTicketId) {
MemberTicket memberTicket = findMemberTicket(memberTicketId);
if (!memberTicket.isOwner(memberId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@
import com.festago.stage.repository.StageRepository;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class FestivalService {

private final FestivalRepository festivalRepository;
private final StageRepository stageRepository;
private final SchoolRepository schoolRepository;

public FestivalService(FestivalRepository festivalRepository, StageRepository stageRepository,
SchoolRepository schoolRepository) {
this.festivalRepository = festivalRepository;
this.stageRepository = stageRepository;
this.schoolRepository = schoolRepository;
}

public FestivalResponse create(FestivalCreateRequest request) {
School school = schoolRepository.findById(request.schoolId())
.orElseThrow(() -> new NotFoundException(ErrorCode.SCHOOL_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import jakarta.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Festival extends BaseTimeEntity {

private static final String DEFAULT_THUMBNAIL = "https://picsum.photos/536/354";
Expand All @@ -24,7 +27,6 @@ public class Festival extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;


@NotNull
@Size(max = 50)
private String name;
Expand All @@ -42,9 +44,6 @@ public class Festival extends BaseTimeEntity {
@ManyToOne(fetch = FetchType.LAZY)
private School school;

protected Festival() {
}

public Festival(String name, LocalDate startDate, LocalDate endDate, School school) {
this(null, name, startDate, endDate, DEFAULT_THUMBNAIL, school);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import com.festago.member.domain.Member;
import com.festago.member.dto.MemberProfileResponse;
import com.festago.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
@RequiredArgsConstructor
public class MemberService {

private final MemberRepository memberRepository;

public MemberService(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}

@Transactional(readOnly = true)
public MemberProfileResponse findMemberProfile(Long memberId) {
Member member = memberRepository.findById(memberId)
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/java/com/festago/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

Expand All @@ -30,6 +32,7 @@
)
}
)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseTimeEntity {

private static final String DEFAULT_IMAGE_URL = "https://festa-go.site/images/default-profile.png";
Expand All @@ -55,9 +58,6 @@ public class Member extends BaseTimeEntity {

private LocalDateTime deletedAt = null;

protected Member() {
}

public Member(Long id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.info.BuildProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
Expand All @@ -48,6 +49,7 @@
@RestController
@RequestMapping("/admin")
@Hidden
@RequiredArgsConstructor
public class AdminController {

private final FestivalService festivalService;
Expand All @@ -58,18 +60,6 @@ public class AdminController {
private final SchoolService schoolService;
private final Optional<BuildProperties> properties;

public AdminController(FestivalService festivalService, StageService stageService, TicketService ticketService,
AdminService adminService, AdminAuthService adminAuthService,
SchoolService schoolService, Optional<BuildProperties> buildProperties) {
this.festivalService = festivalService;
this.stageService = stageService;
this.ticketService = ticketService;
this.adminService = adminService;
this.adminAuthService = adminAuthService;
this.schoolService = schoolService;
this.properties = buildProperties;
}

@PostMapping("/schools")
public ResponseEntity<SchoolResponse> createSchool(@RequestBody @Valid SchoolCreateRequest request) {
SchoolResponse response = schoolService.create(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -18,16 +19,12 @@
@RestController
@RequestMapping("/auth")
@Tag(name = "로그인 관련 요청")
@RequiredArgsConstructor
public class AuthController {

private final AuthFacadeService authFacadeService;
private final MemberFCMService memberFCMService;

public AuthController(AuthFacadeService authFacadeService, MemberFCMService memberFCMService) {
this.authFacadeService = authFacadeService;
this.memberFCMService = memberFCMService;
}

@PostMapping("/oauth2")
@Operation(description = "소셜 엑세스 토큰을 기반으로 로그인 요청을 보낸다.", summary = "OAuth2 로그인")
public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest request) {
Expand Down
Loading

0 comments on commit 8c06f8c

Please sign in to comment.