Skip to content

Commit

Permalink
๐Ÿ› [Bug] TicketSetup ์œ ๋ฌด ํ™•์ธํ•˜๋Š” ๋กœ์ง ์ „๋ถ€ False๋กœ ๋‚˜๊ฐ€๋Š” ๋ฒ„๊ทธ ๋ฐœ์ƒ #1008 (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain authored Sep 9, 2024
1 parent 368be13 commit 7cc4008
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ResponseEntity<AgendaProfileInfoDetailsResDto> myAgendaProfileInfoDetails
public ResponseEntity<MyAgendaProfileDetailsResDto> myAgendaProfileDetails(
@Login @Parameter(hidden = true) UserDto user, HttpServletResponse response) {
AgendaProfile profile = agendaProfileFindService.findAgendaProfileByIntraId(user.getIntraId());
int ticketCount = ticketService.findTicketList(profile).size();
int ticketCount = ticketService.findUsedTrueApproveTrueTicketList(profile).size();
IntraProfile intraProfile = intraProfileUtils.getIntraProfile(response);
MyAgendaProfileDetailsResDto agendaProfileDetails = MyAgendaProfileDetailsResDto.toDto(
profile, ticketCount, intraProfile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public ResponseEntity<Void> ticketSetupAdd(@Parameter(hidden = true) @Login User
@GetMapping
public ResponseEntity<TicketCountResDto> ticketCountFind(@Parameter(hidden = true) @Login UserDto user) {
AgendaProfile profile = agendaProfileFindService.findAgendaProfileByIntraId(user.getIntraId());
List<Ticket> tickets = ticketService.findTicketList(profile);
List<Ticket> tickets = ticketService.findUsedFalseTicketList(profile);
long approvedCount = tickets.stream()
.filter(Ticket::getIsApproved)
.count();
boolean setupTicket = tickets.size() > approvedCount;

return ResponseEntity.ok(new TicketCountResDto(tickets.size(), setupTicket));
return ResponseEntity.ok(new TicketCountResDto(approvedCount, setupTicket));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class TicketCountResDto {
private int ticketCount;
private long ticketCount;
private boolean setupTicket;

public TicketCountResDto(int ticketCount, boolean setupTicket) {
public TicketCountResDto(long ticketCount, boolean setupTicket) {
this.ticketCount = ticketCount;
this.setupTicket = setupTicket;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpClientErrorException;

import gg.agenda.api.user.agendaprofile.service.AgendaProfileFindService;
import gg.auth.FortyTwoAuthUtil;
import gg.auth.UserDto;
import gg.data.agenda.AgendaProfile;
import gg.data.agenda.AgendaTeamProfile;
import gg.data.agenda.Ticket;
import gg.repo.agenda.AgendaProfileRepository;
import gg.repo.agenda.AgendaRepository;
import gg.repo.agenda.TicketRepository;
import gg.utils.DateTimeUtil;
import gg.utils.exception.custom.DuplicationException;
Expand All @@ -38,8 +36,6 @@ public class TicketService {
private final ApiUtil apiUtil;
private final FortyTwoAuthUtil fortyTwoAuthUtil;
private final TicketRepository ticketRepository;
private final AgendaRepository agendaRepository;
private final AgendaProfileFindService agendaProfileFindService;
private final AgendaProfileRepository agendaProfileRepository;

@Value("https://api.intra.42.fr/v2/users/{id}/correction_point_historics?sort=-id")
Expand Down Expand Up @@ -74,10 +70,15 @@ public void addTicketSetup(UserDto user) {
* @return ํ‹ฐ์ผ“ ์ˆ˜
*/
@Transactional(readOnly = true)
public List<Ticket> findTicketList(AgendaProfile profile) {
public List<Ticket> findUsedTrueApproveTrueTicketList(AgendaProfile profile) {
return ticketRepository.findByAgendaProfileAndIsUsedFalseAndIsApprovedTrue(profile);
}

@Transactional(readOnly = true)
public List<Ticket> findUsedFalseTicketList(AgendaProfile profile) {
return ticketRepository.findByAgendaProfileAndIsUsedFalse(profile);
}

/**
* ํ‹ฐ์ผ“ ์Šน์ธ/๊ฑฐ์ ˆ
* @param profile ์‚ฌ์šฉ์ž ์ •๋ณด
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void beforeEach() {
}

@Test
@DisplayName("200 ํ‹ฐ์ผ“ ๊ฐœ์ˆ˜ ํ™•์ธ ์„ฑ๊ณต")
void findTicketCountSuccess() throws Exception {
@DisplayName("200 ํ‹ฐ์ผ“ ๊ฐœ์ˆ˜ ํ™•์ธ ์„ฑ๊ณต ๋ฐ setupTicket ํ™•์ธ")
void findTicketCountSetupTrueSuccess() throws Exception {
//given
ticketFixture.createTicket(seoulUserAgendaProfile);
ticketFixture.createTicket(seoulUserAgendaProfile);
Expand All @@ -158,6 +158,27 @@ void findTicketCountSuccess() throws Exception {
TicketCountResDto result = objectMapper.readValue(res, TicketCountResDto.class);
//then
assertThat(result.getTicketCount()).isEqualTo(2);
assertThat(result.isSetupTicket()).isTrue();
}

@Test
@DisplayName("200 ํ‹ฐ์ผ“ ๊ฐœ์ˆ˜ ํ™•์ธ ์„ฑ๊ณต ๋ฐ setupTicket ํ™•์ธ")
void findTicketCountSetupFalseSuccess() throws Exception {
//given
ticketFixture.createTicket(seoulUserAgendaProfile);
ticketFixture.createTicket(seoulUserAgendaProfile);

//when
String res = mockMvc.perform(
get("/agenda/ticket")
.header("Authorization", "Bearer " + seoulUserAccessToken)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
TicketCountResDto result = objectMapper.readValue(res, TicketCountResDto.class);
//then
assertThat(result.getTicketCount()).isEqualTo(2);
assertThat(result.isSetupTicket()).isFalse();
}

@Test
Expand Down Expand Up @@ -269,7 +290,7 @@ void findTicketHistorySuccessToUsed() throws Exception {
.param("size", String.valueOf(req.getSize())))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
PageResponseDto<TicketHistoryResDto> pageResponseDto = objectMapper.readValue(res, new TypeReference<>() {
});
});
List<TicketHistoryResDto> result = pageResponseDto.getContent();

//then
Expand Down
2 changes: 2 additions & 0 deletions gg-repo/src/main/java/gg/repo/agenda/TicketRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ Optional<Ticket> findFirstByAgendaProfileAndIsApprovedTrueAndIsUsedFalseOrderByC
Page<Ticket> findByAgendaProfileId(Long agendaProfileId, Pageable pageable);

List<Ticket> findByAgendaProfileAndIsUsedFalseAndIsApprovedTrue(AgendaProfile agendaProfile);

List<Ticket> findByAgendaProfileAndIsUsedFalse(AgendaProfile agendaProfile);
}

0 comments on commit 7cc4008

Please sign in to comment.