feat(admin): 사용자 어드민 권한 토글 backend 연결

- AdminUserController.updateAdmin이 호출하던 service/mapper 미커밋 상태였음
- CORS allowedMethods에 PATCH 추가 (PATCH /api/admin/users/{id}/admin)
- UserMapper.updateAdmin + XML (is_admin 0/1)
- UserService.updateAdmin (트랜잭션 + 404 가드)
- findAllWithCounts에 is_admin 컬럼 SELECT 추가

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
joungmin
2026-06-16 19:34:58 +09:00
parent 1164139312
commit 0676a31cfd
4 changed files with 18 additions and 2 deletions

View File

@@ -21,7 +21,7 @@ public class WebConfig implements WebMvcConfigurer {
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(Arrays.asList(allowedOrigins.split(",")));
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
config.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
config.setAllowedHeaders(List.of("*"));
config.setAllowCredentials(true);

View File

@@ -21,4 +21,6 @@ public interface UserMapper {
List<UserInfo> findAllWithCounts(@Param("limit") int limit, @Param("offset") int offset);
int countAll();
int updateAdmin(@Param("id") String id, @Param("admin") int admin);
}

View File

@@ -3,8 +3,10 @@ package com.tasteby.service;
import com.tasteby.domain.UserInfo;
import com.tasteby.mapper.UserMapper;
import com.tasteby.util.IdGenerator;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;
import java.util.List;
@@ -47,4 +49,12 @@ public class UserService {
public int countAll() {
return mapper.countAll();
}
@Transactional
public void updateAdmin(String userId, boolean admin) {
int rows = mapper.updateAdmin(userId, admin ? 1 : 0);
if (rows == 0) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "User not found");
}
}
}

View File

@@ -37,7 +37,7 @@
</select>
<select id="findAllWithCounts" resultMap="userResultMap">
SELECT u.id, u.email, u.nickname, u.avatar_url, u.provider, u.created_at,
SELECT u.id, u.email, u.nickname, u.avatar_url, u.is_admin, u.provider, u.created_at,
NVL(fav.cnt, 0) AS favorite_count,
NVL(rev.cnt, 0) AS review_count,
NVL(memo.cnt, 0) AS memo_count
@@ -53,4 +53,8 @@
SELECT COUNT(*) FROM tasteby_users
</select>
<update id="updateAdmin">
UPDATE tasteby_users SET is_admin = #{admin,jdbcType=NUMERIC} WHERE id = #{id}
</update>
</mapper>