Skip to content

Commit

Permalink
feat: lombok ์ ์šฉ
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed Sep 18, 2023
1 parent 05715dd commit 1d07ed0
Show file tree
Hide file tree
Showing 37 changed files with 91 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@
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;

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

@Transactional(readOnly = true)
public AdminResponse getAdminResponse() {
List<Ticket> allTicket = ticketRepository.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.dto.LoginMemberDto;
import com.festago.auth.dto.LoginRequest;
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(LoginRequest request) {
LoginMemberDto loginMember = authService.login(getUserInfo(request));
String accessToken = getAccessToken(loginMember.memberId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
import com.festago.common.exception.NotFoundException;
import com.festago.member.domain.Member;
import com.festago.member.repository.MemberRepository;
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) {
return memberRepository.findBySocialIdAndSocialType(userInfo.socialId(), userInfo.socialType())
.map(LoginMemberDto::isExists)
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 @@ -12,23 +12,19 @@
import com.festago.ticketing.repository.MemberTicketRepository;
import java.time.Clock;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
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 Clock clock;

public EntryService(EntryCodeManager entryCodeManager, MemberTicketRepository memberTicketRepository, Clock clock) {
this.entryCodeManager = entryCodeManager;
this.memberTicketRepository = memberTicketRepository;
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 @@ -15,21 +15,18 @@
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;

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

public FestivalResponse create(FestivalCreateRequest request) {
Festival festival = request.toEntity();
validate(festival);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,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 @@ -35,9 +38,6 @@ public class Festival extends BaseTimeEntity {
@Size(max = 255)
private String thumbnail;

protected Festival() {
}

public Festival(String name, LocalDate startDate, LocalDate endDate) {
this(null, name, startDate, endDate, DEFAULT_THUMBNAIL);
}
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 @@ -27,6 +27,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 @@ -45,6 +46,7 @@
@RestController
@RequestMapping("/admin")
@Hidden
@RequiredArgsConstructor
public class AdminController {

private final FestivalService festivalService;
Expand All @@ -54,17 +56,6 @@ public class AdminController {
private final AdminAuthService adminAuthService;
private final Optional<BuildProperties> properties;

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

@PostMapping("/festivals")
public ResponseEntity<FestivalResponse> createFestival(@RequestBody @Valid FestivalCreateRequest request) {
FestivalResponse response = festivalService.create(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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 @@ -17,14 +18,11 @@
@RestController
@RequestMapping("/auth")
@Tag(name = "๋กœ๊ทธ์ธ ๊ด€๋ จ ์š”์ฒญ")
@RequiredArgsConstructor
public class AuthController {

private final AuthFacadeService authFacadeService;

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

@PostMapping("/oauth2")
@Operation(description = "์†Œ์…œ ์—‘์„ธ์Šค ํ† ํฐ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋กœ๊ทธ์ธ ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค.", summary = "OAuth2 ๋กœ๊ทธ์ธ")
public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.festago.festival.dto.FestivalsResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -14,14 +15,11 @@
@RestController
@RequestMapping("/festivals")
@Tag(name = "์ถ•์ œ ์ •๋ณด ์š”์ฒญ")
@RequiredArgsConstructor
public class FestivalController {

private final FestivalService festivalService;

public FestivalController(FestivalService festivalService) {
this.festivalService = festivalService;
}

@GetMapping
@Operation(description = "๋ชจ๋“  ์ถ•์ œ๋“ค์„ ์กฐํšŒํ•œ๋‹ค.", summary = "์ถ•์ œ ๋ชฉ๋ก ์กฐํšŒ")
public ResponseEntity<FestivalsResponse> findAll() {
Expand Down
Loading

0 comments on commit 1d07ed0

Please sign in to comment.